> ## Documentation Index
> Fetch the complete documentation index at: https://sendcloud.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

## Before you begin

Before you can start making requests towards Sendcloud APIs, [register a Sendcloud account](https://sendcloud.dev/docs/getting-started.md), and [obtain your Public and Secret API keys](https://sendcloud.dev/docs/getting-started/how-to-create-your-api-keys.md) in order to authenticate your requests.

When adding an API integration in the Sendcloud platform, take a look at the following settings:

* **Service Points**: allows the API integration to be used in `servicepoint.sendcloud.sc` API.
* **Use OAuth2 authentication**: enforces the integration to use OAuth2 authentication instead of basic, otherwise it fails.

## OAuth2 authentication

[OAuth2](https://en.wikipedia.org/wiki/OAuth) provides a token-based authentication mechanism. Obtain an access token by authenticating with the OAuth2 server, then include the obtained token in the `Authorization` headers of your API requests.

```sh Example request using curl theme={null}
# Generate an OAuth2 access token
curl -X POST --location "https://account.sendcloud.com/oauth2/token" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials&scope=api" \
  --basic --user your_sendcloud_public_key:your_sendcloud_private_key
```

The response for the above request will be similar to the following:

```json Response body theme={null}
{
  "access_token": "ory_at_dK...",
  "expires_in": 3599,
  "scope": "api",
  "token_type": "bearer"
}
```

> [!NOTE]
>
> Access tokens expire 1 hour after they are issued, as indicated by `expires_in` (in seconds). Cache the access token
> and request a new one shortly before it expires, instead of requesting a token for every API call.

This request returns an `access_token`, which you can use in subsequent API requests:

```sh Example request using curl theme={null}
# Make a request to the Sendcloud API using OAuth2 authentication
curl --location "https://panel.sendcloud.sc/api/v2/user" \
  --header "Authorization: Bearer ${access_token}"
```

## Basic Authentication

Sendcloud uses [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) for authenticating requests for APIs, where your username is your **Public Key** and your password is your **Private Key** as provided for your integration.

> [!CAUTION]
>
> Do not share your Private API keys in publicly accessible areas such as GitHub, client-side code, etc.

### Authenticating your requests

Once you have obtained your Public and Private keys, start authenticating your requests. To do this, include your keys in your requests.

```sh Example request using curl theme={null}
curl --location 'https://panel.sendcloud.sc/api/v2/parcels' \
--header 'Accept: application/json' \
--header 'Authorization: Basic <base64-encoded-token>'
```

The `Authorization` header value is constructed by combining the API keys (base64-encoded) separated by a colon (`:`).

While this example uses `curl`, you can use any programming language or HTTP client that supports setting HTTP headers to make authenticated requests to the Sendcloud API.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.