Marketing Cloud Soap API使用教程

::: warning 这个教程是Salesforce的Marketing Cloud :::

首先先下载一个SoapUI的工具,它是一个Soap测试工具,类似于PostMan,是专门测试Soap接口的工具。 image

然后使用该工具,向Marketing Cloud发送Xml(Soap的报文都是xml格式的)

image

在SoapUI创建项目,点击File-New SOAP Project 即可创建一个SOAP项目。

image

其中WSDL可以在下面链接的文章中找: 点这里点这里

等待一会儿,就可以看见树图了。

image

其中Retrieve用作查询,其他的是否有效有待验证。

然后就可以发送报文了,但报文中需要添加你的身份信息,即token。如何获得token呢?

下面是获取token的方法:

首先得在Marketing Cloud中配置读写权限,比如读取Automation,读取DE等,在 头像-setup-Apps-Installed Packages中就能创建一个Package,用来配置权限和调用API。

image

Client Id 和 Client Secret 就是调用API的用户名和密码,在package中提供了Authentication Base URI,REST Base URI和SOAP Base URI。

使用Authentication Base URI可以获取token信息,使用PostMan,向http://Authentication Base URI/v2/token   发送Post请求,就会获得供Soap API使用的token信息,要发送的要素有:

grant_type,client_id,client_secret,account_id,scope

其中参数说明:点这里点这里 image

grant_type要素值设为client_credentials即可,client_id,client_secret就是package中的Client Id 和 Client Secret,account_id是环境号,即头像旁边选环境的MID,scope为权限信息,比如你想读automation,就设置成 automations_read,多权限用空格分隔。

获取的报文:

1 { 2 3"access_token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 4 5"token_type": "Bearer", 6 7"expires_in": 1080, 8 9"scope": "data_extensions_read data_extensions_write automations_read", 10 11"soap_instance_url": "https://xxxxxxxxxxxxx.soap.marketingcloudapis.com/", 12 13"rest_instance_url": "https://xxxxxxxxxxxxx.rest.marketingcloudapis.com/" 14 15}

把accenss_token复制出来,粘贴到要发送的Soap报文中,就可以通过身份验证。

下面是Soap API要发送的查询报文示例

查询时要发送的XML:

1<soapenv:envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> 2 3   <soapenv:header> 4 5       <fueloauth>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx这里放刚才获得的token</fueloauth> 6 7   </soapenv:header> 8 9   <soapenv:body> 10 11      <retrieverequestmsg xmlns=""http://exacttarget.com/wsdl/partnerAPI""> 12 13         <retrieverequest> 14 15            <objecttype>SubscriberList</objecttype> 16 17            <properties>ID</properties> 18 19            <properties>PartnerKey</properties> 20 21            <properties>CreatedDate</properties> 22 23            <properties>Client.ID</properties> 24 25            <properties>Status</properties> 26 27            <properties>List.ID</properties> 28 29            <properties>List.ListName</properties> 30 31            <properties>Subscriber.Status</properties> 32 33            <properties>Subscriber.CreatedDate</properties> 34 35            <properties>Subscriber.ID</properties> 36 37            <properties>Subscriber.EmailAddress</properties> 38 39            <properties>Subscriber.SubscriberKey</properties> 40 41            <filter xsi:type=""par:ComplexFilterPart"" xmlns:par=""http://exacttarget.com/wsdl/partnerAPI""> 42 43               <leftoperand xsi:type=""par:SimpleFilterPart""> 44 45                  <property>List.ID</property> 46 47                  <simpleoperator>equals</simpleoperator> 48 49                  <value>xxxxxx</value> 50 51               </leftoperand> 52 53               <logicaloperator>AND</logicaloperator> 54 55               <rightoperand xsi:type=""par:SimpleFilterPart""> 56 57                  <property>CreatedDate</property> 58 59                  <simpleoperator>between</simpleoperator> 60 61                  <datevalue>2013-03-01T08:42:00</datevalue> 62 63                  <datevalue>2013-03-18T08:42:00</datevalue> 64 65               </rightoperand> 66 67            </filter> 68 69            <queryallaccounts>false</queryallaccounts> 70 71         </retrieverequest> 72 73      </retrieverequestmsg> 74 75   </soapenv:body> 76 77</soapenv:envelope>

这是subscriberList对象所包含的元素: 点这里点这里

可以看到,Subscriber 是一个Subscriber对象,如何查出该对象中的元素呢?那就需要这么写:Subscriber.ID 代表Subscriber对象的ID值。

有时候可以看到对象中含有数组元素,那么这种得怎么写properties呢?没法写。。。但这种包含数组的,基本都是一个对象数组,可以通过该种对象进行查询,比如:

查询DataExtension时,Fields就是一个DataExtensionField[]对象数组,这时,就可以通过DataExtensionField对象,查询该DE的所有DataExtensionField信息。即修改报文为<objecttype>DataExtensionField</objecttype>,来查询DE的所有字段。该对象中会包含关于DE的要素,可以与DE关联。

 

如果想开发一些方便的工具,Marketing Cloud还提供了SDK,并且是开源的。 这是SDK 的地址:点这里点这里

有C# SDK、Java SDK、Node SDK、PHP SDK、Ruby SDK、Python SDK

有趣的是,Java的SDK里有的方法还是带有中文备注的。

这个SDK还是不完善的,有的对象查询需要自己创建。

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )