These endpoints will allow you to easily manage locales. Base URI is /api/v1/locales.
If you request a locale via API, you will receive an object with the following fields:
Field | Description |
---|---|
id | Id of the locale |
code | Unique locale identifier |
If you request for more detailed data, you will receive an object with the following fields:
Field | Description |
---|---|
id | Id of the locale |
code | Unique locale identifier |
updatedAt | Last update date of the locale |
createdAt | Creation date of the locale |
Note
Read more about Locales in the component docs</components_and_bundles/components/Locale/models>
.
To create a new locale you will need to call the /api/v1/locales/
endpoint with the POST
method.
POST /api/v1/locales/
Parameter | Parameter type | Description |
---|---|---|
Authorization | header | Token received during authentication |
code | request | (unique) Locale identifier |
curl http://demo.sylius.com/api/v1/locales/ \
-H "Authorization: Bearer SampleToken" \
-H "Content-Type: application/json" \
-X POST \
--data '
{
"code": "pl"
}
'
STATUS: 201 CREATED
{
"id": 4,
"code": "pl",
"createdAt": "2017-02-14T12:49:38+0100",
"updatedAt": "2017-02-14T12:49:39+0100",
"_links": {
"self": {
"href": "\/api\/v1\/locales\/pl"
}
}
}
If you try to create a locale without code you will receive a 400 Bad Request
error.
curl http://demo.sylius.com/api/v1/locales/ \
-H "Authorization: Bearer SampleToken" \
-H "Content-Type: application/json" \
-X POST
STATUS: 400 Bad Request
{
"code": 400,
"message": "Validation Failed",
"errors": {
"children": {
"code": {
"errors": [
"Please enter locale code."
]
}
}
}
}
To retrieve the details of a locale you will need to call the /api/v1/locales/code
endpoint with the GET
method.
GET /api/v1/locales/{code}
Parameter | Parameter type | Description |
---|---|---|
Authorization | header | Token received during authentication |
code | url attribute | Code of the requested locale |
To see the details of the locale with code = pl
use the below method:
curl http://demo.sylius.com/api/v1/locales/pl \
-H "Authorization: Bearer SampleToken" \
-H "Accept: application/json"
Note
The pl code is just an example. Your value can be different.
STATUS: 200 OK
{
"id": 4,
"code": "pl",
"createdAt": "2017-02-14T12:49:38+0100",
"updatedAt": "2017-02-14T12:49:39+0100",
"_links": {
"self": {
"href": "\/api\/v1\/locales\/pl"
}
}
}
To retrieve a paginated list of locales you will need to call the /api/v1/locales/
endpoint with the GET
method.
GET /api/v1/locales/
Parameter | Parameter type | Description |
---|---|---|
Authorization | header | Token received during authentication |
page | query | (optional) Number of the page, by default = 1 |
paginate | query | (optional) Number of items to display per page, by default = 10 |
To see the first page of all locales use the below method:
curl http://demo.sylius.com/api/v1/locales/ \
-H "Authorization: Bearer SampleToken" \
-H "Accept: application/json"
STATUS: 200 OK
{
"page": 1,
"limit": 10,
"pages": 1,
"total": 3,
"_links": {
"self": {
"href": "\/api\/v1\/locales\/?page=1&limit=10"
},
"first": {
"href": "\/api\/v1\/locales\/?page=1&limit=10"
},
"last": {
"href": "\/api\/v1\/locales\/?page=1&limit=10"
}
},
"_embedded": {
"items": [
{
"id": 2,
"code": "en_US",
"_links": {
"self": {
"href": "\/api\/v1\/locales\/en_US"
}
}
},
{
"id": 3,
"code": "af",
"_links": {
"self": {
"href": "\/api\/v1\/locales\/af"
}
}
},
{
"id": 4,
"code": "pl",
"_links": {
"self": {
"href": "\/api\/v1\/locales\/pl"
}
}
}
]
}
}
To delete a locale you will need to call the /api/v1/locales/code
endpoint with the DELETE
method.
DELETE /api/v1/locales/{code}
Parameter | Parameter type | Description |
---|---|---|
Authorization | header | Token received during authentication |
code | url attribute | Code of the removed locale |
curl http://demo.sylius.com/api/v1/locales/pl \
-H "Authorization: Bearer SampleToken" \
-H "Accept: application/json" \
-X DELETE
STATUS: 204 No Content