Customers API
General notes
Customers are used to authorize people with access to shop and place orders.
Content
Customers collection:
Single customer:
Customers collection
Create customer
POST /api/customers
Method for creating new Customer.
Request
| Param | Type | Description | Requirements |
|---|---|---|---|
| Property | Type | Description | Information |
id | int | Identifier | Unique for single customer. |
email | * | ||
| string* | Email for login | Should be valid email address. | |
first_name | * | ||
| string* | First name of a customer | Maximal length is 50 characters. | |
last_name | * | ||
| string* | Last name of a customer | Maximal length is 50 characters. | |
phone | string or * | ||
| null* | Phone number of a customer | Maximal length is 50 characters. | |
is_active | bool | Customer activity state | * |
true for active customer, false for inactive customer. Inactive customer is forbidden to sign in.
last_logged_at | DateTime or null | Customer last login date and time | Read-only.
created_at | DateTime | Customer creation date and time | Read-only.
password | string | Customer's password | Required if is_registered is true. Between 8 - 255 chars long.
password_confirmation |
string* | Customer's password confirmation | Required if is_registered is true. Has to match password.
POST /api/customers HTTP/1.1
Content-Type: application/json
{
"id": 1,
"first_name": "wrfwrf",
"last_name": "ergerg",
"email": "a@a.sk",
"phone": null,
"is_registered": false,
}
Responses
201 CREATED
New Customer was successfully created.
POST /api/customers HTTP/1.1
Content-Type: application/json
Status-Code: 201
{
"id": 1,
"first_name": "wrfwrf",
"last_name": "ergerg",
"email": "a@a.sk",
"phone": null,
"is_active": true,
"last_logged_at": null,
"created_at": "2022-04-28T13:25:12+0200",
"_links": [
{
"href": "/api/v0/customers/1",
"rel": "self",
"type": "GET"
}
]
}
422 UNPROCESSABLE ENTITY
Validation error occurred.
POST /api/customers HTTP/1.1
Content-Type: application/json
Status-Code: 422
{
"type": "ValidationError",
"message": "The given data was invalid.",
"id": "5c99f70a-e400-44bb-9cd4-592b0a30e145",
"errors": [
{
"field": "email",
"message": "The email field is required."
}
]
}
Customers index
GET /api/customers
This method needs permission
readoncustomers.
Get list of existing Customers.
Request
| Index behaviour | Definition |
|---|---|
| Paginated by default | Yes |
| Sorting | id, first_name, last_name, email, phone, is_active, last_logged_at, `created_at`` |
| Filters | id:enum, first_name:string, last_name:string, is_active:bool, email:* |
string, phone:string, last_logged_at:date, created_at:date*
Embedded |
GET /api/customers HTTP/1.1
Responses
200 OK
GET /api/customers HTTP/1.1
Content-Type: application/json
Status-Code: 200
{
"items": [
{
"first_name": "wrfwrf",
"last_name": "ergerg",
"email": "a@a.sk",
"phone": null,
"is_active": true,
"last_logged_at": null,
"created_at": "2022-04-28T13:25:12+0200",
"_links": [
{
"href": "/api/v0/customers/1",
"rel": "self",
"type": "GET"
}
]
}
],
"_meta": {
"page": 1,
"total_pages": 1,
"records": 1,
"per_page": 20
}
}
Single customer
Customer detail
GET /api/customers/{customer_id}
This method needs permission
accessoncustomers.
Get Customer detail.
Request
GET /api/customers/1 HTTP/1.1
Responses
200 OK
GET /api/customers/1 HTTP/1.1
Content-Type: application/json
Status-Code: 200
{
"first_name": "wrfwrf",
"last_name": "ergerg",
"email": "a@a.sk",
"phone": null,
"is_active": true,
"last_logged_at": null,
"created_at": "2022-04-28T13:25:12+0200",
"_links": [
{
"href": "/api/v0/customers/1",
"rel": "self",
"type": "GET"
}
]
}
404 NOT FOUND
Customer was not found.
GET /api/customers/2 HTTP/1.1
Content-Type: application/json
Status-Code: 404
{
"type": "NotFound",
"message": "Required model was not found.",
"id": "0cd85449-05fe-4866-9802-8192e6785fc7"
}
Update customer
PUT/PATCH /api/customers/{customer_id}
This method needs permission
updateoncustomers.
Method for updating Customer data.
Request
| Param | Type | Description | Requirements |
|---|---|---|---|
first_name | string | Customer's first name | Required. Maximal length is 50 characters. |
last_name | string | Customer's last name | Required. Maximal length is 50 characters. |
phone | string | Customer's phone | Nullable. Maximal length is 30 characters. |
is_active | bool | Customer's activity state | Nullable. When null given, activity is set automatically to true. |
For PATCH method any field can be omitted.
PUT /api/customers/1 HTTP/1.1
Content-Type: application/json
{
"first_name": "Jeff",
"last_name": "Way"
}
Responses
200 OK
Customer successfully updated.
PUT /api/customers/1 HTTP/1.1
Content-Type: application/json
Status-Code: 200
{
"first_name": "wrfwrf",
"last_name": "ergerg",
"email": "a@a.sk",
"phone": null,
"is_active": true,
"last_logged_at": null,
"created_at": "2022-04-28T13:25:12+0200",
"_links": [
{
"href": "/api/v0/customers/1",
"rel": "self",
"type": "GET"
}
]
}
404 NOT FOUND
Customer was not found.
PUT /api/customers/2 HTTP/1.1
Content-Type: application/json
Status-Code: 404
{
"type": "NotFound",
"message": "Required model was not found.",
"id": "0cd85449-05fe-4866-9802-8192e6785fc7"
}
422 UNPROCESSABLE ENTITY
Validation error occurred.
PUT /api/customers/1 HTTP/1.1
Content-Type: application/json
Status-Code: 422
{
"type": "ValidationError",
"message": "The given data was invalid.",
"id": "5c99f70a-e400-44bb-9cd4-592b0a30e145",
"errors": [
{
"field": "first_name",
"message": "The first name field is required."
}
]
}
Delete customer
DELETE /api/customers/{customer_id}
This method needs permission
deleteoncustomers.
Method for deleting Customer.
Request
DELETE /api/customers/1 HTTP/1.1
Responses
204 NO CONTENT
Customer successfully deleted.
DELETE /api/customers/1 HTTP/1.1
Status-Code: 204
404 NOT FOUND
Customer was not found.
DELETE /api/customers/1 HTTP/1.1
Content-Type: application/json
Status-Code: 404
{
"type": "NotFound",
"message": "Required model was not found.",
"id": "0cd85449-05fe-4866-9802-8192e6785fc7"
}
Change customer status
POST /api/v0/customers/{customer_id}/status-changes
This method needs permission
createoncustomers.
Method for updating Customer.
Request
post /api/v0/customers/1/status-changes HTTP/1.1
{
"deativation_note": "old Customer",
}
Responses
200 OK
Customer successfully updated.
POST /api/v0/customer/1/status-changes HTTP/1.1
Content-Type: application/json
Status-Code: 200
{
"first_name": "wrfwrf",
"last_name": "ergerg",
"email": "a@a.sk",
"phone": null,
"is_active": true,
"last_logged_at": null,
"created_at": "2022-04-28T13:25:12+0200",
"_links": [
{
"href": "/api/v0/customers/1",
"rel": "self",
"type": "GET"
}
]
}