Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  How to create a Contract for a data action Output

    Posted 6 days ago
      |   view attached

    Hi all, I struggle a little to get the results back in a data action output from the API call.

    API used  Get /api/v2/users/{userId}?expand=authorization

    The returned data is:  "authorization": { "roles": [ { "id": "ecc22cf2-f769-420d-81b3-f89867558c2f", "name": "admin" }, { "id": "86d9a533-bce0-4da3-95f7-5d1f9673006b", "name": "employee" } ],

    In the contract I have this:

    {  "title": "output", "type": "object", "additionalProperties": true, "properties": { 
    "authorization": {"type": "object", "properties": {"roles": {"type": "array", "items": {"type": "object", "properties": {"id": {"type": "string"},  "name": {"type": "string"}
    }}}}}}}

     

    When I run the test, it comes back with no data (attached screenshot) where the API explorer does have the above listed output.
    Where do I go wrong here please?


    #DataActions
    #PlatformAPI

    ------------------------------
    Ruud Reinold
    BNP Paribas Personal Finance UK
    ------------------------------


  • 2.  RE: How to create a Contract for a data action Output

    Posted 3 days ago
    Edited by Christoph Domaschke 3 days ago

    Hi Rudy,
    your contract seems to be okay. Whould you share your translation map, please? Or did you flatten the output?



    ------------------------------
    Christoph Domaschke
    Produktmanager Kunden-Dialog-Center
    ------------------------------



  • 3.  RE: How to create a Contract for a data action Output

    Posted 3 days ago

    I don't have a translation map, that's what likely is the issue here.



    ------------------------------
    Ruud Reinold
    BNP Paribas Personal Finance UK
    ------------------------------



  • 4.  RE: How to create a Contract for a data action Output
    Best Answer

    Posted 3 days ago

    Hi Rudy, 

    You're not doing anything wrong with the API - the issue is that the output contract alone does not populate data in a Data Action.

    In Genesys Cloud, you must map the API response into the output using the Response configuration (translationMap + successTemplate). If you only define the contract, the test window will return empty data.

    What needs to be updated

    Update your Response configuration to include a translation map and success template, for example:

    {
      "translationMap": {
        "roleIds": "$.authorization.roles[*].id",
        "roleNames": "$.authorization.roles[*].name"
      },
      "translationMapDefaults": {
        "roleIds": "[]",
        "roleNames": "[]"
      },
      "successTemplate": "{ \"roleIds\": ${roleIds}, \"roleNames\": ${roleNames} }"
    }

    Then update your output contract to match:

    {
      "type": "object",
      "properties": {
        "roleIds": { "type": "array", "items": { "type": "string" } },
        "roleNames": { "type": "array", "items": { "type": "string" } }
      },
      "required": ["roleIds", "roleNames"]
    }

    The key point: the contract defines the structure, but the translationMap + successTemplate actually move the API data into that structure.



    ------------------------------
    Josh Coyle
    Senior Professional Services Consultant
    ------------------------------



  • 5.  RE: How to create a Contract for a data action Output

    Posted 3 days ago

    Hi Josh,

    That pinned the issue! Many thanks for your guidance on this.



    ------------------------------
    Ruud Reinold
    BNP Paribas Personal Finance UK
    ------------------------------