Asher Travis
Asher Travis

Reputation: 21

Node: Consume API Call and Pass to another API Call

Sorry if this has been asking already but I cannot seem to find a straight answer.

I need to post data to one API endpoint that returns a token. I then need to use that token in a header to make a separate GET request to another endpoint to return the data I want.

The tokens are only good for a few minutes so if the GET endpoint responds token invalid it will send another POST request to get a new token and start the process all over.

I have been trying multiple async methods, promises, etc without luck. Thank you in advance.

Upvotes: 0

Views: 43

Answers (1)

Evert
Evert

Reputation: 99728

Conceptually:

await apiCall2(
  await apiCall1()
);

Upvotes: 0

Related Questions