How toWeb Service Developer Guide

Web Service Developer Guide

Sana Commerce 8.3
Your provider

How to Build XML and JSON Requests

Sana Commerce web service supports requests in XML and JSON formats.
To see an example of valid requests in both formats you can refer to the web service help page, which can be accessed by the URL in the following format: '[frontendurl]/api/CommerceService.svc/help'. Replace '[frontendurl]' with the URL of the Sana Commerce frontend. On the web service help page you can find information about each web service's method, its description and examples of the valid requests in the XML and JSON formats. Use the web service help page to build requests in the valid format.
 
For example, the request to the 'customer/login' method in XML and JSON formats:

XML

<ExternalLogin>
  <UserName>String content</UserName>
  <Password>String content</Password>
</ExternalLogin>

JSON

{
  "UserName":"String content",
  "Password":"String content"
}

In this example the ExternalLogin object is passed in the request and it has two properties, UserName and Password, which are used by the Sana Commerce framework to authenticate the user.

The order of the nodes in the XML request must be exactly the same for each method as it is listed on the web service help page. Otherwise, the request will not be parsed correctly by the Sana Commerce framework. This refers to the XML format only, so in JSON the order of the nodes does not matter.
For example, the following XML request to the 'customer/login' method will work correctly and return HTTP Status 200:
 
<ExternalLogin>
  <UserName>Name</UserName>
  <Password>pass</Password>
</ExternalLogin>

 
If you change the order of the UserName and Password nodes the method will fail because Password is not recognized anymore:
 
<ExternalLogin>
  <Password>pass</Password>
  <UserName>Name</UserName>
</ExternalLogin>

 
This behaviour is intended by design for Data Contracts in WCF and Sana Commerce uses WCF for the web service.
For additional information see: http://msdn.microsoft.com/en-us/library/ms729813.aspx.


Requests in the JSON format should not contain whitespaces between the properties. This is because of the way the JSON request is parsed by the WCF.

For example, the following JSON request:

{
  "UserName":"Name",
  "Password":"pass"
}
should be in one line without whitespaces:
 
{"UserName":"Name","Password":"pass"}
How toWeb Service Developer Guide