SalesforceCommerceCloud / commerce-sdk

https://salesforcecommercecloud.github.io/commerce-sdk/
BSD 3-Clause "New" or "Revised" License
149 stars 48 forks source link

ShopperLogin - getAccessToken - 415 Unsupported Media Type #348

Closed andrewgadziksonos closed 2 years ago

andrewgadziksonos commented 2 years ago

Hello!

I'm trying to use the getAccessToken function from the ShopperLogin client, and I'm getting a 415 Unsupported Media Type response.

Looking at the source code this is where the issue is,

return core_1.StaticClient.post({
      client: this,
      rawResponse: rawResponse,
      path: "/organizations/{organizationId}/oauth2/token",
      pathParameters: pathParameters,
      queryParameters: queryParameters,
      retrySettings: (options || {}).retrySettings,
      headers: headers,
      body: (options || {}).body,
    });

core_1.StaticClient.post internally is setting the body property to body: JSON.stringify(options.body), which is wrong for this particular API. The body should be body: new URLSearchParams(options.body).toString() and the Content-Type header set to application/x-www-form-urlencoded

wjhsf commented 2 years ago

Hi @andrewgadziksonos, thanks for reporting this issue! We will have a fix released in the next week or two. I'll let you know as soon as the release is done.

wjhsf commented 2 years ago

This issue should be fixed in v2.6.1 of the SDK.