# Creating a customer

Creating a customer account enables shoppers to purchase when guest checkout is unavailable. This guide will help you understand how to create a customer account by leveraging the API key or access token to authenticate the request. Follow the steps below to successfully set up a new customer account for shoppers on your site.

You can make this request without an access token by passing in your API key as a query parameter. You can also send this request with a valid anonymous or authenticated customer token.

## Creating a shopper

To create a shopper, send a [`POST /v1/shoppers`](https://app.gitbook.com/s/X2fWaY1Kp5sXA1fmOL7z/shoppers/shoppers#v1-shoppers-client-hosted-shopper) request with the customer's information in the request payload. This request requires either an access token or an API key.

If Digital River manages the customer login credentials, include `username` and `password` in the request body, with a base64 encoded `password`.

If your company manages the customer login credentials, include the `externalReferenceId` in the payload. If you do not specify an `externalReferenceId`, Digital River will assign a `shopperId`.

{% hint style="info" %}
**Best Practices**: Explicitly set the `locale` and `currency` for a customer at the start of a session.
{% endhint %}

{% tabs %}
{% tab title="cURL for a Digital River-hosted shopper" %}

```javascript
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic {{access_token}}' \
--header 'Cookie: {{token}}' \
--data-raw '{
  "shopper": {
    "username": "jdoe@dr.com",
    "firstName": "Jane",
    "lastName": "Doe",
    "emailAddress": jdoe@dr.com,
    "password": "jdoepassword",
    "currency": "USD"    
    "locale": "en_US",
  }
}'
```

{% endtab %}

{% tab title="cURL for a client-hosted shopper" %}

```javascript
curl --location -g --request POST 'api.digitalriver.com/v1/shoppers' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic {{access_token}}' \
--header 'Cookie: {{token}}' \
--data-raw '{
  "shopper": {
    "username": "jdoe@acme.com",
    "firstName": "Jane",
    "lastName": "Doe",
    "emailAddress": jdoe@acme.com,
    "currency": "USD"    
    "locale": "en_US",
    "externalReferenceId": "efe44307-ef82-46ed-bef4-e87ebec2ba28"
  }
}'
```

{% endtab %}
{% endtabs %}

## Required payload contents

The required payload contents depend on whether Digital River or your company manages the customer login credentials. Here are the minimum required fields:

* `username`
* `password` (base64 encoded): Only required for a Digital River-hosted shopper.
* `emailAddress`
* `externalReferenceId`: Only required for a client-hosted shopper.
* `firstName`
* `lastName`

{% tabs %}
{% tab title="Payload example" %}

```javascript
{
  "shopper": {
    "username": "jdoe@dr.com",
    "firstName": "Jane",
    "lastName": "Doe",
    "emailAddress": jdoe@dr.com,
    "password": "jdoepassword",
    "currency": "USD"    
    "locale": "en_US",
  }
}
```

{% endtab %}
{% endtabs %}

The response from the server will be an HTTP Status `201 Created`.

After creating the base customer record, you can obtain an authenticated customer token.

{% tabs %}
{% tab title="cURL with an access token" %}

```html
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers' \
--header 'Authorization: bearer {{access_token}}' \ 
...
```

{% endtab %}
{% endtabs %}

The following example passes in your API key instead of an access token:

{% tabs %}
{% tab title="Request sample without an access token" %}

```http
curl --location --request POST 'https://api.digitalriver.com/v1/shoppers? apiKey=your_api_key' \ 
...
```

{% endtab %}
{% endtabs %}
