Required Parameters

Making a request to Availability is what OnSched is all about. This is usually at the core of every integration to OnSched and requires a few steps to be made to ensure that the right type and number of appointments are booked exactly when, where, and with who you want.

The request URL to get available times from the API requires the Service ID, a start time, and an end time.

curl --location --request GET 'https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=DemoUser' \
--data-urlencode 'client_secret=DemoUser' \
--data-urlencode 'scope=OnSchedApi' \
--data-urlencode 'grant_type=client_credentials'
const params = {
        client_id:     'DemoUser',
        client_secret: 'DemoUser',
        scope:         'OnSchedApi',
        grant_type:    'client_credentials',
      }
      const availabilityURL = 'https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}'
      // querystring.stringify(params) will encode the param data
      // in application/x-www-form-urlencoded format, which is required
      // by the Identity Server
      axios.get( availabilityURL, querystring.stringify( params ) )
           .then( resp => {
             // return the availability object containing available times array
             resolve( resp.data )
           } )
           .catch( error => reject( error ) )
var request = require('request');
var options = {
  'method': 'GET',
  'url': 'https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}',
  'headers': {'Content-Type': 'application/x-www-form-urlencoded' },
  form: {
    'client_id': 'DemoUser',
    'client_secret': 'DemoUser',
    'scope': 'OnSchedApi',
    'grant_type': 'client_credentials'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}",
  "method": "GET",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "Accept": "*/*",
    "Cache-Control": "no-cache",
    "Host": "sandbox-api.onsched.com",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "110",
    "Connection": "keep-alive",
    "cache-control": "no-cache"
  },
  "data": {
    "grant_type": "client_credentials",
    "scope": "OnSchedApi",
    "client_id": "DemoUser",
    "client_secret": "DemoUser"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});
package main
import (
  "fmt"
  "strings"
  "net/http"
  "io/ioutil"
)
func main() {
  url := "https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}"
  method := "GET"
  payload := strings.NewReader("client_id=DemoUser&client_secret=DemoUser&scope=OnSchedApi&grant_type=client_credentials")
  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)
  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()
  body, err := ioutil.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
require "uri"
require "net/http"
url = URI("https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Content-Type"] = "application/x-www-form-urlencoded"
request.body = "client_id=DemoUser&client_secret=DemoUser&scope=OnSchedApi&grant_type=client_credentials"
response = https.request(request)
puts response.read_body
import http.client
conn = http.client.HTTPSConnection("sandbox-api.onsched.com")
payload = 'client_id=DemoUser&client_secret=DemoUser&scope=OnSchedApi&grant_type=client_credentials'
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
conn.request("GET", "/consumer/v1/availability/{serviceId}/{startDate}/{endDate}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var data = "client_id=DemoUser&client_secret=DemoUser&scope=OnSchedApi&grant_type=client_credentials";
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
  if(this.readyState === 4) {
    console.log(this.responseText);
  }
});
xhr.open("GET", "https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "client_id=DemoUser&client_secret=DemoUser&scope=OnSchedApi&grant_type=client_credentials");
Request request = new Request.Builder()
  .url("https://sandbox-api.onsched.com/consumer/v1/availability/{serviceId}/{startDate}/{endDate}")
  .method("GET", body)
  .addHeader("Content-Type", "application/x-www-form-urlencoded")
  .build();
Response response = client.newCall(request).execute();
GET /consumer/v1/availability/{serviceId}/{startDate}/{endDate} HTTP/1.1
Host: sandbox-api.onsched.com
Content-Type: application/x-www-form-urlencoded
Accept: */*
Cache-Control: no-cache
Accept-Encoding: gzip, deflate
Content-Length: 110
Connection: keep-alive
cache-control: no-cache

grant_type=client_credentials&
scope=OnSchedApi&
client_id=DemoUser&
client_secret=DemoUser

Service

The type of Service that is being searched in the request to Availability will make a great effect on Availability. There are two types of Services, the effect they will have on Availability is as follows:

  • Appointment: Weekly availability based on the business hours of the Location, Resource, and Service
  • Event: Closed every day by default with the exception of Allocations created

Service blocks will also effect Availability by filtering out the time slots that conflict with any of the blocks.

Once the Service is decided on, include the ID from that service in the Availability request URL.

Date Range

An Availability request requires both a start and end date in the request URL, submitted with a format of YYYY-MM-DD.

Since Availability is the most complex endpoint to factor the response time will grow with the number of days you're searching for. For example, searching for one day has an approximate response time of 500-600 milliseconds, compared to a month which is nearly double that time averaging 1100-1200 milliseconds.

Resource

Despite being sent in the body of the request instead of the URL, the Resource is also a required parameter when making an Availability request.

If you already know the Resource that you wish to get available times for then simply include the ID for that Resource in the body of the request with the parameter name resourceId and skip to the next step.

Resource Groups
If you do not know the specific resource, but you do know the resource group that you would like to be booked, you may instead provide the value of the resource group's ID to the property resourceGroupId in the body of the request.

Round Robin
Otherwise, if it does not matter which resource you would like to find available times for, you can provide a value of zero to the resourceId property. If a zero is provided to the resourceId property then a value of 1 (Random) or 2 (Balanced) must also be provided for roundRobin, this will change how the appointments are distributed:

📘

Round Robin Settings

None If you are providing a resourceId to the body of the request you can use a value of zero for the roundRobin property, this is done by default if you do not include that property in the body of the request

Balanced If a value of 1 is provided to the property roundRobin the time slots will be distributed evenly when possible

Random If a value of 2 is provided to the property roundRobin the time slots will be distributed at random to whoever is available at that time


What’s Next
Did this page help you?