Zoho Get an Invoice

342 Views Asked by At

I am trying to integrate zoho with my web app. I am making an api call to get a particular invoice. The call as per documentation is

'https://books.zoho.com/api/v3/invoices/INV_ID?organization_id=XXXXXXXX'

This works fine as well. But when I set a variable for INVOICE ID, it returns all the invoices. (200 INVOICES) The call is below.

'https://books.zoho.com/api/v3/invoices/' .$inv_id. '?organization_id=XXXXXXXX';

where I am making the mistake? The method is below.

$zid = '';
if(isset($_POST['_zid'])){
    $zid = $_POST['_zid'];
}
get_invoice($access_token, $zid);
function get_invoice($access_token, $zid){
    $invid = $zid;
    $service_url = $GLOBALS['service_url'] . 'https://books.zoho.com/api/v3/invoices/' .$invid. '?organization_id=XXXXXXXXX';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_URL, $service_url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Authorization: Zoho-oauthtoken '. $access_token,
        'Content-Type: "application/json"'));
    $res = curl_exec($ch);
    curl_close($ch);
    $dec_res = array();
    $dec_res = json_decode($res, true);
    print_r($dec_res);
}
1

There are 1 best solutions below

0
On BEST ANSWER

Everything is fine except a small thing. I didn't think of Array Declaration. The working call is straightly given an integer as the invoice_id. when I pass the variable declared as a string. so although the digits it is counted as a string which makes the call invalid.

//THIS WILL DO THE TRICK
$zid = 0;
if(isset($_POST['_zid'])){
    $zid = $_POST['_zid'];
}