Skip to content

Best practise to chain API calls? #942

Closed Answered by Sl-Alex
CoenraadS asked this question in Q&A
Discussion options

You must be logged in to vote

I'd do it like this:

Request 1. Execute GET /api/foo/latest, get the ìd out of the body and put it to the collection variable in the post-request script:

bru.setVar('app-foo-latest-id', res.body.id);

Request 2. Execute GET /api/foo/ request with the following pre-request script:

req.setUrl(req.getUrl() + bru.getVar('app-foo-latest-id'));

Collection variables work across different requests in the same collection.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@CoenraadS
Comment options

@carlinmack
Comment options

Answer selected by CoenraadS
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants