Zoho Get an Invoice - php

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);
}

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'];
}

Related

Paytm refund api gives 501 - System error in response

I am using paytm refund api in php.
here is my code:
$checkSum = "";
$paramList = array();
// Create an array having all required parameters for creating checksum.
$paramList["MID"] = '**********';
$paramList["ORDERID"] = '*******'; //get during paytm transaction response
$paramList["TXNTYPE"] = 'REFUND';
$paramList["REFUNDAMOUNT"] = '50';
$paramList["TXNID"] = '***********'; // get during paytm transaction response
$paramList["REFID"] = 'REFID'.time();
//Here checksum string will return by getChecksumFromArray() function.
$checkSum = getRefundChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);
$paramList["CHECKSUM"] = urlencode($checkSum);
$data_string = 'JsonData='.json_encode($paramList);
// initiate curl
$ch = curl_init();
$url = 'https://securegw-stage.paytm.in/refund/HANDLER_INTERNAL/REFUND';
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true); // tell curl you want to post something
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string); // define what you want to post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return the output in string format
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$output = curl_exec ($ch); // execute
$info = curl_getinfo($ch);
$data = json_decode($output, true);
print_r($data);
Here is the response, i am getting:
Array ( [RESPCODE] => 501 [RESPMSG] => System Error. [STATUS] => PENDING )
I am not getting that what this system error means. What is the solution for this. Any help would be much appreciated.
Thanks in advance..
According to the error doc error 501 is an system error inside payTm.
https://developer.paytm.com/docs/refund-status-api/
I guess you are using payTm staging server. There is nothing wrong from your side, I suggest you to wait a few hours and try again. it will automatically work
I was facing the same issue because i had not declared the value of PAYTM_MERCHANT_KEY
before passing it to getRefundChecksumFromArray
$checkSum = getRefundChecksumFromArray($paramList,PAYTM_MERCHANT_KEY);
This line of code solved it
define("PAYTM_MERCHANT_KEY", "your_key_goes_here");

Firebase database delete specific data by php

How can I remove firebase specific data? I use the
php Kreait\Firebase library.
$fg = $database->getReference('raw_check_out')->orderByChild('reciptno')->equalTo($recipt)->getSnapshot();
$reb = $fg->getValue();
$fg->remove();
but this is not working.
Based on your code example:
$fg = $database
->getReference('raw_check_out')
->orderByChild('reciptno')
->equalTo($recipt)
->getSnapshot();
Here $fg does not hold the reference, but the snapshot.
If you want to remove the reference after you have retrieved the data you need, you need the reference itself:
$fg = $database->getReference('raw_check_out');
$query = $fg->orderByChild('reciptno')->equalTo($recipt);
$reb = $query->getSnapshot()->getValue();
$fg->remove();
This function is for unsubscribing users if you want to remove "user-id-8776" and your structure is like:
public function unsubscribe($uid)
{
$ref = $this->database->getReference()->getChild('users')->getChild($uid)->orderByChild($uid)->getReference();
$path = $ref->getUri()->getPath();
$ref->remove();
}
For any other data is more or less the same, you just have to find the reference of data you want to delete it and then you can remove it.
Check Image
You have another option to resolve this problem. This solution given below:
$url = "https://<projectID>.firebaseio.com/chatList/".<jsonFileName>."json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain'));
$result = curl_exec($ch);
curl_close($ch);

How to fetch only members fields name (Email address , First name , Last Name) in Mailchimp

I am trying to get all the fields name against list in mailchimp fields like email address , firstname and last name etc.
I am new in mailchimp i am testing with postman:
My controller code:
public function getFields()
{
$list = 'ba6de7f809';
$ch = curl_init(REQUEST_URL.$list.'/members/?fields=members.email_address','members.first_name','members.last_name');
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . 'xyz-us17');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error ( $ch );
curl_close($ch);
}
and my api route:
Route::get('getFields','ApiController#getFields');
I know there is some mistakes in my controller code i am declaring the list id in variable is it correct way to declare? and when i hit url in postman it says and i am using laravel 5.5.
Use of undefined constant REQUEST_URL - assumed 'REQUEST_URL' (this will throw an Error in a future version of PHP)
Can anyone please guide how to fetch fields name from this code:
Any help would be highly appreciated!
in you controller code
$ch = curl_init(REQUEST_URL.$list.'/members/?fields=members.email_address','members.first_name','members.last_name');
The REQUEST_URL you have used is not defined anywhere.
somewhere in you class you have to define the constant
const REQUEST_URL = 'https://usX.api.mailchimp.com/3.0'
I presume you could get this url from you mailchimp account
Additionally to get the user fields, rather than using /members/ endpoint you should use the search_members endpoint

Google web search api to get number of results with php

for keyword selection (seo)I need to know only the number of results for specific group of keywords. got this code from google https://developers.google.com/web-search/docs/), but no way. PHP version is 5.6
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=relax&userip=MYIP";
$referrer = "http://localhost:8080/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body);
in this case ... no results at all
I tried other ways ... eg.:
$url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=relax";
$body = file_get_contents($url);
$json = json_decode($body);
$results= $json->responseData->cursor->resultCount;
in this case I got some schizophrenic results (sometimes I got numbers, sometimes I got nothing)... in any case always under the declared limit of 1000.
any suggestion?
Thanks in advance.

Does anyone have any scripts to share that retrieve products using Commission Junction's API that actually work?

This example only displayed a blank page for me.
This one did as well.
I've got the latest version of PHP and cURL set up properly, as far as I know so there shouldn't be any problem at that end. I'd prefer JavaScript to retrieve products but I'm open minded.
I happen to not be highly skilled, but I'd like to get my foot in the door.
edit: I will show you the code that doesn't work, and the error it is giving me.
<?php
// Your developer key
$cj_id = "My ID - omitted for privacy.";
// Your website ID
$website_id = "Also removed for privacy.";
// Keywords to search for
$keywords = "credit+card";
// URL to query with cURL
$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&keywords=$keywords";
// Initiate the cURL fetch
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
// Send authorization header with the CJ ID. Without this, the query won't work
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$cj_id));
$result = curl_exec($ch);
// Put the results to an object
$resultXML = simplexml_load_string($result);
// Print the results
print "<pre>";
print_r($resultXML);
print "</pre>";
?>
Now, this is the error that it's giving me.
SimpleXMLElement Object
(
[error-message] => Invalid Key provided. Valid keys are: advertiser-ids, advertiser-sku, currency, high-price, high-sale-price, isbn, keywords, low-price, low-sale-price, manufacturer-name, manufacturer-sku, page-number, records-per-page, serviceable-area, sort-by, sort-order, upc, website-id
)
You have a error in your URL, try this:
$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&keywords=$keywords";
instead of :
$url = "https://product-search.api.cj.com/v2/product-search?website-id=$website_id&keywords=$keywords";
<?php
echo '<pre>';
$url='https://product-search.api.cj.com/v2/product-search?website-id=your-id-key-here&advertiser-ids=4415206&records-per-page=999&serviceable-area=US';
$CJ_KEY='0085eb59c8928f028ba5b27bccfe17cdd20cf4e9079b977b2cc6df72752abab9205676a2f7ee67befe9dccab85f656ef46aba49e500faccbf75dfc6e03f655334d/00848a3f9bf0e13525bce27f008d6245c3e42ae80f2d80a8d9d2220807ca386f4b10146cbbcfff06aafb5e49c03a3318213389dee7861abb2dd7229470390a89c9';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, FAlSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: '.$CJ_KEY));
$curl_results = curl_exec($ch);
$xml = simplexml_load_string($curl_results);
var_dump($xml);
// Loop Insert Product to database
echo '<pre>';
// if you no set: records-per-page=999, default get 50 products latest
// advertiser-ids=4415206 is Id of Advertiser in CJ, you can replace other id ,
Hope helpful for you , good luck !
?>

Categories