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

# Enroll a customer

> Enroll a customer in the loyalty program.

Enroll a customer in the loyalty program. If the customer is already enrolled, their existing record is returned with `200 OK` instead.

Only `shopify_customer_id` is required — the endpoint fetches the customer's name, email, and account creation date directly from Shopify.

## Request body

| Field                 | Type   | Required | Description                        |
| --------------------- | ------ | -------- | ---------------------------------- |
| `shopify_customer_id` | string | Yes      | The customer's Shopify customer ID |

```json theme={null}
{
  "shopify_customer_id": "6789012345"
}
```

## Response

Returns `201 Created` on successful enrollment, or `200 OK` if the customer was already enrolled.

The response shape matches the [customer object](/api-reference/customers/object).

## Errors

| Status | Scenario                                      |
| ------ | --------------------------------------------- |
| `400`  | `shopify_customer_id` missing or invalid JSON |
| `404`  | No Shopify customer found with that ID        |
| `503`  | Unable to connect to Shopify                  |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.mageloyalty.com/v1/customers \
    --header 'Authorization: <api-key>' \
    --header 'Content-Type: application/json' \
    --data '{
    "shopify_customer_id": "6789012345"
  }'
  ```

  ```javascript Node theme={null}
  const response = await fetch("https://api.mageloyalty.com/v1/customers", {
    method: "POST",
    headers: {
      Authorization: "<api-key>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      shopify_customer_id: "6789012345",
    }),
  });

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.mageloyalty.com/v1/customers",
      headers={"Authorization": "<api-key>"},
      json={"shopify_customer_id": "6789012345"},
  )

  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init("https://api.mageloyalty.com/v1/customers");
  curl_setopt_array($ch, [
      CURLOPT_POST => true,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTPHEADER => [
          "Authorization: <api-key>",
          "Content-Type: application/json",
      ],
      CURLOPT_POSTFIELDS => json_encode([
          "shopify_customer_id" => "6789012345",
      ]),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</RequestExample>

<ResponseExample>
  ```json 201 Created theme={null}
  {
    "data": {
      "type": "customer",
      "id": "6789012345",
      "attributes": {
        "shopify_customer_id": "6789012345",
        "email": "jane@example.com",
        "first_name": "Jane",
        "last_name": "Doe",
        "current_points": 0,
        "lifetime_points": 0,
        "redeemed_points": 0,
        "loyalty_status": "member",
        "date_of_birth": null,
        "referral_url": "https://mystore.myshopify.com?referral_code=ABC123",
        "referral_code": "ABC123",
        "vip_tier": {
          "id": "tier_abc",
          "name": "Bronze",
          "threshold": 0,
          "points_multiplier": 1,
          "badge_image_url": null,
          "badge_color": "#CD7F32"
        },      "created_at": "2026-06-23T12:00:00.000Z",
        "updated_at": "2026-06-23T12:00:00.000Z"
      }
    }
  }
  ```

  ```json 200 Already Enrolled theme={null}
  {
    "data": {
      "type": "customer",
      "id": "6789012345",
      "attributes": {
        "shopify_customer_id": "6789012345",
        "email": "jane@example.com",
        "first_name": "Jane",
        "last_name": "Doe",
        "current_points": 450,
        "lifetime_points": 1200,
        "redeemed_points": 750,
        "loyalty_status": "member",
        "date_of_birth": "1990-05-15T00:00:00.000Z",
        "referral_url": "https://mystore.myshopify.com?referral_code=ABC123",
        "referral_code": "ABC123",
        "vip_tier": {
          "id": "tier_abc",
          "name": "Gold",
          "threshold": 500,
          "points_multiplier": 1.5,
          "badge_image_url": null,
          "badge_color": "#FFD700"
        },      "created_at": "2024-01-15T10:00:00.000Z",
        "updated_at": "2024-06-20T14:30:00.000Z"
      }
    }
  }
  ```

  ```json 404 Not Found theme={null}
  {
    "errors": [
      {
        "status": "404",
        "title": "Not Found",
        "detail": "Shopify customer '6789012345' not found"
      }
    ]
  }
  ```

  ```json 503 Service Unavailable theme={null}
  {
    "errors": [
      {
        "status": "503",
        "title": "Service Unavailable",
        "detail": "Unable to connect to Shopify. Please try again."
      }
    ]
  }
  ```
</ResponseExample>
