gvasagam | 2019-03-20 13:23:02 UTC | #1
Hi,
I am trying to test data action to update a data table. After going through all the documentation and few posts such as this, created the data action with the following config :
CONTRACT:
Input:
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "Update Table", "description": "using this to update the table", "type": "object", "required": [ "datatableId", "Score"
], "properties": { "datatableId": { "description": "dataTableId", "type": "string" }, "Score": { "description": "Score", "type": "integer" }, "primaryKey": { "description": "Which key to update", "type": "string" } } }
OutPut :
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "Update table", "properties": {} }
CONFIGURATION :
Request:
Request URL Template : /api/v2/flows/datatables/${input.datatableId}/rows/${input.primaryKey}
Headers :
UserAgent : PureCloudIntegrations/1.0 Content-Type : application/json Transfer-Encoding : buffered
Request Body Template
"requestTemplate": "{"Score": ${input.Score},"Key":"${input.primaryKey}"}"
Response:
{ "translationMap": {}, "translationMapDefaults": {}, "successTemplate": "{}" }
My DataTable is very simple with two rows with Reference Key Label named as "primaryKey" and one custom field "score" which is integer
.
the Test passes until step 7 but fails at Execute with Status : 400. I can see the URL template getting resolved as expected
and Resolve request body template
Appreciate any help with this.
Error:
{ "status": 400, "code": "bad.request", "message": "The request could not be understood by the server due to malformed syntax.", "messageParams": {}, "contextId": "2a054f8e-0f13-44b1-a3dc-14a8fe7b6db2", "details": [ { "errorCode": "ACTION.REMOTEENDPOINT" } ], "errors": [ { "status": 400, "code": "BADREQUEST", "message": "REST call for action execute failed. Message:Request to backend service failed. Response from web service: {\"status\":400,\"code\":\"bad.request\",\"message\":\"The request could not be understood by the server due to malformed syntax.\",\"contextId\":\"90b9d791-14e9-49bf-8f73-37400fe7abd3\",\"details\":[],\"errors\":[]} [2a054f8e-0f13-44b1-a3dc-14a8fe7b6db2]", "messageParams": {}, "details": [], "errors": [] } ] }
Jason_Mathison | 2019-03-20 15:35:32 UTC | #2
Please export your action and attach it to this thread. That avoids everyone having to cut and paste all over the place, and avoids the forum messing up any of the escaping that is in your action.
A few things to look at while you are there: You can remove the "Transfer-Encoding : buffered" header. That shouldn't be an issue for a PureCloud action I would guess that primaryKey should be a required property in your input contract. I have never used this API before, so I don't know if this is an issue or not, but should the "Key" in your requestTemplate be "primaryKey" to match the Reference Key Label?
For speed of debugging have you tried to get this working in the developer tools api-explorer? https://developer.mypurecloud.com/developer-tools/#/api-explorer
gvasagam | 2019-03-21 04:24:13 UTC | #3
@Jason_Mathison My bad. Here are two versions of the configuration that I tried <a class="attachment" href="/forum/uploads/db6296/original/2X/6/6ad19ecdc99a191632209602bb5cc33b0b792447.json">updateTableTest-20190320211439.custom.json</a> (1.5 KB) <a class="attachment" href="/forum/uploads/db6296/original/2X/5/5efefc5ee96452f30fe4b345bd45391c8dfdbfce.json">UpdateTableTestV2-20190320211756.custom.json</a> (1.5 KB)
I did use the developer tool to test the API before attempting to create the data action. I have attached the result of the API "/api/v2/flows/datatables/{datatableId}/rows" in <a class="attachment" href="/forum/uploads/db6296/original/2X/6/69cd1fd98830996e20ec71a77a90d39a8840f865.json">GETDataTableRows.json</a> (290 Bytes) where you can see that the table just has 2 fields 1. Reference key label -"primaryKey" and 2. an integer field "Score". This is where I noticed the JSON data returns the reference field as "Key" and not the label that I originally defined when I do a GET.
When I attempted PUT via the Dev tool ( /api/v2/flows/datatables/{datatableId}/rows/{rowId} ), what I noticed is that,
If I just give the Request body with value for field "Score", I was getting an error
{ "Score": 1234 }
This fails with Error 400
and the update happens successfully only if I mention the request body as
{ "Score": 7890, "Key":"11" }
200 OK
update : Tried with postman and that works. Don't understand why the same fail when used in the Data action. Console snippet from PostMan:
PUT /api/v2/flows/datatables/9b32e4cb-20a0-4167-94a7-615248021796/rows/12 Content-Type: application/json cache-control: no-cache Postman-Token: <<<<<>>>>>>> Authorization: <<<<<>>>>>>> User-Agent: PostmanRuntime/7.6.1 Accept: / Host: api.mypurecloud.ie cookie: pcAuth-userPrefLangTag=en-us; pcAuth-userPrefLocale=en_us accept-encoding: gzip, deflate content-length: 39 { "Score": 123456, "Key":"12" } HTTP/1.1 200 status: 200 Content-Type: application/json Content-Length: 27 Connection: keep-alive Date: Thu, 21 Mar 2019 04:02:10 GMT inin-ratelimit-count: 1 inin-ratelimit-allowed: 300 inin-ratelimit-reset: 60 ININ-Correlation-Id: 9938d75c-3604-4804-93dd-352d0265d1c2 Strict-Transport-Security: max-age=600; includeSubDomains Cache-Control: no-cache, no-store, must-revalidate Pragma: no-cache Expires: 0 X-Cache: Miss from cloudfront Via: 1.1 415c421af891d7c3f4ade60aba542014.cloudfront.net (CloudFront) X-Amz-Cf-Id: 8QoINjjx-sZ3eKpRRTQpXjWS9PLPzze5Gfn-9XfJ2uvTqs4Ws4UG1g== {"score":123456,"key":"12"}
Jason_Mathison | 2019-03-21 14:04:19 UTC | #4
Thank you for posting the action exports as well as the postman output, using that I am pretty sure that the improvements to our action configuration UI caught you. If you go to the configuration page and click on "JSON" (instead of Simple) and look at the requestTemplate you will see that it is "requestTemplate": "\"requestTemplate\": \"{\"Score\": ${input.Score},\"Key\":\"${input.Key}\"}\""
Changing the request template in the UI to: {"Score": ${input.Score},"Key":"${input.Key}"} should get you fixed up.
gvasagam | 2019-03-21 14:27:42 UTC | #5
Jason_Mathison, post:4, topic:4826
{"Score": ${input.Score},"Key":"${input.Key}"}
Yup, failed to notice that. :) It worked. Thanks a ton.
system | 2019-04-21 14:27:43 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: 4826