Custom action on custom integration: invalid.schema error on JSON response

I'm currently trying to create a custom action for a custom integration that calls one of my REST web services. When testing the custom action, the request succeeds, but the test fails on the "Validate output against schema" step. It gives the following error:

{
"status": 400,
"code": "invalid.schema",
"message": "JSON failed schema validation because it was malformed JSON. reason: 'Unrecognized token 'html5': was expecting ('true', 'false' or 'null')\n at [Source: (StringReader); line: 1, column: 6]'",
"messageParams": {},
"contextId": "1d036e0d-b14b-4ef9-8015-57e07948cffb",
"details": [],
"errors": []
}

The actual response from the web service is: "html5-e50fd861-96cd-4abb-a2e3-8edada33bdb3", which I can see in the "Apply Output Transformation" step. This is a valid response from the web service and is valid JSON (my header includes Accept: application/json)

The Response Configuration is:
{
"translationMap": {
},
"successTemplate": "${rawResult}"
}

The Response Contract is:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "My Response",
"description": "This is the contract that will be enforced. See the success template for how this is produced. Returns the full response.",
"properties": {
}
}

I'm new to integration development with PureCloud. Can someone point me in the right direction to fix the Response Contract and/or Translation Map so that the test succeeds?

Thanks!
Evan

The Data Action service isn't really designed for returning a String like this since the consumers of the data action are expecting to get an object back. Since your output contract is configured to not return anything from the data action you could change your success template to this:

"successTemplate": "{}"

Or if you need to make use of the response from your web service you need to make it part of a key/value pair and wrap it in an JSON object, like this:

"successTemplate": "{\"Output_Contract_Property_Name\" : ${rawResult}}"

This is exactly what I needed. Thanks!

Ultimately, I needed to return the string value, so I changed my output contract to:

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "My Response",
"description": "This is the contract that will be enforced. See the success template for how this is produced. Returns the full response.",
"type":"object",
"properties": {
"token":{
"type":"string"
}
}
}

and Response Configuration to:
{
"translationMap": {},
"successTemplate": "{"token" : ${rawResult}}"
}

All works now. Much appreciated.

Evan

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