Salesforce Unauthenticated Survey

swagataray Avatar

Unauthenticated Survey – An “unauthenticated survey” refers to a survey that can be accessed and completed by individuals who are not required to log in or authenticate their identity. These surveys are often used for gathering feedback from a wide range of respondents, including anonymous users or customers. These customers do not have access to the Salesforce community or another way of saying is that they are not community member. Some people wants to participate to the survey anonymously and this one the best scenarios for them.

To configure the Salesforce Survey, use this link

In this blog I am going to discuss about the Salesforce Unauthenticated Survey APIs which you can use for following reason

  1. Generate a survey invitation for a contact or lead(Not a community User aka Unauthenticated user)
  2. Get the Survey settings which can be parsed and displayed in the non Salesforce application.
  3. Submit the survey response

Business scenario

You have a customer facing application such as online store where customer can buy items anonymously. That online store relies on the Salesforce, a backend CRM solution for any kind of survey. Currently you want to lunch a new line of products and you need feedback as much as possible on this upcoming product line. So you created a survey in Salesforce and wants to display that on your online store. For more clarity, refer to the below diagram

Step by Step Process to use Salesforce Unauthenticated Survey

Step 1

Send a token request to a specific endpoint. This endpoint, we do not use for our common OAuth authorization.

The URL is

<Your domain>.sandbox.my.salesforce-scrt.com​/surveys/v1/accessToken

Step 2 – Generate the survey invitation

Getting the survey JSON. This JSON needs to be parsed at the front end and show the intended survey with questions and other detailed stuff. The response will look like below

Always check the end point correctly. As I mentioned earlier, this end point is not the usual one.

End Point – <Your Domain>.sandbox.my.salesforce-scrt.com​/surveys/v1/survey-response

In the payload, you need to pass recipient ID and survey developer name. Remember Recipient Id can only be Lead or Contact. Also you need to pass the authorization token as a bearer token.

Request Body

Below response from Salesforce survey endpoint as a JSON format which needs to be parsed and display at the front end.

 

“errors”:[], // Errors observed in the API call

    “flowInterviewState”:”<Unique String. This value will be passed to the next call>“,

   “invitationId”:”<Unique id and needs to be passed>“,

   “status”:”<Success/Failed. Status of this API call>“,

   “surveyDetail”:{

      “label”:”<Label of survey>“, 

      “name”:”<Developer Name of Survey>“,

      “surveyPage”:{

         “label”:”<Internal label of page>“, 

         “name”:”<Internal name of the page>“,

         “surveyQuestions”:[ // List of questions

            {

               “description”: “<Description of the question>”,

               “isResponseRequired”: <true/false based on if response is required>,

               “label”:”<Survey question>“,

               “name”:”<Unique Question name which needs to be passed in the next call>“,

               “questionType”:”<Type of the question>“,

               “responseDataType”:”<Object type of response>“,

               “validationFormula”: <Formula if any custom validation is added>

            }

Step 3 (Get next page of the unauthenticated survey)

To go to the next or previous page, you need to pass following payload. And the response will be same as previous step.

Step 4 (Submit the unauthenticated survey response)

Send the Unauthenticated survey response back to Salesforce using following payload. Interestingly the end point for step 2 and step 3 are same.

There are a couple of things needs to be taken care when it comes to Salesforce unauthenticated Survey

  1. Create a sharing rule for the guest user so that they can access Contact and Lead. Because this is unauthenticated survey, unless you are providing the access explicitly, guest user can not able to access those and thus survey failed.
  2. Account can not be attached with the survey invitation.
  3. To getting the token and the use the unauthenticated survey invitation, use full domain name + ‘-scrt.com
           Example
           Full domain – https://xyzmydomain.sandbox.my.salesforce.com
           Scrt endpoint – ‘-scrt.com
  4. Getting the org id using this SOQL –    SELECT Id, Name FROM Network
  5. Currently API only supports Basic survey.
swagataray Avatar

Leave a Reply

Discover more from Tech Talk

Subscribe now to keep reading and get access to the full archive.

Continue reading