0

I'm using FuelSDK-node-REST to make API requests by following instructions given here: https://github.com/salesforce-marketingcloud/FuelSDK-Node-REST. Upon running my code, i am getting an error. Below is my code and the error i receive.

const FuelRest = require("fuel-rest");

const options = {
  auth: {
    clientId: "CLIENT_ID_HERE",
    clientSecret: "CLIENT_SECRET_HERE",
    authUrl:
      "https://MY_AUTH_URL.auth.marketingcloudapis.com/v2/token/", //Tried without '/v2/token/' also
  },
  origin: "https://MY_ORIGIN.rest.marketingcloudapis.com/",
};

const RestClient = new FuelRest(options);

const getOpts = {
  uri: "/platform/v1/endpoints",
  headers: {},
  // other request options
};

RestClient.get(getOpts)
  .then(function (response) {
    var result = response && response.body ? response.body : response;
    console.log(result);
  })
  .catch(function (err) {
    console.log(err);
  });

I get this error when i run my code:

{ Error: No access token
    at AuthClient.getAccessToken.then.tokenInfo (E:\Development\node-scripts\node_modules\fuel-rest\lib\fuel-rest.js:88:18)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:189:7)
  res:
   { error: 'unsupported_grant_type',
     error_description: 'Use "authorization_code" or "refresh_token" or "client_credentials" or "urn:ietf:params:oauth:grant-type:jwt-bearer" as the grant_type.',
     error_uri: 'https://developer.salesforce.com/docs' } }

I don't see any issues with permissions etc with the installed app in my account. Any help would be much appreciated!

1

If someone else stumbles across this, I was missing authOptions in the rest client initialization. Below is the correct way to init the rest client.

const options = {
  auth: {
    clientId: "CLIENT_ID_HERE",
    clientSecret: "CLIENT_SECRET_HERE",
    authUrl:
      "https://MY_AUTH_URL.auth.marketingcloudapis.com/v2/token/", 
authOptions: {
      authVersion: 2,
    }
  },
  origin: "https://MY_ORIGIN.rest.marketingcloudapis.com/",
};

const RestClient = new FuelRest(options);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.