Make generic Skedulo API requests using Salesforce

Making generic requests to the Skedulo API using Salesforce.

Non-specialized (Generic) API requests

The Generic input is used for APIs that do not have dedicated methods for calling them. It has the following definition:

global Generic(String httpMethod, String path, Map<String, String> params, String jsonBody)
  • httpMethod: The following verbs are supported: GET, POST, PUT, DELETE, PATCH.
  • path: The path portion of the Skedulo API url.
  • params: List of (Key, Value) query parameters being sent to Skedulo API. This must not be null. Use an empty map when there is no query parameter.
  • jsonBody: JSON encoded request body being sent to the Skedulo API. Use null when there is no JSON body.

Make a GET API request

  1. Log in to your Skedulo account in Salesforce.
  2. Open the Developer Console. a. Click the Settings cog in the upper-right corner. b. Select Developer Console.
  3. Select Debug -> Open Execute Anonymous Window, or press Ctrl + E.
  4. Enter the following Apex code to make a GET request to the /config/org_preference endpoint:
sked.ApiInput.Generic input1 = new sked.ApiInput.Generic('GET', '/config/org_preference', new Map<String, String>(), null);
System.debug(sked.SkeduloAPI.callAPI(input1));
  1. Click Execute.

  2. Select the Debug Only filter in the Execution Log and open the USER_DEBUG event to view the log and confirm the job has been dispatched. If the job has been dispatched correctly, the output in the log should be the JSON response for the /config/org_preference request:

    15:32:05:732 USER_DEBUG [2]|DEBUG|Generic:[CalloutResultBase.message=null, CalloutResultBase.response={"result":{"allowAbortJob":false,"attachmentsDownload":false,"enableHIPAACompliance":false,"futureJobBuffer":0,"jobTasksAreOptional":false,"enableCompletionNotes":true,"popupCompletionNotes":false,"turnOnChatter":true,"saveAttachmentAsFile":false,"enableSMSResponse":true,"allowJobsToBeDeclined":true,"dispatc...
    

Make POST API requests

You can also make API calls that include a JSON request body by specifying inputJson in the input definition. The following example demonstrates how to call the /availability/resources endpoint in the Salesforce Developer Console.

Map<String, Object> inputJson = new Map<String, Object>{
    'availability' => true,
    'unavailability' => true,
    'start' => DateTime.newInstance(2019, 5, 13, 0, 0, 0),
    'end' => DateTime.newInstance(2019, 5, 14, 59, 59, 59),
    'regionIds' => new String[]{'a0M2v00000KuYI6EAN'},
    'resourceFilter' => 'ResourceType IN [\"Person\"]'
};

sked.ApiInput.Generic input1 = new sked.ApiInput.Generic(
    'POST',
    '/availability/resources',
    new Map<String, String>(),
    JSON.serialize(inputJson)
);
System.debug(sked.SkeduloAPI.callAPI(input1));

The result of the above query returns the following information in the log:

16:53:12:588 USER_DEBUG [16]|DEBUG|Generic:[CalloutResultBase.message=null, CalloutResultBase.response={"result":{"a0X2v00000MKToREAX":{"available":[],"unavailable":[{"start":"2019-05-12T14:00:00Z","end":"2019-05-16T01:59:59Z"}],"availability":{"records":[[],[],[]],"entries":{"template":{},"holiday":{},"custom":{}}},"unavailability":{"defaults":[{"start":"201...

Make GraphQL API requests

You can make GraphQL requests in the same way as the POST request demonstrated above. The following example requests all current job offers:

Map<String, Object> inputJson = new Map<String, Object>{
    'query' => 'query ($filter: EQLQueryFilterJobOffers!) {\n jobOffers(filter: $filter) {\n edges {\n node {\n UID\n Status\n Job {\n UID\n GeoLatitude\n GeoLongitude\n }\n ResourceJobOffers {\n UID\n Status\n Response\n TimeNotified\n TimeResponded\n CreatedDate\n Resource {\n UID\n Name\n Category\n GeoLatitude\n GeoLongitude\n NotificationType\n }\n }\n ResourceRequirement {\n UID\n }\n }\n }\n }\n }',
        'variables' => new Map<String, String>{'filter' => 'JobId IN []'}
};

sked.ApiInput.Generic input1 = new sked.ApiInput.Generic(
    'POST',
    '/graphql/graphql',
    new Map<String, String>(),
    JSON.serialize(inputJson)
);
System.debug(sked.SkeduloAPI.callAPI(input1));

Note that line breaks are not permitted in string fields, therefore line breaks must be represented in GraphQL queries as \n.