Skip to content

mergeBasket requires Content-Type: application/json #114

@johnboxall

Description

@johnboxall

ShopperBaskets.mergeBasket requires the content-type application/json or it fails with an HTTP 415 (unsupported media type).

The API itself is a bit odd, in that no request body is needed, so this behaviour is sorta unexpected.

Maybe our existing logic is looking for the existence of a required request payload to send this header:

{{#if (isRequestWithPayload request)}}
"Content-Type": "{{{getMediaTypeFromRequest request}}}",
{{/if}}

It might be a safe default to always send it or alternatively special case this method.

Alternatively, maybe we could request a change to the RAML. 🤷

The workaround for customers is to provide the header manually:

const mergeResponse = await new capi.ShopperBaskets(
    clientConfig
).mergeBasket({
    headers: {
        "Content-Type": "application/json",
    },
    parameters: { createDestinationBasket: true },
})

Here is a sample script showing the behaviour:

https://gist.github.com/johnboxall/eed791f95ad6636baa01269a1d178bbb

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions