0

This may be a quick one for experienced developers. I am looking to parse the JSON response below via Postman for specific values of named properties. Here is an example response:

[
  {
    "SubscriptionQty": "1.0",
    "ProductName": "Product A",
    "ProductId": "12345",
    "AccountName": "Customer A",
    "AccountId": "66723",
    "ProductID": "7JQ-00341",
    "Message": "successful"
  },
  {
    "SubscriptionQty": "10.0",
    "ProductName": "Product A",
    "ProductId": "12345",
    "AccountName": "Customer B",
    "AccountId": "66746",
    "ProductID": "7JQ-00341",
    "Message": "successful"
  }
]

What would be the best approach to parse the response as it will change over time?

Would it be possible via Postman to take the values for (SubscriptionQty, ProductId, and AccountId) for each Account, set them as env variables (Ex: customer_1_SubscriptionQty, customer_1_ProductId, customer_1_AccountId, next level down (customer_2_SubscriptionQty, customer_2_ProductId, customer_2_AccountId, etc) and then use those variables in another API call to post the data I require for each customer?

In the end, I am looking for a sound method to take the data for each property found, set it as defined variables for that customer and then take those values to utilize them in a second API call to post data for another piece of software. If I need to break this down further I am happy to. Just looking for the best possible method to approach this and Postman seemed to be appropriate with the options for env. variables and collection runner. Appreciate any and all assistance!

NebulaFox
  • 7,813
  • 9
  • 47
  • 65
Sling4778
  • 21
  • 4
  • You wouldn't want to do for each customer because I assume you don't know how many records that will be. What I would suggest you do is create a variable for each key, store the content then make your other call using those values and continue looping through the array in that manner. Also assuming all calls will be the same except for the values it should be easy enough to do it in a collection and with collection runner. – so cal cheesehead Mar 09 '20 at 19:40
  • Thanks for the feedback and confirmation! Was able to get this going by leveraging the following documentation - https://thisendout.com/2017/02/22/loops-dynamic-variables-postman-pt2/ – Sling4778 Mar 09 '20 at 20:26
  • 3
    Does this answer your question? [Postman: Can i save JSON objects to environment variable so as to chain it for another request?](https://stackoverflow.com/questions/41479494/postman-can-i-save-json-objects-to-environment-variable-so-as-to-chain-it-for-a) – Henke Feb 20 '21 at 05:34

0 Answers0