1

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.

enter image description here

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?

1 Answer 1

2

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

0

You must log in to answer this question.

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