interface FetchOptions<T> {
    accessToken?: string;
    correlationId?: string;
    data?: T;
    headers?: Record<string, string>;
    method: "GET" | "DELETE" | "HEAD" | "POST";
    params?: Record<string, any>;
    path: string;
    retry?: CommercetoolsRetryConfig;
}

Type Parameters

  • T = any

Properties

accessToken?: string

Access token to use as the value for the Authorization bearer token

Typically, this would be the access token that belongs to a customer. This must be passed in when using one of the me endpoints.

If this property is not passed in, we fall back to using the client access token.

correlationId?: string

Value to be passed in the X-Correlation-ID HTTP header

data?: T

Plain JavaScript object containing the payload to send as JSON

This object will be converted to a JSON string and sent as the body of a POST or DELETE request.

headers?: Record<string, string>

Key/value pairs representing the HTTP headers to send

You can pass in any headers you like using this property, however this is generally not necessary, as the {@see CommercetoolsApi.request} method applies all necessary headers.

You should specifically avoid setting values for the following headers:

  • Authorization
  • Content-Type
  • X-Correlation-ID
  • User-Agent

All of the above are set by the CommercetoolsApi class.

Example value:

{
...
headers: {
'X-My-Special-Header': 'MyCustomValue'
}
...
}
method: "GET" | "DELETE" | "HEAD" | "POST"

HTTP method to use when sending the request

params?: Record<string, any>

Querystring parameters to send with the request

Key/value pairs that are then converted in to a querystring using the qs npm package. See the paramSerializer option in {@see CommercetoolsApi.createAxiosInstance} for implementation details.

path: string

Path of the REST endpoint

This is the absolute path, without the host/schema/port etc. You should not include your project key, as this will be automatically prepended.

Example: /product-projections

Note that if you want to create a path that takes into account the store key that you defined in {@see CommercetoolsApiConfig} then you should use the {@see CommercetoolsApi.applyStore} method.

Request retry configuration

The request retry configuration can be set on the CommercetoolsApi instance or on a request by request basis. If no value is passed in here, we fall back to using the configuration provided when constructing the CommercetoolsApi instance. If no value was passed in to the constructor configuration, then no retries will take place.