Getting Empty response

This thread is now closed to new comments.
Some of the links provided in this thread may no longer be available or relevant.
If you have a question please start a new post.
1 REPLY 1
Former Staff DeveloperJack
140 Posts
Former Staff
Australia
DeveloperJack
Former Staff

141Posts

31Kudos

21Solutions

Re: Getting Empty response

Gday Mick,

 

I can see you're checking for the Message field in a reply to determine if there's been an error. The best way to check this is to determine the HTTP status code of the response.

 

If you're still getting errors, can you email the team via developers@myob.com and send them your full HTTP message trace (URI, headers and message body for both the request and response) and we'll help take a closer look.

 

Cheers,

Jack

Jack Skinner
MYOBapi Evangelist

Are you a developer? Check out http://developer.myob.com
Looking for an Add-on? Check out http://myob.com/addons/
Highlighted
Partner MickBurian
1 Post
Partner
Australia
MickBurian
Partner

1Posts

0Kudos

0Solutions

Getting Empty response

I am attempting to use API's to retrieve a list of Invoices from MYOB.

I have used the script below to succesfully get Contacts and Accounts, but, trying the same concept for invoices returns an empty response.  I have 2 test invoices setup in MYOB (one item and one service) so I would be expecting at least one line to be returned.  My code is below (I am using the example code from MYOB developers).

 

I would greatly appreciate some input and advise.

 

Code example follows

================

<?php

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
$headers = array(
'Authorization: Bearer '.$_SESSION['access_token'],
'x-myobapi-cftoken: '.$cftoken,
'x-myobapi-key: '.$api_key,
);

 

$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);
curl_close($session);
// return what we got
return($response);

}

// start a timer to check the API
$API_starttime = microtime();
$API_startarray = explode(" ", $API_starttime);
$API_starttime = $API_startarray[1] + $API_startarray[0];

$response = getURL(api_url.'/'.$_GET['guid'].'/Sale/Invoice/Item/', '', '', api_key);

$API_endtime = microtime();
$API_endarray = explode(" ", $API_endtime);
$API_endtime = $API_endarray[1] + $API_endarray[0];

// it returned as JSON so lets decode it
$response = json_decode($response);

if( isset( $response->Message ) ) {
$response = '<p class="well"><span class="label label-important">Error</span> Sorry there was an error<br />'.$response->Message.'</p>';
}

?>
<!-- Jumbotron -->
<div class="jumbotron">
<h2>Invoice List</h2>
<?php
echo "<pre>";
foreach ($response->Items as $key => $value) {
echo "<pre>";
print_r($value);
/*echo "Contact Information-->".$value->FirstName." - ".$value->CoLastName;
echo "Address-".$value->Addresses[0]->Street."--".$value->Addresses[0]->City."--".$value->Addresses[0]->State."--".$value->Addresses[0]->Phone1;
echo "<br>";
echo "<br>";
echo "<br>";*/
}

?>
</div>

<hr>

<!-- Example row of columns -->
<!-- <div class="row-fluid">
<div class="span4">
<h2>Do more</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>With Your</h2>
<p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
<div class="span4">
<h2>Company File</h2>
<p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa.</p>
<p><a class="btn" href="#">View details &raquo;</a></p>
</div>
</div>-->

 

Didn't find your answer here?
Try using advanced search to find a post more easily Advanced Search
or
Get the conversation started and make a new post Start a Post