Extract Variable w/ multi-variable JSON Payload

I have a proxy which will POST up to 100 productId's and get a return on each productId. How can I extract each productId as a separate variable to be sent to the backend. Below is the request payload for 1 product:

Request Payload 1 Id:

{
  "customerId": "55555",
  "regionCode": "EAST",
  "contractId": "",
  "locationId": "1",
  "Products": [
    {
      "Id": "09",
      "quantity": "10"
    },
]

Response Payload/Output from 1 Id:

[
    {
        "id": "09",
        "listPrice": "154.95",
        "netPrice": "120.551"
    }
]

Request Payload 4 Id's:

{
  "customerId": "55555",
  "regionCode": "EAST",
  "contractId": "",
  "locationId": "1",
  "Products": [
    {
      "Id": "09",
      "quantity": "10"
    },
    {
      "Id": "08",
      "quantity": "11"
    },    {
      "Id": "07",
      "quantity": "12"
    },    {
      "Id": "06",
      "quantity": "13"
    },
]

Desired Output:

[
    {
        "id": "09",
        "listPrice": "154.95",
        "netPrice": "120.551"
    }
   {
        "id": "08",
        "listPrice": "2.95",
        "netPrice": "3.551"
    }
   {
        "id": "07",
        "listPrice": "4.95",
        "netPrice": "5.551"
    }
   {
        "id": "06",
        "listPrice": "6.95",
        "netPrice": "7.551"
    }
]

This pattern can go up to 100 Id's. Each Id has the exact same name and may or may not have the same quantity.

Presently, the proxy can only evaluate 1 Id given and simply ignores the rest. How can I extract all Id's and have it return them same as the first?

0 2 262
2 REPLIES 2

Not clear what you're doing at all.

What is the input to the API Proxy?

And for that input, What is the desired ... output? And is this output something you want to send to the upstream (target)? or is it something you want to send back to the original client?

You are showing listPrice and netPrice, where does that come from?

You use the phrase "Response Payload/Output".. response from what?

I don't understand what data is going in and what you are trying to get out.

JavaScript policy below solved my issue:

var requestObj = request.content.asJSON;


request.content = '';


request.headers['Content-Type'] = 'application/json';


var body = request.content.asJSON;


    body.customerId = requestObj.customerId;
    body.branchId = requestObj.regionCode;
    body.contractId = requestObj.contractId;
    body.shipWhseId = requestObj.locationId;
    body.products = [];


    var data = requestObj.Products;
    for(var i in data)
    {
        var newProduct = {
            "productId": data[i]["Id"],
            "quantity" : data[i]["quantity"],
        };
        
        body.products.push(newProduct);
    }