Reputation: 31
I've been trying to figure out how to put the two pieces together...so my task is to call a GET request from OpenWeatherMap API and send it as a text message(Twilio API) through Postman. I am curious how to go about it? I was thinking if there is a possible way to call the Weather API as a 'body' on my Twilio POST request.
My mission is to successfully post the current weather as a text message through Twilio on Postman, and I see that I would have to make one request as a 'body' in the other. Any help or insight would be appreciated, thanks!
Upvotes: 0
Views: 133
Reputation: 3434
You can use pm.sendRequest
in the pre-request script
of your request.
You can store the response (or the parts of it that you need), in Environment variables
and re-use them.
pm.sendRequest
: https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#sending-requests-from-scriptspre-request script
: https://learning.postman.com/docs/writing-scripts/pre-request-scripts/Environment variables
: https://learning.postman.com/docs/sending-requests/managing-environments/Upvotes: 0
Reputation: 73057
Twilio developer evangelist here.
You cannot make requests as part of the body of another request. The "body" of a request is the data that you are sending to that APIs endpoint, and the "Body" parameter you are referring to above is the text of the message that you want to send via Twilio.
In Postman, however, you can chain requests together using the response of one request as data that you can feed into the next request. To find out more about this read up on Extracting Data from Responses and Chaining Requests.
In this case you will want to create an environment to make your requests in and create a environment variable called message. Then make your first request to the weather API then use the Postman scripting after to set the message environment variable based on the response from the API. Finally you set up the second request to Twilio and set the value for the "Body" parameter to be your {{message}}
environment variable.
Check out the documentation on Postman to see how this works in more depth.
Upvotes: 0