API reference
Create a customer
How to create a customer via API
To create a new customer, send a POST request to the /api/customers endpoint, passing the resource arguments in the request body.

Request

POST https://yourdomain.commercelayer.io/api/customers

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.email
string
Required
attributes.password
string
Optional
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional
relationships.customer_group
object
Optional

Example

Request
Response
The following request creates a new customer:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/customers' \
3
-H 'Accept: application/vnd.api+json' \
4
-H 'Authorization: Bearer your-access-token' \
5
-H 'Content-Type: application/vnd.api+json' \
6
-d '{
7
"data": {
8
"type": "customers",
9
"attributes": {
10
"email": "[email protected]"
11
}
12
}
13
}'
Copied!
On success, the API responds with a 201 Created status code, returning the created resource object:
1
{
2
"data": {
3
"id": "xYZkjABcde",
4
"type": "customers",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde"
7
},
8
"attributes": {
9
"email": "[email protected]",
10
"status": "prospect",
11
"has_password": false,
12
"created_at": "2018-01-01T12:00:00.000Z",
13
"updated_at": "2018-01-01T12:00:00.000Z",
14
"reference": "ANY-EXTERNAL-REFEFERNCE",
15
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
16
"metadata": {
17
"foo": "bar"
18
}
19
},
20
"relationships": {
21
"customer_group": {
22
"links": {
23
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/customer_group",
24
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/customer_group"
25
}
26
},
27
"customer_addresses": {
28
"links": {
29
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/customer_addresses",
30
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/customer_addresses"
31
}
32
},
33
"customer_payment_sources": {
34
"links": {
35
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/customer_payment_sources",
36
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/customer_payment_sources"
37
}
38
},
39
"customer_subscriptions": {
40
"links": {
41
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/customer_subscriptions",
42
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/customer_subscriptions"
43
}
44
},
45
"orders": {
46
"links": {
47
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/orders",
48
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/orders"
49
}
50
},
51
"order_subscriptions": {
52
"links": {
53
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/order_subscriptions",
54
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/order_subscriptions"
55
}
56
},
57
"returns": {
58
"links": {
59
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/returns",
60
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/returns"
61
}
62
},
63
"attachments": {
64
"links": {
65
"self": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/relationships/attachments",
66
"related": "https://yourdomain.commercelayer.io/api/customers/xYZkjABcde/attachments"
67
}
68
}
69
},
70
"meta": {
71
"mode": "test"
72
}
73
}
74
}
Copied!
Copy link