loading...

re: Testing your API with REST Client VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Can the variables be used inside POST data? I have added an item in a request. I can get the id from the response. Then I want to use the id in ...
 

Yes you can, you just have to call the first request, then the second request.
You can find below an example. I tested it, it works fine.

### First request
# @name myRequest
POST https://jsonplaceholder.typicode.com/posts
Content-Type: application/json

{
    "userId": 1,
    "title": "TEST 18",
    "body": "TEST body 18"
}

### Second request using response in body 
POST https://jsonplaceholder.typicode.com/posts
Content-Type: application/json

{
    "userId": 1,
    "title": "TEST ",
    "body": "TEST body {{myRequest.response.body.id}}"
}

### Second request using a variable 
@test2 = {{myRequest.response.body.id}}
POST https://jsonplaceholder.typicode.com/posts
Content-Type: application/json

{
    "userId": 1,
    "title": "TEST ",
    "body": "TEST body {{test2}}"
}
Code of Conduct Report abuse