jet.com 合作伙伴 API - 休息,JSON,RestSharp?

jet.com Partner API - Rest, JSON, RestSharp?

我有一个自定义订单管理系统,用VB.net编写。我现在需要使用 jet.com 合作伙伴 api 来与他们集成。我相信这对你们这些网络专家来说并不难,但我对 RESTful 调用 apis.

没有太多经验

documentation I have 说:

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:

POST https://merchant-api.jet.com/api/Token HTTP/1.1 
Host: merchant-api.jet.com 
Content-Type: application/json; charset=utf-8 
Content-Length: 42 

{"user":"dummy@jet.com","pass":"XXXXXXXX"} 

/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=/ 

{"id_token":"XXX...XX","access_token":"XXX...XX","token_type":"bearer"} 

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.

任何人都可以告诉我一些在 C# 中执行此操作的示例代码吗?我在想使用 RestSharp 会有所帮助,但也没有任何经验。

为了他们的 API 我需要:

  1. 授权我的 API 通话
  2. 在 JSON
  3. 中上传产品
  4. 检索订单信息
  5. 等等

所以,我停留在第一阶段,授权我的 API 调用。

您好,您可以使用此示例代码,我使用 this link

生成了此代码
var client = new RestClient("https://merchant-api.jet.com/api/token/");
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);