Getting a 400 Bad Request from our external endpoint when the Genesys Cloud Data Action tries to parse the request body. The error log in the Data Action monitor shows Invalid JSON syntax at line 1, position 1. It’s weird because the JSON looks perfectly valid in Postman.
Here is the Data Action configuration for the HTTP request:
{
"name": "GetCognigyProfile",
"type": "http",
"url": "https://api.cognigy.ai/v1/profiles/{{user.id}}/tokens",
"method": "GET",
"headers": {
"Authorization": "Bearer {{oauth.token}}"
}
}
The issue seems to be how Genesys passes the user.id variable. If the user hasn’t been identified yet, {{user.id}} might be null or an empty string, causing the URL to malformed or the body parsing to fail if Cognigy expects a specific format. Wait, it’s a GET request, so there is no body. The error message Invalid JSON syntax suggests the response from Cognigy is not valid JSON, or Genesys is trying to parse the response as JSON and failing.
I added a response handler to log the raw response:
{
"status": 200,
"body": "<html><body><h1>404 Not Found</h1></body></html>"
}
Ah, so Cognigy is returning HTML for 404s. Genesys Cloud Data Actions expect a JSON response by default if you don’t specify the content type or handle non-JSON responses. The Data Action fails because it tries to parse the HTML as JSON.
Is there a way to configure the Data Action to handle non-JSON responses or to add a fallback if the response isn’t JSON? I’ve tried setting Accept: application/json in the headers, but Cognigy still returns HTML for errors.
Also, how do I check if {{user.id}} is null before making the request? I don’t want to hit the external API with an empty ID. I’ve looked at the Architect expressions, but I’m not sure how to conditionally execute a Data Action based on a variable’s value.