Resources API
Fetches catalog resources given a valid filter.
The Resources API allows for fetching resources given a valid filter in the same way they are fetched in .json page files. Maximum of 5 at a time. The resource data will be on the data
property.
Note: This was the deprecated resource
API.
Example
fetch('/s/api/v1/resources', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': 'csrf_token_from_csrf_meta_tag',
'Accept': 'application/json'
},
body: JSON.stringify({
input: {
'items': {
type: 'item-list',
filters: {}
},
'item': {
type: 'item',
filters: {
'id': '15'
'square_online_id': true
}
},
'category': {
type: 'category',
filters: {
'id': '5',
'square_online_id': true
}
}
}
})
})
.then((response) => response.text())
.then((text) => {
node.innerHTML = text;
});
Meta
On successful load of a resource, additional meta information is available on the meta
property.
At the moment, only paginate
exists and provides the pagination context for the following resources:
- category-list
- discount-list
- item-list
- location-list
You can use the pagination context to do pagination via pagination.page
and pagination.page_size
on a resource request.
Error handling
If a resource fails to load, the resource name will have an errors
key populated in the response object. The errors
key will also be populated with any validation errors pertaining to the resource query filters.
Valid resource filters to resources that exist be populated in the response even if other resources are invalid or do not exist.
Example
Payload
{
"input": {
"foo": {
"type": "INVALID_TYPE",
"filters": {
"id": "15",
"square_online_id": true
}
},
"featuredCategory": {
"type": "category",
"filters": {
"id": "NON_EXISTENT_ID",
"square_online_id": true
}
},
"item": {
"type": "item",
"filters": {
"id": "2",
"square_online_id": true
}
},
"items": {
"type": "item-list"
}
}
}
Response
{
"foo": {
"errors": [
"Invalid type INVALID_TYPE"
]
},
"featuredCategory": {
"errors": [
"Resource not found"
]
},
"item": {
"errors": [],
"data": {
...item attributes
},
"meta": {}
},
"items": {
"errors": [],
"data": [
{
...item attributes
},
...more items
],
"meta": {
"paginate": {
"current_page": 1,
"limit": 100,
"total": 3,
"total_pages": 1
}
}
},
}