Johnson_Lu1 | 2018-03-19 14:52:32 UTC | #1
Hi,
I am new to Data Action. May I seek advice.
I create a Data Action to get all the default PureCloud Status, however, my Data Action hit error as below:
Error running action test { "status": 400, "code": "invalid.schema", "message": "JSON failed schema validation for the following reasons: instance type (array) does not match any allowed primitive type (allowed: [\"object\"])", "messageParams": {}, "contextId": "e06c3468-2119-4534-89dd-71a30e793e99", "details": [], "errors": [] }
Here are my Data Action details:
Input Contract { "$schema": "http://json-schema.org/draft-04/schema#", "title": "SystemPresenceRequest", "description": "System Presence request.", "type": "object", "properties": {} }
Output Contract { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Get System Presence Response", "description": "Returns all system’s presence.", "type": "object", "properties": { "name": { "description": "The system presence name, which indicates whether the system presences in PureCloud.", "type": "string", "title": "Presence Name" }, "id": { "description": "The system presence ID, which indicates whether the system presences in PureCloud.", "type": "string", "title": "Presence ID" } } }
Configuration
Request { "requestUrlTemplate": "/api/v2/systempresences", "requestType": "GET", "headers": { "UserAgent": "PureCloudIntegrations/1.0", "Content-Type": "application/x-www-form-urlencoded" }, "requestTemplate": "${input.rawRequest}" }
Response { "translationMap": {}, "successTemplate": "${rawResult}" }
The error is as below
- Validate output against schema
{ "status": 400, "code": "invalid.schema", "message": "JSON failed schema validation for the following reasons: instance type (array) does not match any allowed primitive type (allowed: [\"object\"])", "messageParams": {}, "contextId": "e06c3468-2119-4534-89dd-71a30e793e99", "details": [], "errors": [] }
Can someone comment on my mistakes?
Best regards,
Johnson
Jason_Mathison | 2018-03-21 19:06:10 UTC | #2
The PureCloud api is returning an array of objects which requires changes to the output contract as well as the successTemplate.
Your output contract was expecting the GetSystemPresence API to return something like:
{
"name" : "some name",
"id" : "some id"
}
However the API was returning an array of objects like that, so we need to update the output contract to indicate it will be an array of values. Also, we have to assign that array to a variable in order for this to be valid JSON. Finally, I made the statuses array required, this helps ensure that everything is wired up correctly.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["statuses"],
"properties": {
"statuses": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "The Name Schema "
},
"id": {
"type": "string",
"title": "The Id Schema "
}
}
}
}
}
}
Finally we need to update the successTemplate to assign the returned array to the statuses value and wrap everything in curly braces to make it an object.
"successTemplate": "{ \"statuses\" : ${rawResult} }"
Johnson_Lu1 | 2018-03-22 09:22:55 UTC | #3
Thank you very much, Jason
I have a question, may I know what is this programming language is? I think I should pick up the syntax of this language.
Regards,
Johnson
Jason_Mathison | 2018-03-22 14:35:35 UTC | #4
We tried to stick with common standards/libraries for our configuration:
The templates are Apache Velocity Templates The schemas are standard JSON Schemas The template map uses JSONPath to extract data into variables
I typically use online tools like: https://jsonlint.com/ to validate JSON https://jsonschema.net/ to generate a schema from an example response http://jsonpath.com/ to test and create JSONPath
Johnson_Lu1 | 2018-03-23 14:21:55 UTC | #5
Appreciate for the sharing, Jason
system | 2018-04-23 14:25:38 UTC | #6
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: 2641