JayTee | 2022-03-16 00:08:33 UTC | #1
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: https://developer.genesys.cloud/forum/t/how-to-add-form-data-in-purecloud-action-request/5307
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 granttype: "refreshtoken" clientid: "myclientid" clientsecret: "myclientsecret" refresh_token: "myrefreshtoken"
Request Body Template (From Genesys Cloud): "requestTemplate": "granttype=$esc.url("refreshtoken")&refreshtoken=$esc.url("myrefreshtoken")&clientid=$esc.url("myclientid")&client_secret=$esc.url("myclientsecret")"
Result from step 7 of the test tool - Resolve Request Body Template: "\"requestTemplate\": \"granttype=refreshtoken&refreshtoken=<REDACTED>&clientid=<REDACTED>&client_secret=<REDACTED>\""
Error from API: "message": "The request could not be understood by the server due to malformed syntax.", "code": "bad.request", "status": 400, "messageParams": {},
Lloyd | 2022-03-16 00:22:59 UTC | #2
Your example has Content-Type of multipart-form-data.
Try changing that to:
"headers": { "Content-Type": "application/x-www-form-urlencoded" }
JayTee | 2022-03-16 02:20:53 UTC | #3
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.
Jason_Mathison | 2022-03-17 12:29:07 UTC | #4
Your step 7 results look suspicious:
"requestTemplate": "granttype=refreshtoken&refreshtoken=&clientid=&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
JayTee | 2022-03-18 01:18:37 UTC | #5
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\": \"granttype=refreshtoken&refreshtoken=$esc.url(${credentials.refreshToken})&clientid=$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}?refreshtoken=${credentials.refreshToken}&clientid=${credentials.clientId}&clientsecret=${credentials.clientSecret}&granttype=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 } `
JayTee | 2022-03-18 01:19:22 UTC | #6
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. https://help.mypurecloud.com/articles/velocity-macros-data-actions/#optionalQueryParam
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": "granttype=refreshtoken$urlTool.optionalQueryParam(\"refreshtoken\", $!{credentials.refreshToken})$urlTool.optionalQueryParam(\"clientid\", $!{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 }
system | 2022-04-17 23:24:44 UTC | #7
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 13936