0

I'm attempting to get the Salesforce Access Token using typescript and Axios. Unfortunately, I'm getting a Serialized Error. I can't figure out why. Can anyone assist me, please?

import axios from 'axios';

let clientId : string = ‘somestring-1’;
let clientSecret : string = ‘somestring02’;

let body = {
     grant_type: "password",
     client_id: clientId,
     client_secret: clientSecret,
     username: ’s’omeusername,
     password: ‘somepassword_concatonated_with_secret’
}

let headers = {
    "Authorization": `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`,
    "Content-Type": 'application/x-www-form-urlencoded'
}

let data = await axios.post('https://test.salesforce.com/services/oauth2/token', body, {headers});

The results is

AxiosError: Request failed with status code 400

and

Serialized Error: Object { "code": "ERR_BAD_REQUEST"

What on earth am I doing wrong?

1
  • 2
    Do you actually need to send an Authorization header? There is nothing about it in documentation - help.salesforce.com/s/…
    – kurunve
    Oct 19, 2022 at 7:33

1 Answer 1

0

I believe this will solve your issue.

I had to switch on "Follow Authorization header" in Postman under "Settings" for the REST endpoints to work. I was using a Bearer Token generated through oAuth.

https://developer.salesforce.com/forums/?id=906F000000099xAIAQ

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .