Invalid authentication token

This thread is now closed to new comments.
Some of the links and information provided in this thread may no longer be available or relevant.
If you have a question please start a new post.
1 Post




Invalid authentication token

I'm using MYOB Essentials using OAUTH in the github code sample. I am getting the get request code and the access token but it displays Invalid authentication token error.

Below is code parameters passed

api_key, api_secret and redirect_url info are given as in the developer dashboard.

define('api_url',        '');
define('api_scope',        '');
define('base_url',        'http://localhost/AccountRight_OAUTH');

function getURL($url, $username=NULL, $password=NULL, $api_key) {
  //echo 'token: '.$_SESSION['access_token'];

  // build the cftoken
  $cftoken = base64_encode('Administrator:');

  // setup the session & setup curl options
  echo $_SESSION['access_token'] . '<br/><br/>';
  echo $cftoken . '<br/><br/>';
  echo $api_key . '<br/><br/>';

  //'x-myobapi-cftoken: '.$cftoken,
  $headers = array(
        'Authorization: Bearer '.$_SESSION['access_token'],
        'x-myobapi-key: '.$api_key,
        'x-myobapi-version: v0',
        'Accept: application/json'

  $session = curl_init($url);
  curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
  curl_setopt($session, CURLOPT_HEADER, false);
  curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
  // if there is a username present, assume we want to use it
  if($username) {
    // pass the username and password like 'usernameSmiley Tongueassword' to curl
    curl_setopt($session, CURLOPT_USERPWD, $username . ":" . $password);
  // get the response & close the session
  $response = curl_exec($session);
  // return what we got

$response = getURL('', '', '', api_key);

Below is the error output

object(stdClass)#1 (1) { ["errors"]=> array(1) { [0]=> object(stdClass)#2 (3) { ["field"]=> string(0) "" ["message"]=> string(29) "Invalid authentication token." ["code"]=> string(3) "401" } } }

Didn't find your answer here?

Try using advanced search to find a post more easily Advanced Search
Get the conversation started and make a new post Start a Post