# Extracting the code for an Oauth 2 Call

**URL:** <https://community.postman.com/t/extracting-the-code-for-an-oauth-2-call/3313>\
**Category:** Help Hub\
**Created:** [November 16, 2018, 4:29pm UTC](https://community.postman.com/t/extracting-the-code-for-an-oauth-2-call/3313 "2018-11-16T16:29:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![philb12345](https://avatars.discourse-cdn.com/v4/letter/p/b19c9b/32.png) [@philb12345](https://community.postman.com/u/philb12345)\
**Post date:** [November 16, 2018, 4:29pm UTC](https://community.postman.com/t/extracting-the-code-for-an-oauth-2-call/3313/1 "2018-11-16T16:29:35Z")

</div>

I have successfully created a post call to pick up a token.

When I click the code snippet and put it my code, I am getting a

Access to XMLHttpRequest at ‘[test.company&nbsp;-&nbsp;This website is for sale!&nbsp;-&nbsp;test Resources and Information.](Https://test.company/auth/token)’ from origin test’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

The javascript code snippet generated does not contain all things necessary.

```
var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://testcompany.com/API/Auth/Token",
  "method": "POST",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "cache-control": "no-cache",
    "Postman-Token": "23423-12345ff"
  },
  "data": {
    "grant_type": "client_credentials",
    "client_id": " 12345-abcdeftest",
    "client_secret": "2345-abcdefgh"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

```

The credentials have been changed from the working ones for this segment
