28 Jun 2022 08:48 PM
As one of my synthetic events in my browser monitor I have need to make a curl request and capture some of the return data to use in another step. I am struggling on how to convert to js or if this is possible.
Any help on this is very appreciated.
Here is post request.
curl --location --request POST 'https://someurl.com/auth/oauth2/access_token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: NSC_bvuifoujdbujpo-tuhb_443=ffffffffaf1a5c9b45525d5f4f58455e445a4a4229a0; NSC_jh-tuhb_443=ffffffffaf1a5c9445525d5f4f58455e445a4a4216cb' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code=LLz_H3aMMGZle7PtqJxrA8cj0fU' \
--data-urlencode 'client_id=902c9ae8b9ac98fb12a785e925f889a0' \
--data-urlencode 'redirect_uri=https://oidcdebugger.com/debug' \
--data-urlencode 'client_secret=fd7d4bf54d68edc06559ffdb5f0265a8'
Solved! Go to Solution.
29 Jun 2022 12:05 PM
Something like this:
api.startAsyncSyntheticEvent(); fetch('<yoururl>', { method: 'POST', headers: { 'Cookie: NSC_bvuifoujdbujpo-tuhb_443=ffffffffaf1a5c9b45525d5f4f58455e445a4a4229a0; NSC_jh-tuhb_443=ffffffffaf1a5c9445525d5f4f58455e445a4a4216cb', 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ 'grant_type': 'authorization_code', 'code': 'LLz_H3aMMGZle7PtqJxrA8cj0fU', 'client_id': '902c9ae8b9ac98fb12a785e925f889a0', 'redirect_uri': 'https://oidcdebugger.com/debug', 'client_secret': 'fd7d4bf54d68edc06559ffdb5f0265a8' } }).then(function(response) { if (!response.ok) { throw Error(response.status + ":" + response.statusText); } return response; }).then(response => response.text()).then(text => { try { api.info('Resp length: ' + text.length); if (text.indexOf('code') >= 0) { <your code to retrieve token> api.setValue("token", token); api.finish(); } else { api.fail("Invalid Response"); } } catch (err) { api.fail("Failed to Execute"); } }).catch(function(error) { api.fail(error); });
29 Jun 2022 01:15 PM
Hannah, thank you so much for doing this work and helping. I dont know js like this so you are a huge help right now.
Thanks again!