Javascript net::ERR_ABORTED 400 when Getting the Access Token

XinwangN
Rookie
0 Votes
const client_id = '{client_id}';
const client_secret = '{client_secret}';
const authBase64 = btoa(client_id+':'+client_secret);
const redirect_uri = encodeURIComponent('http://localhost/constant-contact/index.html?id=0');

const options = {
  method: 'POST',
  mode: 'no-cors',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    Authorization: 'Basic '+authBase64
  }
};


let code = findGetParameter('code');
if (!code) {
  location.href = 'https://authz.constantcontact.com/oauth2/default/v1/authorize?client_id='+client_id+'&response_type=code&scope=contact_data&state=12345&redirect_uri='+redirect_uri;
}
console.log('code: '+code);
document.getElementById('authorization_code').innerText = code;

let url = 'https://authz.constantcontact.com/oauth2/default/v1/token?code='+code+'&redirect_uri='+redirect_uri+'&grant_type=authorization_code';

response = fetch(url, options);

if (response.ok) {
  console.log('response.status: '+response.status);
  document.getElementById('response').innerText = response.json();
}
1 REPLY 1
Courtney_E
Moderator
0 Votes

Hello XinwangN,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

Based on our logs for your account, it looks like you may have already resolved your issue.

 

However, if you still need assistance, please feel free to contact us directly/securely via email at webservices@constantcontact.com and reference case #30215783.  

 

Within your email, please also include the API key that you are using to make the request, the full request(s) where you are receiving the response error (including URL, headers, timestamp, and request body), and the full response body so that we can so that we can better assist you in identifying the root cause of the issue.

 

Please let us know if you have any other questions!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up