简化和增强Salesforce Marketing Cloud的FuelSDK(ExactTarget)

FuelSDKWrapper的Python项目详细描述


燃油压缩机

简化和增强Salesforce Marketing Cloud(ExactTarget)的FuelSDK。

概述

用于python的fuel sdk包装器将功能添加到默认的fuelsdk,并提供对更多soap api对象的访问。可以找到fuel sdk文档here

安装

pipinstallFuelSDKWrapper

开始

配置

您必须通过以下两种方式之一配置fuel sdk的访问令牌和详细信息。

  1. 将包含的config.python.template文件复制到~/.fuelsdk/中的config.python,可以是在这个python模块中,也可以是在项目的根目录中。
  2. 添加环境变量:
    • FUELSDK_CLIENT_ID(必需)
    • FUELSDK_CLIENT_SECRET(必需)
    • FUELSDK_APP_SIGNATURE
    • FUELSDK_DEFAULT_WSDL
    • FUELSDK_AUTH_URL
    • FUELSDK_WSDL_FILE_LOCAL_LOC

编辑config.python或声明环境变量,以便您可以输入注册应用程序时提供的clientid和client secret值。如果要为交互式营销中心构建hubexchange应用程序,则还必须提供应用程序签名(appsignature/FUELSDK_APP_SIGNATURE)。 defaultwsdl/FUELSDK_DEFAULT_WSDL配置必须是changed depending on the ExactTarget serviceauthenticationurl/FUELSDK_AUTH_URL也必须是changed depending on servicewsdl_file_local_loc/FUELSDK_WSDL_FILE_LOCAL_LOC允许您指定wsdl文件将位于磁盘上的完整路径/文件名,例如,如果您连接到来自同一服务器的不同端点。

如果您尚未注册应用程序,或者需要查找应用程序密钥或应用程序签名值,请转到Code@: ExactTarget's Developer Community的应用程序中心。

EnvironmentWSDL (default)URL (auth)
Productionhttps://webservice.exacttarget.com/etframework.wsdlhttps://auth.exacttargetapis.com/v1/requestToken?legacy=1
Sandboxhttps://webservice.test.exacttarget.com/Service.asmx?wsdlhttps://auth-test.exacttargetapis.com/v1/requestToken?legacy=1

也可以将这些值直接传递给api对象:

params={"clientid":"YOUR_CLIENT_ID","clientsecret":"YOUR_CLIENT_SECRET"}api=ET_API(params=params)

示例

获取列表对象

# Add a require statement to reference the FuelSDK functionalityfromFuelSDKWrapperimportET_API,ObjectType# Next, create an instance of the ET_API classapi=ET_API()# Get the List objectsresponse=api.get_objects(ObjectType.LIST)# Print out the results for viewingprint('Post Status: {}'.format(response.status))print('Code: {}'.format(response.code))print('Message: {}'.format(response.message))print('Result Count: {}'.format(len(response.results)))print('Results: {}'.format(response.results))

利用率

的一些例子
fromFuelSDKWrapperimportET_API,ObjectType,Operator,FolderType,simple_filter,complex_filterfromdatetimeimportdatetime,timedeltaapi=ET_API()# Get Subscriber Data using the IN Operatorresponse=api.get_objects(ObjectType.SUBSCRIBER,simple_filter("EmailAddress",Operator.IN,["my.email@domain.com","your.email@domain.com"]))# Find Query Definition using the LIKE Operatorresponse=api.get_objects(ObjectType.QUERY_DEFINITION,simple_filter("QueryText",Operator.LIKE,"FROM My_DE"),property_list=["Name","CategoryID","QueryText"])# Get Jobs sent in the last 30 daysstart_date=datetime.now()-timedelta(days=30)response=api.get_objects(ObjectType.SEND,simple_filter("SendDate",Operator.GREATER_THAN,start_date))# Get Folder Dataresponse=api.get_objects(ObjectType.FOLDER,complex_filter(simple_filter("Name",Operator.EQUALS,"My_Folder_Name"),"OR",simple_filter("Name",Operator.EQUALS,"My_Other_Folder_Name")),property_list=["ID","Name"])# Get Folder Full Pathfolder_id=12345response=api.get_folder_full_path(folder_id)# Get or Create Folder Full Pathfolder_names=["Test","Sub_Test"]folder_type=FolderType.DATA_EXTENSIONSresponse=api.get_or_create_folder_hierarchy(folder_type,folder_names)# Start an Automationresponse=api.start_automation("Automation_Key")# Seng Trigger Emailresponse=api.send_trigger_email("MyTriggerKey","email@email.com","subscriberkey@email.com",attributes={"first_nm":"Sebastien","birth_dt":"1/1/1990"})# Get Tokensshort_token=api.get_client().authTokenlong_token=api.get_client().internalAuthToken# Get Data Extension Fields sorted by Ordinalfields=sorted(api.get_data_extension_columns("My_DE_Key").results,key=lambdax:x.Ordinal)# Clear Data Extensionresponse=api.clear_data_extension("DE_Key")# Create Batch of Data Extension Rowskeys_list=[["Field1","Field2","Field3"],# Fields for Row 1["Field1","Field2","Field3"],# Fields for Row 2["Field1","Field2","Field3"]# Fields for Row 3]values_list=[["Row1_Value1","Row1_Value2","Row1_Value3"],["Row2_Value1","Row2_Value2","Row2_Value3"],["Row3_Value1","Row3_Value2","Row3_Value3"]]response=api.create_data_extension_rows("DE_Key",keys_list,values_list)

获得更多结果

response=api.get_objects(ObjectType.LIST_SUBSCRIBER,simple_filter("ListID",Operator.EQUALS,1234),property_list=["ID"])total=len(response.results)whileresponse.more_results:response=api.get_more_results()total+=len(response.results)

提取请求

start_date=datetime.now()-timedelta(days=30)end_date=datetime.now()response=api.extract_data(parameters={"AccountIDs":"123456","_AsyncID":0,"StartDate":start_date,"EndDate":end_date,"ExtractSent":"true","ExtractSendJobs":"true","ExtractBounces":"false","ExtractClicks":"false","ExtractOpens":"false","ExtractUnsubs":"false","ExtractConversions":"false","IncludeTestSends":"false","IncludeUniqueClicks":"false","IncludeUniqueOpens":"false","ExtractSurveyResponses":"false","Format":"tab","OutputFileName":"extract.zip"})

执行请求

您可以执行找到的操作列表here

response=api.get_objects(ObjectType.IMPORT_DEFINITION,simple_filter("Name",Operator.EQUALS,"Import_my_file"))try:import_def=response.results[0]response=api.perform_action("start",import_def)exceptIndexError:pass

列出soap api对象属性

response=api.get_info(ObjectType.CONTENT_AREA)

响应

fuel sdk对象上的所有方法都返回一个遵循相同结构的通用对象,而不管调用类型如何。此对象包含一组常用属性,用于显示有关请求的详细信息。

ParameterDescription
statusBoolean value that indicates if the call was successful
codeHTTP Error Code (will always be 200 for SOAP requests)
messageText values containing more details in the event of an Error
resultsCollection containing the details unique to the method called.

调试

要调试任何问题,请激活调试模式:

api=ET_API(debug=True)

要求

python 2.7.x

库:

  • fuelsdk=0.9.3
  • Pyjwt>;=0.1.9
  • 请求>;=2.18.4
  • 泡沫=0.4
  • suds jurko>;=0.6

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java三角测距   java Spring异步任务返回未来   java如何显示数据库中的下一条记录   java这些读取用户输入的方法有什么不同?   java Spring+Spring安全请求只接受contenttype xwwwformurlencoded   checkName()和将用户输入存储到ArrayList和boolean[]的java问题   java如何使用JPA和Facade?   java Neo4j类型不匹配   java如何依赖Maven的系统包?   通过FileChooser保存pdf格式会提示在java中出现第二个对话框   java如何将通量链接到另一个通量/单声道并应用另一个背压?   java如何修复安卓 studio中的权限错误?   尝试清除JavaFX ObservableMap时出现java ConcurrentException   java编辑文本。GetText,返回关于null引用的异常,但已声明该异常   mysql组织。乔达。时间LocalDate在Redhat(Linux)java上显示少一天   在java中通过序列化获取多个对象   有人有java注释“java.lang.Synthetic”的背景吗?