Salesforce webhook for Wufoo form integration

I have a wufoo form (survey) which goes out to different clients. On submit I want the wufoo form to call an Apex REST class on my Salesforce org and post data which will be created in a record for a custom object.

Salesforce webhook for Wufoo form integration

The Webhook URL is: https://myinstance.salesforce.com/services/apexrest/MySurveyClass

This is my code for the post:

@RestResource(urlMapping='/MySurveyClass/*')
global with sharing class SurveyWebhook {
    
    @HttpPost
    global static void getSurveyData() {
        RestRequest req = RestContext.request;
        System.debug('------------------- survey data from wufoo: ' + JSON.deserializeuntyped(req.requestBody.toString()));
    }
}

I do not know the format of the POST data Wufoo is going to send.
When I submit the form it gives an error for the webhook integration saying:

(401) [{“message”:”Session expired or
invalid”,”errorCode”:”INVALID_SESSION_ID”}]

I believe this is because I am not sending the session id or some authorzation key. How do I do this? Also, how do I read the data from the POST body?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

As you are setting up the REST service as WebHook, you have to access this over a public URL.

You can’t access the service with this Salesforce instance URL
https://myinstance.salesforce.com/services/apexrest/MySurveyClass
without authorization.

In Wufoo console I don’t think there is any option to provide Salesforce authentication/authorization details.

So first create a Force.com site and add the REST class and any relevant objects/fields to your Site’s Public Access Settings. So that you can access the REST methods via the Site URL without login.

The URL will look like this: https://<Your Force.com Site URL>/services/apexrest/MySurveyClass

Add this URL as WebHook URL in Wufoo console. Now you are ready to get the form details in Salesforce and do your processing like saving in a custom object.

Your REST Class should look like this:

@RestResource(urlMapping='/MySurveyClass/*') 
global with sharing class MySurveyClass {
    @HttpPost 
    global static void doPost(){
        RestRequest req = RestContext.request;
        String EntryId = req.params.get('EntryId');
        String Field1 = req.params.get('Field1');
        .....
        .....
        .....
    }
}

Where EntryId, Field1 are the form field names in the Wufoo form.

The quickest way to see what data will be sent from the webhook is to submit a new entry to your form and visit the following link to see the entry in xml format with all the relevant fields: https://<yourAccountName>.wufoo.com/api/v3/forms/<yourFormName>/entries.xml


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x