JSON Array Handling

Connectors may return their payload as an array of items. In the example below, we showcase configuring the connector action and utilizing the returned array data to update a user's properties, such as their phone number.

This flow takes the user's email and then queries an API to verify if the email exists as a user in a 3rd party system through the HTTP Connector, and if so, update their user information to include their phone number.

Configure Connector Action

The first step is to configure your connector action. You will later need to use the Context Key of the connector's data; in this example, the data is stored under connectors.httpResult.

HTTP Connector Configuration Retrieving Custom Data

Get Data from Array

Next, we can access the data from the returned array from other Descope actions or conditionals, before we try to access it though, here is an example of it's contents.

{
  "connectors": {
    "httpResult": {
      "body": {
        "data": [
          {
            "user@email.com": {
              "email": "user@email.com",
              "email_verified": true,
              "name": {
                "first": "John",
                "last": "Doe"
              },
              "phone": {
                "number": "+12223334455",
                "verified": true
              }
            }
          }
        ]
      }
	}
  }
}

Now we will access the array; in this example, we will use the Update User/ Properties action to get data from the array and update the user's phone number and verification status.

Based on the above returned data under the connectors.httpResult context key, we will need to parse out the phone details per the below paths using jquery.

  • jq:.connectors.httpResult.body.data[0][].phone.verified
  • jq:.connectors.httpResult.body.data[0][].phone.number

!Update User Based on HTTP Connector JSON Array Data](/assets/update-user-json-array.webp)

Connecting the Flow

Once you have configured the connector action and the condition or other action to parse the data via jquery, you can now connect the flow. Here is the flow in this example once completed.

Example Flow Overview Showing User Property Update From Returned JSON Array Data

Post Flow Execution

Below you can see the user's details are updated after the flow execution.

User Properties Without Phone Number Prior To Update From Returned JSON Array Data

User Properties Without Phone Number After Update From Returned JSON Array Data

Was this helpful?

On this page