# how can I make a curl request in my browser monitor

**URL:** <https://community.dynatrace.com/t/how-can-i-make-a-curl-request-in-my-browser-monitor/35650>\
**Category:** Synthetic Monitoring\
**Tags:** browser-monitors, javascript, synthetic-monitoring\
**Created:** [June 28, 2022, 7:48pm UTC](https://community.dynatrace.com/t/how-can-i-make-a-curl-request-in-my-browser-monitor/35650 "2022-06-28T19:48:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordan\_rose](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@jordan\_rose](https://community.dynatrace.com/u/jordan_rose)\
**Post date:** [June 28, 2022, 7:48pm UTC](https://community.dynatrace.com/t/how-can-i-make-a-curl-request-in-my-browser-monitor/35650/1 "2022-06-28T19:48:30Z")

</div>

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](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=[Debug a request - OpenID Connect Debugger](https://oidcdebugger.com/debug)’ \  
--data-urlencode ‘client\_secret=fd7d4bf54d68edc06559ffdb5f0265a8’

---

<div class="post-metadata">

**Author:** ![hannahmac](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@hannahmac](https://community.dynatrace.com/u/hannahmac)\
**Post date:** [June 29, 2022, 11:05am UTC](https://community.dynatrace.com/t/how-can-i-make-a-curl-request-in-my-browser-monitor/35650/2 "2022-06-29T11:05:24Z")

</div>

Something like this:

```auto
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 + <span>":"</span> + 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(<span>"token"</span>, token);
                api.finish();
            } else {
                api.fail(<span>"Invalid Response"</span>);
            }
        } catch (err) {
            api.fail(<span>"Failed to Execute"</span>);
        }
   }).catch(function(error) {
        api.fail(error); 
   });

```

---

<div class="post-metadata">

**Author:** ![jordan\_rose](https://avatars.discourse-cdn.com/v4/letter/j/8e8cbc/32.png) [@jordan\_rose](https://community.dynatrace.com/u/jordan_rose)\
**Post date:** [June 29, 2022, 12:15pm UTC](https://community.dynatrace.com/t/how-can-i-make-a-curl-request-in-my-browser-monitor/35650/3 "2022-06-29T12:15:47Z")

</div>

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!
