Chilkat Online Tools

unicodeC / Selling Partner API for Authorization / Returns the Login with Amazon (LWA) authorization code for an existing Amazon MWS authorization.

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW queryParams;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *code;
    const wchar_t *message;
    const wchar_t *details;
    const wchar_t *AuthorizationCode;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    queryParams = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(queryParams,L"sellingPartnerId",L"proident deserunt ea mollit aute");
    CkJsonObjectW_UpdateString(queryParams,L"developerId",L"proident deserunt ea mollit aute");
    CkJsonObjectW_UpdateString(queryParams,L"mwsAuthToken",L"proident deserunt ea mollit aute");

    CkHttpW_SetRequestHeader(http,L"Accept",L"application/json");

    resp = CkHttpW_QuickRequestParams(http,L"GET",L"https://sellingpartnerapi-na.amazon.com/authorization/v1/authorizationCode",queryParams);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(queryParams);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "payload": {
    //     "authorizationCode": "in irure ipsum id Duis"
    //   },
    //   "errors": [
    //     {
    //       "code": "Excepteur in",
    //       "message": "est irure nulla sint dolore",
    //       "details": "irure ex"
    //     },
    //     {
    //       "code": "exercitation sit esse",
    //       "message": "ut fugiat ea",
    //       "details": "Excepteur esse"
    //     }
    //   ]
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    AuthorizationCode = CkJsonObjectW_stringOf(jResp,L"payload.authorizationCode");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"errors");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        code = CkJsonObjectW_stringOf(jResp,L"errors[i].code");
        message = CkJsonObjectW_stringOf(jResp,L"errors[i].message");
        details = CkJsonObjectW_stringOf(jResp,L"errors[i].details");
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(queryParams);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -G -d "sellingPartnerId=proident%20deserunt%20ea%20mollit%20aute"
	-d "developerId=proident%20deserunt%20ea%20mollit%20aute"
	-d "mwsAuthToken=proident%20deserunt%20ea%20mollit%20aute"
	-H "Accept: application/json"
https://sellingpartnerapi-na.amazon.com/authorization/v1/authorizationCode

Postman Collection Item JSON

{
  "name": "Returns the Login with Amazon (LWA) authorization code for an existing Amazon MWS authorization.",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "authorization",
        "v1",
        "authorizationCode"
      ],
      "query": [
        {
          "key": "sellingPartnerId",
          "value": "proident deserunt ea mollit aute",
          "description": "(Required) The seller ID of the seller for whom you are requesting Selling Partner API authorization. This must be the seller ID of the seller who authorized your application on the Marketplace Appstore."
        },
        {
          "key": "developerId",
          "value": "proident deserunt ea mollit aute",
          "description": "(Required) Your developer ID. This must be one of the developer ID values that you provided when you registered your application in Developer Central."
        },
        {
          "key": "mwsAuthToken",
          "value": "proident deserunt ea mollit aute",
          "description": "(Required) The MWS Auth Token that was generated when the seller authorized your application on the Marketplace Appstore."
        }
      ]
    },
    "description": "With the getAuthorizationCode operation, you can request a Login With Amazon (LWA) authorization code that will allow you to call a Selling Partner API on behalf of a seller who has already authorized you to call Amazon Marketplace Web Service (Amazon MWS). You specify a developer ID, an MWS auth token, and a seller ID. Taken together, these represent the Amazon MWS authorization that the seller previously granted you. The operation returns an LWA authorization code that can be exchanged for a refresh token and access token representing authorization to call the Selling Partner API on the seller's behalf. By using this API, sellers who have already authorized you for Amazon MWS do not need to re-authorize you for the Selling Partner API.\n\n**Usage Plan:**\n\n| Rate (requests per second) | Burst |\n| ---- | ---- |\n| 1 | 5 |\n\nFor more information, see \"Usage Plans and Rate Limits\" in the Selling Partner API documentation."
  },
  "response": [
    {
      "name": "Success.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"in irure ipsum id Duis\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"Excepteur in\",\n      \"message\": \"est irure nulla sint dolore\",\n      \"details\": \"irure ex\"\n    },\n    {\n      \"code\": \"exercitation sit esse\",\n      \"message\": \"ut fugiat ea\",\n      \"details\": \"Excepteur esse\"\n    }\n  ]\n}"
    },
    {
      "name": "Request has missing or invalid parameters and cannot be parsed.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    },
    {
      "name": "Indicates that access to the resource is forbidden. Possible reasons include Access Denied, Unauthorized, Expired Token, or Invalid Signature.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    },
    {
      "name": "The resource specified does not exist.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    },
    {
      "name": "The request size exceeded the maximum accepted size.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Request Entity Too Large",
      "code": 413,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation.\n_Note:_ For this status code, the rate limit header is deprecated and no longer returned."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    },
    {
      "name": "The request payload is in an unsupported format.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Unsupported Media Type",
      "code": 415,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation.\n_Note:_ For this status code, the rate limit header is deprecated and no longer returned."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    },
    {
      "name": "The frequency of requests was greater than allowed.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation.\n_Note:_ For this status code, the rate limit header is deprecated and no longer returned."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    },
    {
      "name": "An unexpected condition occurred that prevented the server from fulfilling the request.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation.\n_Note:_ For this status code, the rate limit header is deprecated and no longer returned."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    },
    {
      "name": "Temporary overloading or maintenance of the server.",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "{{baseUrl}}/authorization/v1/authorizationCode?sellingPartnerId=proident deserunt ea mollit aute&developerId=proident deserunt ea mollit aute&mwsAuthToken=proident deserunt ea mollit aute",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "authorization",
            "v1",
            "authorizationCode"
          ],
          "query": [
            {
              "key": "sellingPartnerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "developerId",
              "value": "proident deserunt ea mollit aute"
            },
            {
              "key": "mwsAuthToken",
              "value": "proident deserunt ea mollit aute"
            }
          ]
        }
      },
      "status": "Service Unavailable",
      "code": 503,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "x-amzn-RateLimit-Limit",
          "value": "proident deserunt ea mollit aute",
          "description": "Your rate limit (requests per second) for this operation.\n_Note:_ For this status code, the rate limit header is deprecated and no longer returned."
        },
        {
          "key": "x-amzn-RequestId",
          "value": "proident deserunt ea mollit aute",
          "description": "Unique request reference ID."
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"payload\": {\n    \"authorizationCode\": \"ex in mollit magna\"\n  },\n  \"errors\": [\n    {\n      \"code\": \"qui aliqua dolor e\",\n      \"message\": \"id\",\n      \"details\": \"aliqua ullamco aute dolor\"\n    },\n    {\n      \"code\": \"nostrud occaecat ullamco laboris consequat\",\n      \"message\": \"ea\",\n      \"details\": \"Excepteur Duis irure aute veniam\"\n    }\n  ]\n}"
    }
  ]
}