Processor Request API

Use this processor when the Script must interact with an external API, letting you send the request, parse the response, and map the returned data onto Profile attributes.

Configure the API request processor

In this example the processor performs a GET request to https://api.restful-api.dev/objectsarrow-up-right and saves the payload in API_RESPONSE

The result is stored in the profile variable API_RESPONSE

Configuration meanings:

Field name
Required?
Detail

Variable name for storing result

Yes

This processor returns the API response, so pick a variable to capture it.

For example API_RESPONSE

Method

Yes

Select the method: GET, POST, PUT, or DELETE

URL

Yes

Endpoint of API

Header

API request headers

Query

No

API query parameters

Extract response

Use this area to parse, calculate, or extract specific fields from the API response, the operations work just like JavaScript

Extract response

In this example, the API response from https://api.restful-api.dev/objectsarrow-up-right looks like this:

API response

To fetch the name of the item whose id is 2, write JavaScript that extracts that field from the response:

Extract the response with JavaScript code

When you write JavaScript in the Extract Response section, first run the scenario once, open the queue to inspect the API response, then click Analyze variable.

Analyze the API response

A popup like this appears afterwards:

Review the API response details

Next, tweak the JavaScript to confirm the result meets your needs:

Grab the item whose id equals 2

Use this code to fetch the item whose id is 2:

Next, adjust the JavaScript like this to capture the name of the item with id is 2:

Retrieve the name of the item whose id is 2

Finally, once you have the result you want, copy that code and paste it into the processor’s main configuration:

Copy code
The finished JavaScript snippet

The returned value now matches your intent: the name of the item with id is 2 :

The output now gives you the name of the item with id is 2

Last updated