Genesys Cloud CX

 View Only
Discussion Thread View
  • 1.  Data Action Translation Map

    Posted 5 days ago
    Edited by Hanife Nur Özçetin 5 days ago
    Hello,
    I am working on my integration action information. I am trying to create a custom action by taking id as input and from that I am going to get user info such as avatar and first/last name of the user.
    INPUT CONTRACT
    {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "User Info Request",
    "description": "Fields needed in the body of the POST to create a calendar reminder.",
    "type": "object",
    "required": [
    "id"
    ],
    "properties": {
    "id": {
    "type": "number"
    }
    },
    "additionalProperties": true
    }

    OUTPUT CONTRACT
    {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "data",
    "description": "",
    "type": "object",
    "properties": {
    "avatar": {
    "type": "string"
    },
    "first_name": {
    "type": "string"
    },
    "last_name": {
    "type": "string"
    }
    },
    "additionalProperties": true
    }


    RESPONSE
    {
    "translationMap": {
    "first_name": "$first_name",
    "last_name": "$last_name",
    "avatar": "$avatar"
    },
    "translationMapDefaults": {},
    "successTemplate": "${rawResult}"
    }


    When I try to test I got an error which is :
    Resolve translation map: Failed while processing the translation map. Could not resolve value for the key: 'first_name' and no default value was configured. Additional details: Illegal character at position 1 expected '.' or '['

    What I do wrong? I am new at coding. Any help would be appreciated.
    Sincerely, 

      #Integrations

      ------------------------------
      Hanife Nur Özçetin
      Customer Experience Yazilim Danismalik Ticaret LTD
      ------------------------------


    • 2.  RE: Data Action Translation Map

      GENESYS
      Posted 5 days ago
      Hello Hanife,

      One of our peers here might respond to your question in a bit, but as an alternative I wanted to point you to our Developer Forum where devs and programmers like you are more active. There might already be a thread similar to your question there. It is also highly likely that posting this question there would get you a faster, if not better, answer.

      ------------------------------
      Nico Feliciano
      Genesys - Employees
      ------------------------------



    • 3.  RE: Data Action Translation Map

      Posted 4 days ago
      Hi Hanife -
      I agree with Jan - the Developer Forum is where I got up to speed on building out data actions and response mapping. But sometimes asking the right question to get the right result is pretty tedious. I'll take a shot at giving you a hand.
      I'm still fairly new to how all of this works, but I think you might be missing a "." to help the data action search within the message for the tag you're looking for.
      So: "first_name": "$first_name",
      Should be: "first_name": "$.first_name",

      Maybe try:
      {
      "translationMap": {
      "first_nameValue": "$.first_name",
      "last_nameValue": "$.last_name",
      "avatarValue": "$.avatar"
      },
      "translationMapDefaults": {},
       "successTemplate": "{\"first_name\": ${first_nameValue}, \"last_name\": ${last_nameValue}, \"avatar\": ${avatarValue}}"
      }

      Thanks,


      ------------------------------
      Cory King
      IT Lead
      Interstate Gas Supply, Inc.
      ------------------------------



    • 4.  RE: Data Action Translation Map

      Posted 3 days ago
      Edited by Muhammad Zubair Awan 3 days ago
      Hi Hanife,

      The JSON path for translation map values $first_name, $last_name, and $avatar look incorrect - that is why you are getting the error Illegal character at position 1 expected '.' or '[' - also you haven't defined the success template. You need to define the correct JSON path for the translation map values which you will need to find from the (Response) body of the API you are calling. You have only shared the contracts and not the config so can't tell you the exact path without knowing the API you are using but as an example if you need to read id and name from below JSON

      {
      "id": "1111-2222-3333-4444",
      "name": "Jack Sparrow"
      }

      then your translation map should be as below - where userId and userName are your output contracts

      {
      "translationMap": {
      "userId": "$.id",
      "userName": "$.name"
      },
      "translationMapDefaults": {},
      "successTemplate": "{\"userId\": ${userId},\"userName\": ${userName}}"
      }

      Hope this helps.

      Cheers

      ------------------------------
      Muhammad Zubair Awan
      Spark NZ Trading
      ------------------------------



    • 5.  RE: Data Action Translation Map

      Posted 3 days ago
      Hi,
      My configuration ;
      {
      "requestUrlTemplate": "https://reqres.in/api/users?page=2",
      "requestType": "GET",
      "headers": {},
      "requestTemplate": "${input.rawRequest}"
      }

      I tried both of the suggestions but the error is the same.
      9. Resolve translation map: Failed while processing the translation map. Could not resolve value for the key: 'userId' and no default value was configured. Additional details: No results for path: $['id'].


      ------------------------------
      Hanife Nur Özçetin
      Customer Experience Yazilim Danismalik Ticaret LTD
      ------------------------------



    • 6.  RE: Data Action Translation Map

      Posted 2 days ago
      Hi,

      The example in my previous comment was just to show you how to define the JSON path for the values you are trying to read. You were supposed to replace $.id with the fields you are trying to read in your source data - error "No results for path: $['id']" means in your source data, system could not find id under $. path.

      Now that I have the API/data you are trying to access, I see that your user data is an array. so for example if you need to read the first_name from element 0 of the data array which is something like

      {"data":[{"id":7,"email":"XXXXXX@example.com","first_name":"Michael","last_name":"XXXXXX","avatar":"https://XXXXX/7-image.jpg"}

      your translation map will be as below, where first_name is defined as output contract with type string.

      {
      "translationMap": {
      "first_name":"$.data[0].first_name"
      },
      "translationMapDefaults": {},
      "successTemplate": "{\"first_name\": ${first_name}}"
      }

      it will return "Michael". Similarly you can retrieve other values as you need.

      So above should resolve the errors. However, I see that you are taking id (number) as input and trying to retrieve the user details matching that id from the array. I do not think you can do so within the Data Action itself with this GET api. I suggest reading complete data array and extract the data based on the id using the architect flow.

      To read the first_name array, change the output contract to

      {
      "type": "object",
      "properties": {
      "data": {
      "type": "array",
      "items": {
      "type": "object",
      "properties": {
      "first_name": {
      "type": "string"
      }
      },
      "additionalProperties": true
      }
      }
      },
      "additionalProperties": true
      }

      and leave the translation map to default config

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

      similarly you can read other values like last_name, avatar, id etc.

      Cheers

      ------------------------------
      Muhammad Zubair Awan
      Spark NZ Trading
      ------------------------------



    • 7.  RE: Data Action Translation Map

      Posted 2 days ago
      Hi,
      Thank you for the reply. I see your point. I changed my request url to this --> https://reqres.in/api/users/${input.id}
      Right now While response like below
      {
      "translationMap": {},
      "translationMapDefaults": {},
      "successTemplate": "${rawResult}"
      }
      It receives the correct information about the input id I get without output contracts.
      The problem is now when I arranged output contracts like this;
      {
      "title": "data",
      "type": "object",
      "properties": {
      "first_name": {
      "type": "string"
      },
      "last_name": {
      "type": "string"
      }
      },
      "additionalProperties": true
      }


      It receives correct json but doesn't fill the output template. I tried to add arrays and first_name : $.first_name kind of solutions however it respond an error or remained the same. Do u have any suggestions?
      Thank you in advance.

      ------------------------------
      Hanife Nur Özçetin
      Customer Experience Yazilim Danismalik Ticaret LTD
      ------------------------------



    • 8.  RE: Data Action Translation Map

      Posted 2 days ago
      Hi,

      Leaving the translation map as default, following output contract should work mapping the values

      {
      "title": "Output",
      "type": "object",
      "properties": {
      "data": {
      "type": "object",
      "properties": {
      "first_name": {
      "type": "string"
      },
      "last_name": {
      "type": "string"
      },
      "avatar": {
      "type": "string"
      }
      },
      "additionalProperties": true
      }
      },
      "additionalProperties": true
      }

      Cheers

      ------------------------------
      Muhammad Zubair Awan
      Spark NZ Trading
      ------------------------------



    • 9.  RE: Data Action Translation Map

      Posted yesterday
      Thank you so much. It solved my problem.
      Regards

      ------------------------------
      Hanife Nur Özçetin
      Customer Experience Yazilim Danismalik Ticaret LTD
      ------------------------------