TheShark TheShark - 1 year ago 193
JSON Question Partner API - Rest, JSON, RestSharp?

I have a custom order management system, written in I now need to use the partner api for integration with them. I'm sure this isn't hard for you web experts out there, but I don't have much experience with RESTful calls to apis.

The documentation I have ( says:

Jet API Security Flow
The following security flow is the assumed flow for accessing Jet API functions that require authorization:

User submits his/her credentials over SSL/TLS to Jet API /api/Token endpoint via HTTPS POST request, like below:
Content-Type: application/json; charset=utf-8
Content-Length: 42


/api/Token endpoint is a single point of authentication for Jet API users. Therefore, it does not require either authentication or authorization.

If the user successfully authenticated, the security (bearer) token is returned back over SSL/TLS carrying claims associated with the user encoded and signed:
HTTP/1.1 200 OK
Cache-Control: no-store
Pragma: no-cache
Content-Length: XXX
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.0
Set-Cookie: auth0=XXX...XX; path=/; secure; httponly
Server: nginx/1.7.1
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Wed, 06 Aug 2014 13:50:17 GMT
Set-Cookie: SERVERID=03-4BRURJ6FFLMCK; path=/


Token is contained in JSON node id_token that should be used in the following HTTP requests to Jet API as authorization vehicle (see article 4 below) until it expires or gets refreshed.

If not authenticated at the /api/Token endpoint, the user gets back HTTP response carrying header HTTP/1.1 401 Unauthorized.
Having the above bearer token, the user then should provide it when calling other Jet API endpoints as part of HTTPS requests within Authorization header. This header has the following form: Authorization: Bearer
If the user has proper permissions associated with the token he/she will be allowed to access the endpoints and/or specific data assigned by those permissions. The request will be executed and response will be defined by the correspondent called API function, otherwise HTTP/1.1 401 Unauthorized response is returned back.

Bearer tokens provided to Jet API users have a limited lifetime. However, until the token expires, the bearer token will be a full substitute for user credentials, so the token must be handled as private cryptographic material.

Can anyone show me some sample code to do this in C#? I was thinking using RestSharp would be helpful, but don't have any experience with that either.

For their API I need:
1.) Authorize my API calls
2.) Upload products in JSON
3.) Retrieve order information

So, I stuck at the first phase, authorizing my API calls.


Answer Source

Hi You can use this sample code, i have generated this code using this link

var client = new RestClient("");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "xxxx");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("authorization", "Basic xxxx");
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", "{\"user\":\"xxxx\",\"pass\":\"xxxx\"}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download