Good Afternoon all
Hope you are all well
I am trying to set a variable form extracting the CODE (in bold below) this string response
https://script.google.com/macros/d/1WsrBafTT3Ofqp2Znw_kXDyZUNd/usercallback?code=890890890809890809890&state=xyz"
Any ideas would be super helpful
SabriH
(Sabri H)
2
Hey @rainwave22,
Iโve uploaded a template to help provide some guidance on the way to achieve that. It can be found here: https://documenter.getpostman.com/view/10582367/SzYdSbmk?version=latest
Youโll want to look at the tests tab to see it. It would involve making use of the url
and querystring
libraries to fetch the information. More information available here: https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/#require
You could then set the environment variable or global by using the likes of pm.environment.set
if needed. More information about that here: https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/#require
Hopefully, this helps!
Sorry about the inexperience
but I am trying to do
let Data = pm.response.json();
pm.collectionVariables.set("code", pm.response.json().code[0].code);
to get
890890890809890809890
https://script.google.com/macros/d/1WsrBafTT3Ofqp2Znw_kXDyZUNd/usercallback?code= 890890890809890809890 &state=xyz"
from my response?
Hey @rainwave22,
What does your Response Body
look like?
If we can get that exactly how itโs received, it will be easier to offer a more targeted solution.
Just as a plain text string?
So if you were to do something like:
pm.globals.set("url", pm.response.text())
It would set that URL as the global variable?
trying to pull
code= โxxxxxxxxxxxxxxโ
just plain string
I know what youโre trying to do but what the response is and the format itโs returned in is very important.
So does the code I posted, set the whole string, as a global variable when run?
The whole string was set
Just need to pull the code out of the string now
This is completely hacky and horrible but if you just want the code value, it might do:
let str = pm.response.text()
pm.globals.set("code", str.split("=")[1].split("&")[0])
KING!!!
Thank you again Danny
About trying to set a variable form extracting the state (in bold below)
https://script.google.com/macros/d/1WsrBafTT3Ofqp2Znw_kXDyZUNd/usercallback?code= 890890890809890809890 &state=xyz"
How can I do? please help me
system
(system)
Closed
14
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.