Genesys Cloud - Main

 View Only

Sign Up

  Thread closed by the administrator, not accepting new replies.
  • 1.  Need to include null value in the response when the API doesn't give any values.

    Posted 02-20-2025 08:30
    No replies, thread closed.

    Hi All,

    I have an API which gives the below raw response,

    {
      "total": 5,
      "data": [
        {
          "worker": {
            "descriptor": "Dummy name",
            "id": "9e4bae7b012b01d0c97f1ab726089393"
          },
          "unit": {
            "descriptor": "Hours",
            "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb"
          },
          "absencePlan": {
            "timeoffs": "(Discretionary Day)",
            "descriptor": "Discretionary Day",
            "id": "9f87f860702d108b8efd3c6723349928"
          },
          "category": {
            "descriptor": "Time Off Plan",
            "id": "8cdc5bb54494100018789cabb3df006d"
          },
          "effectiveDate": "2025-02-21"
        },
        {
          "worker": {
            "descriptor": "Dummy name",
            "id": "9e4bae7b012b01d0c97f1ab726089393"
          },
          "unit": {
            "descriptor": "Hours",
            "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb"
          },
          "absencePlan": {
            "timeoffs": "(Diversity Celebration Day)",
            "descriptor": "Diversity Celebration Day",
            "id": "7219002ea3ed010e3ed3025bfc01eec7"
          },
          "category": {
            "descriptor": "Time Off Plan",
            "id": "8cdc5bb54494100018789cabb3df006d"
          },
          "effectiveDate": "2025-02-21",
          "quantity": "8"
        },
        {
          "worker": {
            "descriptor": "Dummy name",
            "id": "9e4bae7b012b01d0c97f1ab726089393"
          },
          "unit": {
            "descriptor": "Hours",
            "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb"
          },
          "absencePlan": {
            "timeoffs": "(Unpaid Leave - PTO, Protected/Sick Time, PTO)",
            "descriptor": "PTO",
            "id": "9f87f860702d108b8efd482c5a04992e"
          },
          "category": {
            "descriptor": "Time Off Plan",
            "id": "8cdc5bb54494100018789cabb3df006d"
          },
          "effectiveDate": "2025-02-21",
          "quantity": "184"
        },
        {
          "worker": {
            "descriptor": "Dummy name",
            "id": "9e4bae7b012b01d0c97f1ab726089393"
          },
          "unit": {
            "descriptor": "Hours",
            "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb"
          },
          "absencePlan": {
            "descriptor": "Vaccine/Wellness Time",
            "id": "d560d355351d01aab570df4f8754ae73",
            "timeoffs": "(Vaccine/Wellness Time)"
          },
          "category": {
            "descriptor": "Time Off Plan",
            "id": "8cdc5bb54494100018789cabb3df006d"
          },
          "effectiveDate": "2025-02-21",
          "quantity": "4"
        },
        {
          "worker": {
            "descriptor": "Dummy name",
            "id": "9e4bae7b012b01d0c97f1ab726089393"
          },
          "unit": {
            "descriptor": "Hours",
            "id": "c4dacbd56bca4a9a8950e8d3ed21bbdb"
          },
          "absencePlan": {
            "timeoffs": "(Volunteer Time)",
            "descriptor": "Volunteer Time",
            "id": "9f87f860702d108b8efd557de9ac9938"
          },
          "category": {
            "descriptor": "Time Off Plan",
            "id": "8cdc5bb54494100018789cabb3df006d"
          },
          "effectiveDate": "2025-02-21",
          "quantity": "40"
        }
      ]
    }

    if you take a close look for the first item we don't have anything called quantity, if we are not getting any fields like this I want to take it as 0/null using translation mapping.

    Current translation mapping which I have is below:

    {
      "translationMap": {
        "timeOffType": "$.data[*].absencePlan.id",
        "balance": "$.data[*].quantity"
      },
      "translationMapDefaults": {
        "timeOffType": "UNKNOWN",
        "balance": "UNKNOWN"
      },
      "successTemplate": "{ \"timeOffType\": ${timeOffType}, \"balance\": ${balance} }"
    }
    Current Response:
    {
      "timeOffType": [
        "9f87f860702d108b8efd3c6723349928",
        "7219002ea3ed010e3ed3025bfc01eec7",
        "9f87f860702d108b8efd482c5a04992e",
        "d560d355351d01aab570df4f8754ae73",
        "9f87f860702d108b8efd557de9ac9938"
      ],
      "balance": [
        "8",
        "184",
        "4",
        "40"
      ]
    }
    Expected Response:
    {
      "timeOffType": [
        "9f87f860702d108b8efd3c6723349928",
        "7219002ea3ed010e3ed3025bfc01eec7",
        "9f87f860702d108b8efd482c5a04992e",
        "d560d355351d01aab570df4f8754ae73",
        "9f87f860702d108b8efd557de9ac9938"
      ],
      "balance": [
        "NA"/"0"/null
        "8",
        "184",
        "4",
        "40"
      ]
    }


    Kindly look into this and let me know your thoughts on this.

    #API/Integrations

    ------------------------------
    Jarvish Kisanth Singh
    ------------------------------


  • 2.  RE: Need to include null value in the response when the API doesn't give any values.
    Best Answer

    Posted 02-20-2025 11:03
    Edited by Cameron Tomlin 02-21-2025 08:34
    No replies, thread closed.

    Hi Jarvish,

    It doesn't look like a "quantity" is returned if there is no timeoff balance.  This might be a good question to ask in the Developer Forum as they will be better placed to answer what is expected in the API Responses



    ------------------------------
    Sam Jillard
    Online Community Manager/Moderator
    Genesys - Employees
    ------------------------------



  • 3.  RE: Need to include null value in the response when the API doesn't give any values.

    Posted 02-20-2025 11:41
    No replies, thread closed.

    Hi Samuel,

    Thanks for the update,

    I have asked the question already, but I haven't got the response yet!



    ------------------------------
    Jarvish Kisanth Singh
    ------------------------------



  • 4.  RE: Need to include null value in the response when the API doesn't give any values.

    Posted 02-21-2025 15:43
    No replies, thread closed.

    Something I have used when an element in the returned array may or may not have a value is something like:

    \"Address1\":$Address1.replace(\"null\", \" $esc.quote$esc.quote\")
    That replaces a null value with "" since you can't have a null in the result set


    ------------------------------
    George Ganahl GCP, GCSME, ICCE, ICHD, etc.
    Technical Adoption Champion
    Genesys
    ------------------------------



  • 5.  RE: Need to include null value in the response when the API doesn't give any values.

    Posted 02-24-2025 13:52
    No replies, thread closed.

    Hi George,

    Thanks for the reply, but it didn't work,

    Error:
    Apply output transformation: Transform failed to process result using 'successTemplate' template due to error:'Unexpected character ('[' (code 91)): was expecting comma to separate Object entries at [Source: (String)"{ "timeOffType": [ "9f87f860702d108b8efd3c6723349928", "7219002ea3ed010e3ed3025bfc01eec7", "9f87f860702d108b8efd482c5a04992e", "d560d355351d01aab570df4f8754ae73", "9f87f860702d108b8efd557de9ac9938" ], "balance": ""[ "" """ ""8 """ "", "" """ ""1 ""8 ""4 """ "", "" """ ""4 """ "", "" """ ""4 ""0 """ "" ""] ""}"; line: 1, column: 216]' Template:'{ "timeOffType": ${timeOffType}, "balance": $balance.replace("", " $esc.quote$esc.quote")}'.

    Translation Mapping:

    \"balance\": $balance.replace(\"\", \" $esc.quote$esc.quote\")


    ------------------------------
    Jarvish Kisanth Singh
    ------------------------------



  • 6.  RE: Need to include null value in the response when the API doesn't give any values.

    Posted 02-27-2025 23:14
    No replies, thread closed.

    Hi Jarvish,

    See Jerome's post (March '22) on the similar question in the Developer Forum https://developer.genesys.cloud/forum/t/null-values-do-not-work-in-string-collection/13779/8. 



    ------------------------------
    Tatjana Knezevic

    www.startelecom.cloud

    https://www.linkedin.com/company/star-telecom-www-startelecom-ca-/
    ------------------------------