Legacy Dev Forum Posts

 View Only

Sign Up

Data Action to create External Contact

  • 1.  Data Action to create External Contact

    Posted 06-05-2025 18:41

    Philip_Hagenfeldt | 2020-03-05 11:45:33 UTC | #1

    Hi,

    I'm trying to create a data action to create an external contact. I'm succeeding in creating a contact with the values that aren't in an object (firstName, lastName etc.) but as soon as I'm trying to add the ExternalOrginazation object with id I get below error:

    1. Validate request body contains simple json (key-value pairs): The request could not be understood by the server due to malformed syntax.

    • The value provided in the request body is in the wrong format. Only key-value JSON pairs are supported. Example: {"FirstName" : "Joe", "LastName" : "Williams"}

    I'm sure this is quite easy to fix, but I am in no means a developer and Google/this forum haven't been able to help me come to a solution.


    tim.smith | 2020-03-05 14:07:45 UTC | #2

    Can you provide the request configuration for your data action? It's likely malformed somehow.


    Philip_Hagenfeldt | 2020-03-05 14:23:40 UTC | #3

    Not sure exactly what you need so I'm sending you the entire configuration. When googling around it seems it can't take a nested object as input, but maybe there's a work around? I guess it has to to with the request body template, but I'm way too novice to understand what to do.

    INPUT CONTRACT:

    "title": "Create Contact", "description": "The root schema comprises the entire JSON document.", "type": "object", "$schema": "http://json-schema.org/draft-04/schema", "properties": { "firstName": { "type": "string" }, "middleName": { "type": "string" }, "lastName": { "type": "string" }, "workEmail": { "type": "string" }, "personalEmail": { "type": "string" }, "externalOrganization": { "default": {}, "type": "object", "properties": { "name": { "type": "string" }, "id": { "type": "string" } }, "additionalProperties": true } }, "additionalProperties": true }

    OUTPUT CONTRACT

    { "type": "object", "properties": { "id": { "type": "string" } }, "additionalProperties": true }

    REQUEST

    { "requestUrlTemplate": "/api/v2/externalcontacts/contacts", "requestType": "POST", "headers": { "Content-Type": "application/json" }, "requestTemplate": "{\\\"firstName\\\": \\\"${input.firstName}\\\",\\\"lastName\\\": \\\"${input.lastName}\\\"}\"," }

    RESPONSE { "translationMap": {}, "translationMapDefaults": {}, "successTemplate": "${rawResult}" }


    Jason_Mathison | 2020-03-05 14:27:26 UTC | #4

    The issue is that Data Actions have to have "flat" input schemas. They only accept key value pairs, not arrays or objects.

    In order to support an API that requires a "complex" input you need to setup the object in the requestTemplate. Basically the template will have the "Object shape", and then the blanks are filled in from the input values.

    --Jason


    Philip_Hagenfeldt | 2020-03-05 14:39:01 UTC | #5

    Jason_Mathison, post:4, topic:7271
    ue is that Data Actions have to have "flat" input schemas. They only accept key value pairs, not arrays or objects.

    In order to support an API that requires a "complex" input you need to setup the object in the requestTemplate. Basically the template will have the "Object shape", and then the blanks are filled in from the input values.

    Alright! And how would this template look like? Is it complex to set up? As mentioned, I'm not well versed in developing and I usually go with the trial and error methodology


    Jason_Mathison | 2020-03-05 14:50:14 UTC | #6

    The request template you posted above is the right idea, but instead of this

    "{\"firstName\": \"${input.FIRSTNAME}\",\"lastName\": \"${input.LASTNAME}\"}",

    you would include the object the API is expecting. This is much easier to do in the "simple UI" option where it will take care of escaping characters for you. In the simple UI it would look something like:

    {"firstName" : "${input.FIRSTNAME}", "lastName": "${input.LASTNAME}", "externalOrganization" : {"name" : "${input.exernalOrgName}", "id" : "${input.exernalOrgId}"}}

    Also, the forum likes to remove characters from cut and pastes of data actions, attaching the export .json to the thread is much more reliable.


    Philip_Hagenfeldt | 2020-03-05 15:00:59 UTC | #7

    Hmm.. Getting the same error message. I exported the .json but the forum won't allow me to upload it since I'm a new user.. Uploaded it to WeTransfer at https://we.tl/t-VXxzCHxb9w, maybe you could have a look? Also pasting the raw text below:

    { "name": "Create Contact TEST - Exported 2020-03-05 @ 15:57", "integrationType": "purecloud-data-actions", "actionType": "custom", "config": { "request": { "requestUrlTemplate": "/api/v2/externalcontacts/contacts", "requestType": "POST", "headers": { "Content-Type": "application/json" }, "requestTemplate": "{\"firstName\" : \"${input.firstName}\", \"lastName\": \"${input.lastName}\", \"externalOrganization\" : { \"id\" : \"${input.externalOrganization.id}\"}}" }, "response": { "translationMap": {}, "translationMapDefaults": {}, "successTemplate": "${rawResult}" } }, "contract": { "input": { "inputSchema": { "$schema": "http://json-schema.org/draft-04/schema", "title": "Create Contact", "description": "The root schema comprises the entire JSON document.", "type": "object", "properties": { "firstName": { "type": "string" }, "middleName": { "type": "string" }, "lastName": { "type": "string" }, "workEmail": { "type": "string" }, "personalEmail": { "type": "string" }, "externalOrganization": { "default": {}, "type": "object", "properties": { "id": { "type": "string" } }, "additionalProperties": true } }, "additionalProperties": true } }, "output": { "successSchema": { "type": "object", "properties": { "id": { "type": "string" } }, "additionalProperties": true } } }, "secure": false }


    Jason_Mathison | 2020-03-05 15:07:43 UTC | #8

    The externalOrganization in your input contract is an object, which is not supported. You will need to make the externalorg id a top level string input.


    Philip_Hagenfeldt | 2020-03-05 15:51:38 UTC | #10

    Fantastic, that worked! (Found a minor error in my request template also)


    Jason_Mathison | 2020-03-05 16:06:21 UTC | #11

    I personally added

    A common reason for this error is needing to prepend the variable with 'input.' or 'credentials.'

    because I made that mistake multiple times :) Glad to hear that you got this sorted out!


    system | 2020-04-05 16:06:24 UTC | #12

    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: 7271