# Create a customer

This guide describes how to create a customer using the [Rebilly JS SDK](https://www.npmjs.com/package/rebilly-js-sdk), [Express JS](https://expressjs.com/en/starter/installing.html), and the [Upsert a customer API operation](/catalog/all/customers/putcustomer).

- Prerequisites

  To complete this guide, you must have a website ID, an organization ID, and a secret API key.

  If you already have your IDs and API keys, continue to [Step 1: Set up the server](#step-1-set-up-the-server).
  If you do not, get your IDs and API key in [Set up your environment](/docs/dev-docs/set-up-environment).

## Step 1: Set up the server

This section describes how to set up your server-side code to create customers using the Rebilly JS SDK.

1. Install the required dependencies in your project directory:

```bash
npm install express rebilly-js-sdk@latest --save
```
2. Initialize Express and the Rebilly SDK as dependencies.

Provide your secret key, website ID, and organization ID.
For more information, see [Prerequisites](/docs/dev-docs/set-up-environment).

Store your secret key in a secrets manager, not in your code.

Set up the Rebilly JS SDK and provide your secret API key.
Set `sandbox` to `true` to test in the sandbox environment.

Define a route for handling HTTP POST requests to the `/create-customer` endpoint.

This endpoint uses the Rebilly SDK `customers.upsert()` method to create or update customers.

Create the customer data object with the required structure for the Rebilly API, including the customer ID, website ID, and primary address information.

Use the Rebilly SDK `customers.upsert()` method to create or update the customer.
This method creates a new customer if the ID does not exist, or updates an existing customer if it does.

Implement error handling to catch and respond to any errors that occur during customer creation.
This includes API errors, validation errors, and network issues.

The error response includes the HTTP status code and detailed error information from the Rebilly API.

## Step 2: Set up the form

This section describes how to create a form that collects customer information and simulates a customer registration or authentication.
Customer information is sent to the server to create or update a customer.

Create an HTML form with fields for customer information:

- Customer ID (required) - Enter your external identifier for the customer.
If the ID already exists in Rebilly, the API updates the customer's information.
If the ID does not exist, a new customer is created.
- First name (required)
- Last name (required)
- Email (required)
- Phone (optional)

You can also provide other fields that are supported by the [Upsert a customer API operation](/catalog/all/customers/putcustomer), such as address and date of birth.

Add JavaScript to handle form submission and send the data to your server endpoint.

## Step 3: Test the customer creation

This section describes how to test the customer creation functionality.

Run `server.js`. When the server is running, open a browser and visit `http://localhost:8080`.

```bash
node server.js
```