Legacy Dev Forum Posts

 View Only

Sign Up

Drawing a blank on what the output contracts should be

  • 1.  Drawing a blank on what the output contracts should be

    Posted 06-05-2025 18:43

    VaunMcCarthy | 2022-01-24 23:22:50 UTC | #1

    Hi guys

    Can someone please help with how the output contracts should look here:

    Raw JSON response from API is:

    { "total": 1, "results.archived": [ false ], "results.updatedAt": [ "2022-01-24T20:11:36.886Z" ], "results.id": [ "601" ], "results.properties.createdate": [ "2022-01-24T20:11:16.630Z" ], "results.properties.lastname": [ "McCarthy" ], "results.properties.lastmodifieddate": [ "2022-01-24T20:11:36.886Z" ], "results.properties.firstname": [ "Vaun" ], "results.createdAt": [ "2022-01-24T20:11:16.630Z" ], "results.properties.hsobjectid": [ "601" ], "results.properties.email": [ "xxxxxxxx@xxxxxxx.com" ]}

    I need to get just that results.properties.lastname object value out. I don't know what I keep doing wrong because I've done this before but can't for the life of me get the array/object/string layout correct so that it also properly flattens.


    Jerome.Saint-Marc | 2022-01-25 08:43:08 UTC | #2

    Hello,

    You can use any of the following two approaches.

    With an Output Contract to define an output string parameter (lastname):

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

    First approach accessing the first element of the array via the JSONPath expression:

    { "translationMap": { "tmpLastname": "$['results.properties.lastname'][0]" }, "translationMapDefaults": { "tmpLastname": "\"\"" }, "successTemplate": "{\"lastname\":${tmpLastname}}" }

    Second approach using the successTemplateUtils.firstFromArray macro:

    { "translationMap": { "tmpLastnameArray": "$['results.properties.lastname']" }, "translationMapDefaults": { "tmpLastnameArray": "[\"\"]" }, "successTemplate": "{\"lastname\":${successTemplateUtils.firstFromArray(\"${tmpLastnameArray}\",\"$esc.quote$esc.quote\")}}" }

    Regards,


    VaunMcCarthy | 2022-01-25 20:02:46 UTC | #3

    Jerome.Saint-Marc, post:2, topic:13315
    {
        "translationMap": {
          "tmpLastname": "$['results.properties.lastname'][0]"
        },
        "translationMapDefaults": {
          "tmpLastname": "\"\""
        },
        "successTemplate": "{\"lastname\":${tmpLastname}}"
    }

    HI Jerome

    Getting a blank result from this using either your first or second approach.


    Jerome.Saint-Marc | 2022-01-26 11:02:33 UTC | #4

    Hello,

    I just tried both approaches with a web service returning exactly what you have posted (the raw JSON response) and it is working fine for me. I get lastname = "McCarthy"

    Is what you have posted really the raw JSON response (HTTP Response body)? Or has it been flattened?

    Regards,


    VaunMcCarthy | 2022-01-26 18:49:25 UTC | #5

    Sorry Jerome, yes I've just seen that's not the raw response. Here is the correct paste:

    { "total": 1, "results": [ { "id": "601", "properties": { "createdate": "2022-01-24T20:11:16.630Z", "email": "xxxx@xxxxx.com", "firstname": "Vaun", "hsobjectid": "601", "lastmodifieddate": "2022-01-24T20:11:36.886Z", "lastname": "McCarthy" }, "createdAt": "2022-01-24T20:11:16.630Z", "updatedAt": "2022-01-24T20:11:36.886Z", "archived": false } ] }


    Jerome.Saint-Marc | 2022-01-27 07:44:24 UTC | #6

    So that would need the following Response Configuration (empty string returned if the results array is empty, otherwise takes the first element from array).

    { "translationMap": { "tmpLastname": "$.results[0].properties.lastname" }, "translationMapDefaults": { "tmpLastname": "\"\"" }, "successTemplate": "{\"lastname\":${tmpLastname}}" }

    Regards,


    VaunMcCarthy | 2022-01-27 08:08:38 UTC | #8

    Thanks Jerome, that's got me on the right track now.


    system | 2022-02-27 08:09:34 UTC | #9

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