Referencing an Array in an HTTP Request Action

Hi all,

I have a use case to call an API to record the entitlements that have been removed on a particular source. The Provisioning Completed trigger returns the following structure:

{
    "trackingNumber":"4b4d982dddff4267ab12f0f1e72b5a6d",
    . . .
    "accountRequests":[
        {
            "source":{
                "id":"4e4d982dddff4267ab12f0f1e72b5a6d",
                "name":"Corporate Active Directory",
                "type":"SOURCE"
            },
            . . .
            "accountId": "harold.smith",
            "attributeRequests":[
                {
                    "operation":"Remove",
                    "attributeName":"memberOf",
                    "attributeValue":"CN=admin,DC=training,DC=com"
                }
             . . .
            ]
        }
    ]

In the HTTP Request action, I would like to pass the full set of attribute requests to document what has changed on the account. In my request body, I have set a value of {{$.trigger.accountRequests[0].attributeRequests}} which returns an empty string.

In contrast {{$.trigger.accountRequests[0].accountId}} returns “harold.smith”, indicating that the variable substitution is working for strings but not arrays (or JSON objects). The Define Variable action has a similar limitation so I cannot use it to pre-define the array variable to pass in my API request body. Loop wouldn’t work for me either, as I would have to send an API response for each attributeRequest rather than including them all in one.

Has anyone encountered this use case before, and if so, were there any workarounds?
Thank you

Hi,

If you want to send the array of objects you can use $.trigger.accountRequests[0].attributeRequests.* It will send the entire array.

If you need to pass only attributeValue of all objects you can use:
$.trigger.accountRequests[0].attributeRequests.*.attributeValue.

-Abhinov

Hi Abhinov,

I appreciate the suggestion, and while that does seem to work in a JSONPath evaluator it still renders as an empty string in the Workflow engine on the HTTP request body. Here are the relevant lines of the Workflow Result for reference:

Print out of the HTTP step config in the workflow result:

Actual body of the HTTP request as shown in the workflow result and confirmed on end system:
image

Hello @chris-hogan

Good day!

$.trigger.accountRequests[*].attributeRequests[*]

Hi @vijayasaikoppineni , thank you for the suggestion. This does bring me one step closer as it properly fetches the array. Unfortunately, the resultant array seems to get interpreted as part of the request body JSON

In this example, the first quotation mark before attributeName terminates the JSON value and thus the HTTP Request sees it as:`“additional_comments”: “[map[” with a trailing “a” after the value has already closed.

@chris-hogan
In your HTTP Request action, you can build the JSON request body by iterating over the attributeRequests array using Velocity’s #foreach directive.

{
  "trackingNumber": "*********************",
  "accountId": "$!{trigger.accountRequests[0].accountId}",
  "attributeRequests": [
    #foreach( $attrRequest in $trigger.accountRequests[0].attributeRequests )
    {
      "operation": "$!{attrRequest.operation}",
      "attributeName": "$!{attrRequest.attributeName}",
      "attributeValue": "$!{attrRequest.attributeValue}"
    }#if( $foreach.hasNext ),#end
    #end
  ]
}

Let me know if it helps.

Hi Amit,

Thank you for the suggestion. I am not certain whether VTL can be used in the request body as the documentation doesn’t reference it. I have tried the following simple VTL statements to test whether it will execute:

#if($.trigger.action==\"IdentityRefresh\")Correct#{else}Incorrect#end
{{#if($.trigger.action==\"IdentityRefresh\")Correct#{else}Incorrect#end}}
#if({{$.trigger.action}}==\"IdentityRefresh\")Correct#{else}Incorrect#end
image

All result in the VTL expression rendering as plain text in the API call. Do you happen to have an example of working VTL usage in the HTTP Request Body?

Hey Chris,

I am just checking if you could do the following.

Instead of Enter Value, go with Choose Variable and add $.trigger.accountRequests[0].attributeRequests as request body.

It will parse the array as a JSON instead of reading it as a String.

When passing as value (Enter Value):
{68DA9542-6A03-468A-975B-AA6E35378438}

1 Like

Hi Zeel,

This is a great suggestion. This did work to properly escape the array in the JSON request body. Unfortunately, our request body still needs other mandatory key value pairs unrelated to the array, so Choose Variable will not suffice.

I am beginning to think it is simply not feasible in workflows, but I appreciate all the help I have received.

That’s what I thought. This is not a great option when you want to add other key-value pairs under request body.

I’ll try to figure out a way and if I find anything I’ll keep you updated.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.