0

I've never done anything with APIs before so this question is going to be badly asked.

We use a online scheduling tool called ScheduleOnce. That tool has the ability to utilize webhooks, per this article https://developers.oncehub.com/reference#introduction, to notify other systems of bookings behind made.

What I don't know how to do, nor find the information on apparently, is how do I listen for / consume the POST message in Salesforce? I want to create a record in a custom object whenever a booking is made in that scheduling tool.

Not asking for anyone to write any code for me. I just can't seem to figure out the starting point for this. Found plenty of info on how to have Salesforce post to another system but not finding how to consume the message from another system.

Thanks!

1
  • 1
    Hmm, that site seems to not include any authentication parameters in their webhook messages, which is not so good since to receive them you have to expose an endpoint to the unauthenticated Internet.
    – David Reed
    Commented Oct 12, 2020 at 17:41

1 Answer 1

1

It sounds like what you are asking about is a custom Apex REST service. Keep in mind it looks like OnceHub has a Salesforce integration. I would attempt to exhaust that option first before even considering a custom integration.

That said, you can create and expose a custom REST endpoint that accepts only POST requests for the use case you shared. There are examples in the documentation linked, but I'm including a code sample here for completeness.

@RestResource(urlMapping='/CaseManagement/v1/*')
global with sharing class CaseMgmtService {

    @HttpPost
    global static String attachPic(){
        RestRequest req = RestContext.request;
        RestResponse res = Restcontext.response;
        Id caseId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Blob picture = req.requestBody;
        Attachment a = new Attachment (ParentId = caseId,
                                       Body = picture,
                                       ContentType = 'image/jpg',
                                       Name = 'VehiclePicture');
        insert a;
        return a.Id;
   }
}

The most difficult part of doing something like this is security. You want the endpoint to be available to OnceHub, but not to anyone else by using some sort of authentication like OAuth. Not all APIs that use webhooks are possible to configure to use an authentication mechanism such as this so look at the OnceHub documentation to see what is possible.

1
  • Thanks! This gets me started down that path. I do know that they have their managed package but it only works on standard objects like Leads and Opportunities which my org doesn't use. I could create some PB or Trigger that would then create another record but seems like a bad practice.
    – Matt M
    Commented Oct 12, 2020 at 19:43

Not the answer you're looking for? Browse other questions tagged .