Request messages
Request format and type
All kinds of request messages are send by POST.
There are no specific name-value pairs in the request, which should contain action parameters. Whole message is serialised in JSON and pushed as a POST container.
PHP example:
<?php
$message = json_encode($messageArray);
$curlHandler = curl_init();
$curlOptions = array(
...
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $message,
...
);
Consuming the request
As mentioned before, there are no special fields and a whole POST message contains complete request information.
PHP example, showing how to consume the request by SC:
<?php
$rawMessage = file_get_contents('php://input');
$jsonMessage = json_decode($rawMessage);
$user = $jsonMessage[0]->params->username;
$password = $jsonMessage[0]->params->password;
Request headers
SC message is suffixed with the following headers:
- Content-type: application/json
PHP example:
<?php
$message = json_encode($messageArray);
$curlHandler = curl_init();
$curlOptions = array(
...
CURLINFO_CONTENT_TYPE => 'application/json',
...
);
Structure of the request message
There are several requirements for the message:
- message has to be serialised in JSON format;
- textual data has to be UTF-8;
- message has to contain following two main blocks respectively:
- authentication block, which is always first;
- and the action block;
JSON example:
[
{ /* AUTHENTICATION BLOCK, ALWAYS FIRST */
"api":1,
"method":"auth",
"params":{
"username":"...",
"password":"..."
},
"id":1
},
{ /* ACTION BLOCK */
"api":1,
"method":"Product.addSources",
"params":{
"productsInfo":[
{
"seller":"745",
"product_id":"243427",
"seller_sku":"DCSWS 1",
"shipment_type":1,
"product_identifier":null
}
]
},
"id":1
}
]
Authentication block:
Field name |
Type |
Value |
Description |
---|---|---|---|
api |
integer |
1 |
API version, always 1 |
method |
string |
"auth" |
Always "auth" |
params |
array |
[] |
Authentication parameters |
username |
string |
"sellercenter" |
Endpoint user name |
password |
string |
"password" |
Endpoint password |
id |
integer |
undefined | Request id, should be always passed to the response message |
Action block depends on the type, but it has special required fields:
Field name |
Type |
Value |
Description |
---|---|---|---|
api |
integer |
1 |
API version, always 1 |
method |
string |
undefined | Action method |
params |
array |
[…] |
Action parameters |
id |
integer |
undefined | Request id, should be always passed to the response message |