Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

This page shows an example of Variable Insertion in  using stream consisting of the HTTP Client function.

Refer to the example and follow the steps to understand Variable Insertion:

  1. Enter the JS code using the Script function. Example of a JS code snippet:

    await push({
        url: 'https://postman-echo.com',
        foo: 42,
        bar: 'kawaboom!',
        baz: payload.value % 2,
        someData: {
            alpha: 1337,
            beta: 'foobar'
        }
    })
  2. Configure an HTTP request response in the following format. You can substitute the values of variables defined in the JS code snippet using ${variable} or @{variable}.

    Note!

    While configuring HTTP body, you must add the JSON objects within quotes (" ") . Applicable only for JSON objects that return value in the string format.

     Example:
    {
    "comp": "dr",
    "dept": "pm",
    "score": 100,
    "name": "@{payload.name}",
    "age": "@{payload.age}"
    }

    You will receive the following httpResponse:

    httpResponse.json.agehttpResponse.json.comphttpResponse.json.depthttpResponse.json.namehttpResponse.json.score
    <age>drpm<name>100


    However, if you do not use " " with ${name} or ${age} or both, then you will see the httpResponse in the string format as shown below:

    httpResponse.json

    { "age": 18, "comp": "dr", "dept": "pm", "score": 100, "name": "jason" } 

Using ${variable}


You are passing the url value as postman-echo.com and you will see the following response:

Output in the table format

The output below is divided, into three rows, due to a very long horizontal original output.   

Output in the tree format

Using @{variable}

You can also use @{} for variable substitution as shown:


Output in the table format

The output below is divided, into five rows, due to a very long horizontal original output.

Output in the tree format

  • No labels