> For the complete documentation index, see [llms.txt](https://samypesse.gitbook.io/commercetools-demo/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://samypesse.gitbook.io/commercetools-demo/sdk/api.md).

# API Reference

This section documents the SDK packages APIs.

## Importing

Every function described in each package below is a top-level export. You can import any of them like this:

#### ES6

```js
import { createClient } from '@commercetools/sdk-client'
```

#### ES5 (CommonJS)

```js
var createClient = require('@commercetools/sdk-client').createClient
```

#### ES5 (UMD build)

```js
// We recommend to use https://unpkg.com as CDN
var createClient = CommercetoolsSdkClient.createClient
```

## Core

### `sdk-client`

Core package to enable executing HTTP [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest). To be used together with middlewares.

* [createClient(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkClient.md#createclient)

## Middlewares

It's up to you to pick whatever middleware fits your needs: you can compose them together, create your own custom versions, choose only one of them (*e.g. you might not need authentication, but you need to send http requests*).

### `sdk-middleware-auth`

Middleware to authenticate the [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest) using one of the supported *auth flows*.

* [createAuthMiddlewareForClientCredentialsFlow(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareAuth.md#createauthmiddlewareforclientcredentialsflowoptions)
* [createAuthMiddlewareForPasswordFlow(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareAuth.md#createauthmiddlewareforpasswordflow)
* [createAuthMiddlewareForRefreshTokenFlow(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareAuth.md#createauthmiddlewareforrefreshtokenflow)
* [createAuthMiddlewareForAnonymousSessionFlow(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareAuth.md#createauthmiddlewareforanonymoussessionflow)
* [createAuthMiddlewareWithExistingToken(authorization, options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareAuth.md#createauthmiddlewarewithexistingtoken)

### `sdk-middleware-http`

Middleware to send the actual HTTP [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest).

* [createHttpMiddleware(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareHttp.md#createhttpmiddlewareoptions)
* [getErrorByCode(code)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareHttp.md#geterrorbycode)

### `sdk-middleware-queue`

Middleware to throttle concurrent [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest) to a certain limit. Useful to reduce concurrent HTTP requests.

* [createQueueMiddleware(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareQueue.md#createqueuemiddlewareoptions)

### `sdk-middleware-logger`

Middleware to log incoming [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest) and [response](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientresponse) objects.

* [createLoggerMiddleware(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareLogger.md#createloggermiddlewareoptions)

### `sdk-middleware-user-agent`

Middleware to automatically set the `User-Agent` to the [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest).

* [createUserAgentMiddleware(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareUserAgent.md#createuseragentmiddlewareoptions)

### `sdk-middleware-correlation-id`

Middleware to add a correlation id to [requests](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest).

* [createCorrelationIdMiddleware(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/sdkMiddlewareCorrelationId.md)

## Helpers

Those are optional packages that provides help building the final [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest). You can choose to use them but you don't have to.

### `api-request-builder`

Provides an API to construct a URI for the HTTP API endpoints in a declarative way. Useful for building [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest) `uri` for requests.

* [createRequestBuilder(customServices)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/apiRequestBuilder.md#createrequestbuildercustomservices)

### `http-user-agent`

Creates a proper HTTP User-Agent. Can be used everywhere.

* [createHttpUserAgent(options)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/httpUserAgent.md#createhttpuseragentoptions)

### `sync-actions`

Provides an API to construct update actions. Useful for building [request](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/Glossary.md#clientrequest) `body` for updates.

* [createSyncCategories(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsynccategoriesactiongroups)
* [createSyncCustomers(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsynccustomersactiongroups)
* [createSyncInventories(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsyncinventoriesactiongroups)
* [createSyncProducts(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsyncproductsactiongroups)
* [createSyncOrders(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsyncordersactiongroups)
* [createSyncDiscountCodes(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsyncdiscountcodesactiongroups)
* [createSyncProductDiscounts(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsyncproductdiscountsactiongroups)
* [createSyncCustomerGroup(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsynccustomergroupactiongroups)
* [createSyncCartDiscounts(actionGroups)](https://github.com/SamyPesse/commercetools-nodejs/blob/master/sdk/api/syncActions.md#createsynccartdiscountsactiongroups)
