Forum Discussion

nkm's avatar
nkm
Experienced User
4 years ago

Bad Message 400 reason: Illegal character SPACE=' '

Hi, I am trying to retrieve the accounts using PHP curl. On Postman, I can use the query filter, but when I do it on my own script, it will return the error:

Bad Message 400

reason: Illegal character SPACE=' '. 

This is the url that I am using 

This is my code: 
$theHeaderArray = array(
'x-myobapi-key: '.$theAPIKey,
'x-myobapi-cftoken: '.$theCFToken,
'x-myobapi-version: v2',
'Accept Encoding: gzip,deflate',
'Authorization: Bearer '.$theAccessToken
);

$theGetAccountHandle = curl_init(); curl_setopt_array($theGetAccountHandle, array( CURLOPT_URL => $theCompanyURL.'/'.$theCompanyId.'/GeneralLedger/Account?$filter=Type%20eq%20\'OtherAsset\'', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => $theHeaderArray, )); $theAccounts = curl_exec($theGetAccountHandle); curl_close($theGetAccountHandle);

echo $theAccounts;
  • Hi nkm,

    Thanks for reaching out, The API Team is a technical support team trained to support the AccountRight and Essentials API. We provide support and advice for the API via the use of JSON and HTTP traces however we are not developers so do not know full languages. 

    I have tested this endpoint to ensure there were no issues on the endpoint using `GeneralLedger/Account?$filter = Type eq 'OtherAsset'` which gave a 200 successful responses. 

    I recommend double-checking the format of the filter as that does not look quite right when I decoded this. 

    Thanks, 

  • nkm's avatar
    nkm
    Experienced User

    The issue was the way I crafted out the HTTP header ($theHeaderArray) .   

    I changed the code to this: 

    $theGetAccountHandle = curl_init();
    
    curl_setopt_array($theGetAccountHandle, array(
      CURLOPT_URL => $theCompanyURL.'/'.$theCompanyId.'/GeneralLedger/Account?$filter=Type%20eq%20\'OtherAsset\'',
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_ENCODING => '',
      CURLOPT_MAXREDIRS => 10,
      CURLOPT_TIMEOUT => 0,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
      CURLOPT_CUSTOMREQUEST => 'GET',
      CURLOPT_HTTPHEADER => array(
        'x-myobapi-version: v2',
        'Accept-Encoding: gzip,deflate',
        'x-myobapi-key: '.$theAPIKey,
        'x-myobapi-cftoken: '.$theCFToken,
        'Authorization: Bearer '.$theAccessToken
      ),
    ));
    
    $theAccounts = curl_exec($theGetAccountHandle);
    
    curl_close($theGetAccountHandle);
    
    echo $theAccounts;
  • Han-Solo's avatar
    Han-Solo
    MYOB Moderator

    Hi nkm,

    Thanks for reaching out, The API Team is a technical support team trained to support the AccountRight and Essentials API. We provide support and advice for the API via the use of JSON and HTTP traces however we are not developers so do not know full languages. 

    I have tested this endpoint to ensure there were no issues on the endpoint using `GeneralLedger/Account?$filter = Type eq 'OtherAsset'` which gave a 200 successful responses. 

    I recommend double-checking the format of the filter as that does not look quite right when I decoded this. 

    Thanks, 

    • nkm's avatar
      nkm
      Experienced User

      Hi Han-Solo ,

      Thank you for the reply. I have double checked the format and there was no problem with it. The issue was the way I handled the headers.