数据格式

Data format 数据格式

GET 请求很简单. 全部所需的数据应由URL中使用标准的GET语句提供.
对于大多数其他的请求,全部所需的数据应以XML语言提供. 应答也生成为XML语言.
例如,POST请求方式应当通过XML格式语句建立以保证POST请求的主体中包含XML语言. 这样的请求所对应的类型应设置为text/xml.

 

Authentication 认证

要访问ExpertSender 的 API,你必须于每个请求都提供你的API key。API key 是一个数字和字母组成的随机字符串,ExpertSender系统为每个业务单元自动生成。

你可以从ExpertSender系统中的“业务单元设置 – >API”标签得到你的API key。 API key 具有唯一性,提供它系统就会自动识别您的信息。API key 应以URL参数方式提供(GET请求)或在请求的 XML 语言主体中(其他请求方式:见”Request 请求”详情)。
注意:所有 API 的示例在应用时都需要替代为正确的API 服务器 和 API key.

 

Request 请求

Request 请求主体应该是UTF-8编码的 XML语言,不需要 XML 语言的头部 (<?xml…),例如:
<ApiRequest
  xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
  xmlns:xs=”http://www.w3.org/2001/XMLSchema”>
  <ApiKey>YOUR_API_KEY_HERE</ApiKey>
  <Data xsi:type=”Subscriber”>
    <Mode>AddAndUpdate</Mode>
    <Force>true</Force>
    <ListId>1</ListId>
    <Email>john.smith@domain.com</Email>
    <Firstname>John</Firstname>
    <Lastname>Smith</Lastname>
    <TrackingCode>123</TrackingCode>
    <Vendor>xyz</Vendor>
    <Ip>11.22.33.44</Ip>
    <Properties>
      <Property>
         <Id>2</Id>
        <Value xsi:type=”xs:string”>student</Value>
      </Property>
      <Property>
        <Id>3</Id>
        <Value xsi:type=”xs:dateTime”>1985-03-12</Value>
      </Property>
    </Properties>
  </Data>
</ApiRequest>

 

请求是由两部分组成的:

1.  ApiKey – 这是您的API key,认证需要

2.  数据 – 这是请求数据。其内容可能会有所不同,这取决于所操作的资源。数据类型应始终指定使用xsi:type属性 (xsi:type attribute)。

 

Response应答

要返回任何数据(大多为GET请求方式)时,或在出现错误的情况下,一段XML语言将被提供。 应答内容类型(content-type)设置为text/xml且应答主体包含XML语言。格式如下:

正确的应答Correct Response:

<ApiResponse xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<Data xsi:type=”…”>

</Data>
</ApiResponse>

 

数据元素的类型和内容取决于所访问的数据资源类型(见下文不同数据资源的详细描述)。

错误的应答 Error response:
<ApiResponse xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xmlns:xsd=”http://www.w3.org/2001/XMLSchema”>
<ErrorMessage>
<Code>400</Code>
<Message>Email is invalid; </Message>
</ErrorMessage>
</ApiResponse>

错误代码(包括返回的HTTP应答代码)以及一段解释性错误消息会被返回。