Linked Services
Linked Services allows each Resource to specify the Services for which they can be booked. By default a Resource is able to be booked for all services within the Business Location, however, if Linked Services are added to the Resource, then all others Services become disabled.
Linking a Service
Services can be linked to a resource via the Setup API Interface using the a POST request. To link a Service the only parameter you will need is the Resource. In the body pass an array of strings with the services' IDs that you want to link to a Resource.
curl -X POST
'https://sandbox-api.onsched.com/setup/v1/resources/{RESOURCE_ID}/services'
--header 'Content-Type: application/json-patch+json'
--header 'Accept: application/json'
--header 'Authorization: Bearer {AUTH_TOKEN}'
-d '["116572", "116574", "116577"]
POST /setup/v1/resources/{RESOURCE_ID}/services HTTP/1.1
Host: sandbox-api.onsched.com
Content-Type: application/json
Authorization: Bearer {AUTH_TOKEN}
Accept: */*
Cache-Control: no-cache
Host: sandbox-api.onsched.com
Accept-Encoding: gzip, deflate
Content-Length: 102
Cookie: ARRAffinity={RANDOM_STRING}
Connection: keep-alive
cache-control: no-cache
["116572", "116572", "116572"]
var request = require("request");
var options = { method: 'POST',
url: 'https://sandbox-api.onsched.com/setup/v1/resources/{RESOURCE_ID}/services',
headers:
{ 'cache-control': 'no-cache',
Connection: 'keep-alive',
Cookie: 'ARRAffinity={RANDOM_STRING}}',
'Content-Length': '102',
'Accept-Encoding': 'gzip, deflate',
Host: 'sandbox-api.onsched.com',
'Cache-Control': 'no-cache',
Accept: '*/*',
Authorization: 'Bearer {AUTH_TOKEN}',
'Content-Type': 'application/json' },
body: ["116572", "116572", "116572"],
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
var settings = {
"async": true,
"crossDomain": true,
"url": "https://sandbox-api.onsched.com/setup/v1/resources/{RESOURCE_ID/services",
"method": "POST",
"headers": {
"Content-Type": "application/json",
"Accept": "*/*",
"Cache-Control": "no-cache",
"Host": "sandbox-api.onsched.com",
"Accept-Encoding": "gzip, deflate",
"Content-Length": "102",
"Cookie": "ARRAffinity={RANDOM_STRING}",
"Connection": "keep-alive",
"cache-control": "no-cache"
},
"processData": false,
"data": "["116572", "116572", "116572"]"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
You can also link a Service from the PUT /resources endpoint in the Setup API Interface However, the previous approach is recommended because the performance penalty is lower.
To updated the linked services, call PUT resources/{RESOURCE_ID) updating the "serviceIds" property with an array containing the Ids of the services you want to link as the following:
{
"serviceIds": [
"116572",
"116574",
"116577",
],
}
Retrieving Possible Resources
Once you have linked your resources to their respective applicable services, you can retrieve all of the resources that can be booked for a specific service in the Setup API Interface by calling the endpoint: GET /setup/v1/services/{service_id}/resources.
The results from this query will return all of the resource objects that are linked to the service specified in the request URL.
Updated about 2 years ago