Adding Form Data in Genesys Cloud Data Action

Hi All,

I have used the Web Services data actions integration to create a series of data actions for a CRM. This is working, however the 'Data Action (Auth)' action is currently encoding credentials within the URL.

This CRM supports receiving these credentials encoded within the URL, or as Form Data - but not as json in the request. I am trying to refactor this to avoid sending credentials in the request URL.

I am able to successfully call this API from Postman while providing credentials as Form Data, however I am unable to replicate this success using Data Actions within Genesys Cloud.

I've seen another post where a Genesys employee shared an example from their notes, however this failed validation when I tried it, and I haven't been able to find a way to make this work.
Other Post: How to add Form Data in PureCloud Action Request

Has anyone managed to get this working?

I've got the following config (I've left some out and redacted my creds, but I'm sharing what I think is relevant. Feel free to ask for more if you need to see anything else):

Content-Type: multipart/form-data
Request Body (from Postman Console):
Request Body
grant_type: "refresh_token"
client_id: "myclientid"
client_secret: "myclientsecret"
refresh_token: "myrefreshtoken"

Request Body Template (From Genesys Cloud):
"requestTemplate": "grant_type=$esc.url("refresh_token")&refresh_token=$esc.url("myrefreshtoken")&client_id=$esc.url("myclientid")&client_secret=$esc.url("myclientsecret")"

Result from step 7 of the test tool - Resolve Request Body Template:
""requestTemplate": "grant_type=refresh_token&refresh_token=&client_id=&client_secret=""

Error from API:
"message": "The request could not be understood by the server due to malformed syntax.",
"code": "bad.request",
"status": 400,
"messageParams": {},

Your example has Content-Type of multipart-form-data.

Try changing that to:

"headers": {
"Content-Type": "application/x-www-form-urlencoded"
}

Hi Lloyd,

Thanks for the suggestion.

I've tried that, however I'm now receiving the following error from the API:
{
"error": "invalid_client"
}

For reference, this same error occurs if I make the request from Postman with no params.

It's worth noting that I had tried this value initially, but changed it to match the value that Postman is successfully using.

Your step 7 results look suspicious:

"requestTemplate": "grant_type=refresh_token&refresh_token=&client_id=&client_secret=""

It looks like you are attempting to use variables for the token/id/secret, but the variables are empty. Could you either post an export of the action so we can see exactly how it is set up, or open up a support ticket so we can look at what is going on privately?

--Jason

Hi Jason,

Here is an updated Step 7:
"{\n\t\"requestTemplate\": \"grant_type=refresh_token&refresh_token=<REDACTED>&client_id=<REDACTED>&client_secret=<REDACTED>\"\n}"

Here is the export of my Auth action:
{ "name": "Zoho CRM - PROD (Auth) - Exported 2022-03-18 @ 9:51", "integrationType": "custom-rest-actions", "actionType": "customAuth", "config": { "request": { "requestUrlTemplate": "https://accounts.zoho.com.au/oauth/v2/token", "requestType": "POST", "headers": { "Host": "accounts.zoho.com.au", "Accept-Encoding": "gzip, deflate, br", "Accept": "application/json", "Content-Type": "application/x-www-form-urlencoded", "Connection": "keep-alive", "Authorization": "Basic $encoding.base64(\"${credentials.clientId}:${credentials.clientSecret}\")" }, "requestTemplate": "{\n\t\"requestTemplate\": \"grant_type=refresh_token&refresh_token=$esc.url(${credentials.refreshToken})&client_id=$esc.url(${credentials.clientId})&client_secret=$esc.url(${credentials.clientSecret})\"\n}" }, "response": { "translationMap": {}, "translationMapDefaults": {}, "successTemplate": "${rawResult}" } }, "contract": { "input": { "inputSchema": { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Auth Input", "description": "No Input Value", "type": "object", "properties": {} } }, "output": { "successSchema": { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": {}, "additionalProperties": true } } }, "secure": false }

And here is the export of my working version (the published version of the same action):
{ "name": "Zoho CRM - PROD (Auth) - Exported 2022-03-18 @ 9:50", "integrationType": "custom-rest-actions", "actionType": "customAuth", "config": { "request": { "requestUrlTemplate": "${credentials.loginUrl}?refresh_token=${credentials.refreshToken}&client_id=${credentials.clientId}&client_secret=${credentials.clientSecret}&grant_type=refresh_token", "requestType": "POST", "headers": { "Authorization": "Basic $encoding.base64(\"${credentials.clientId}:${credentials.clientSecret}\")", "Host": "accounts.zoho.com.au", "Accept-Encoding": "gzip, deflate, br", "Accept": "*/*", "Content-Type": "application/json" }, "requestTemplate": "${input.rawRequest}" }, "response": { "translationMap": {}, "translationMapDefaults": {}, "successTemplate": "${rawResult}" } }, "contract": { "input": { "inputSchema": { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Auth Input", "description": "No Input Value", "type": "object", "properties": {} } }, "output": { "successSchema": { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": {}, "additionalProperties": true } } }, "secure": false }

Good news everyone, I've got this working!

Here is my Request Body Template:
grant_type=refresh_token$urlTool.optionalQueryParam("refresh_token", $!{credentials.refreshToken})$urlTool.optionalQueryParam("client_id", $!{credentials.clientId})$urlTool.optionalQueryParam("client_secret", $!{credentials.clientSecret})

It is worth noting that the template example on this page does not work. The "/" within this template prevent the Action from validating.

If the description on that page could be changed from:
amount=${input.AMOUNT}$urlTool.optionalQueryParam(\"description\", $!{input.DESCRIPTION})

To:
amount=${input.AMOUNT}$urlTool.optionalQueryParam("description", $!{input.DESCRIPTION})

Then it will work.

So, long story short, it's working now. For reference (in case anyone wants to shortcut doing this themselves) here is a working export of my action:

{
  "name": "Zoho CRM - PROD (Auth) - Exported 2022-03-18 @ 10:23",
  "integrationType": "custom-rest-actions",
  "actionType": "customAuth",
  "config": {
    "request": {
      "requestUrlTemplate": "https://accounts.zoho.com.au/oauth/v2/token",
      "requestType": "POST",
      "headers": {
        "Host": "accounts.zoho.com.au",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept": "application/json",
        "Content-Type": "application/x-www-form-urlencoded",
        "Connection": "keep-alive",
        "Authorization": "Basic $encoding.base64(\"${credentials.clientId}:${credentials.clientSecret}\")"
      },
      "requestTemplate": "grant_type=refresh_token$urlTool.optionalQueryParam(\"refresh_token\", $!{credentials.refreshToken})$urlTool.optionalQueryParam(\"client_id\", $!{credentials.clientId})$urlTool.optionalQueryParam(\"client_secret\", $!{credentials.clientSecret})"
    },
    "response": {
      "translationMap": {},
      "translationMapDefaults": {},
      "successTemplate": "${rawResult}"
    }
  },
  "contract": {
    "input": {
      "inputSchema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "title": "Auth Input",
        "description": "No Input Value",
        "type": "object",
        "properties": {}
      }
    },
    "output": {
      "successSchema": {
        "$schema": "http://json-schema.org/draft-04/schema#",
        "type": "object",
        "properties": {},
        "additionalProperties": true
      }
    }
  },
  "secure": false
}

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.