Zoho crm API sometimes returns error - api

I'm trying to searchRecord using the Zoho CRM API and I sometimes get the following error:
Array ( [response] => Array ( [error] => Array ( [message] => Unable
to process your request. Please verify whether you have entered proper
method name,parameter and parameter values. [code] => 4600 ) [uri] =>
/crm/private/json/Contacts/searchRecords ) )
My problem is that sometimes everything works fine and sometimes I get this error
define("TARGETURL", "https://crm.zoho.com/crm/private/json/Contacts/searchRecords");
$parameter = array(
'scope' => 'crmapi',
'authtoken' => AUTHTOKEN,
'selectColumns' => 'All',
'criteria' => '(Account Name:'.$accountName.')',
'fromIndex' => $fromIndex,
'toIndex' => $toIndex
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, TARGETURL);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter);
$result = curl_exec($ch);
curl_close($ch);

Try search field with double quotation mark, following is script to search email from lead module.
$xmlData = "(Email:$email)";
$ch = curl_init('https://crm.zoho.com/crm/private/xml/Leads/searchRecords');
curl_setopt($ch, CURLOPT_VERBOSE, 1); //standard i/o streams
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turn off the server and peer verification
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set to return data to string ($response)
curl_setopt($ch, CURLOPT_POST, 1); //Regular post
$authtoken = "********************************";
$query = "authtoken=" . $authtoken . "&scope=crmapi&criteria=" . $xmlData;
curl_setopt($ch, CURLOPT_POSTFIELDS, $query); // Set the request as a POST FIELD for curl.
$response = curl_exec($ch);
curl_close($ch);

Related

Whatsapp Cloud Api get Media Object ID

I want to upload the media via Whatsapp cloud API in order to send the media to WhatsApp, I have followed the link below, but having the stated issue.
https://developers.facebook.com/docs/whatsapp/cloud-api/reference/media#get-media-id
Array ( [error] => Array ( [message] => (#100) The parameter messaging_product is required. [type] => OAuthException [code] => 100 [fbtrace_id] => AQPftb9Bf343375gQ_QytxNen ) ) 400
My Code is
// #1640191015925.jpg on my root folder
$post = [
'file' => '#1640191015925.jpg;type=image/jpeg',
'messaging_product' => 'whatsapp'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v13.0/Phone-Number-ID/media');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$headers = array();
$YOUR_WHATSAPP_ACCESS_TOKEN = '+++++++';
$headers[] = "Authorization: Bearer $YOUR_WHATSAPP_ACCESS_TOKEN";
$headers[] = "Content-Type: image/jpeg";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = json_decode(curl_exec($ch), true);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//$MEDIA_OBJECT_ID = $result['media'][0]['id']; //MEDIA OBJECT ID
print_r($result);
print_r($httpcode);
?> ```
I had the same issue, after some digging around I wrote this function to upload a file and return the id.
function waFileUploader($token, $file, $senderid){
$mime = mime_content_type($file);
$info = pathinfo($file);
$name = $info['basename'];
$curlfile = new CURLFile($file, $mime, $name);
$filedata = array("messaging_product"=>"whatsapp", "file" => $curlfile);
$url = 'https://graph.facebook.com/v13.0/' . $senderid . '/media';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Authorization: Bearer $token", "Content-Type: multipart/form-data"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $filedata);
$r = curl_exec($ch);
curl_close($ch);
$id = json_decode($r, true);
return $id["id"];
}

How to update Products inventory from 3rd party POS system in Magento2?

How to update Products inventory from 3rd party POS system in Magento2?
I need to make a button in POS system when I hit that button the products inventory should be update from POS to Magento2 system.
Here is working code for update qty from Rest API
<?php $adminUrl = 'http://localhost/magento2/rest/V1/integration/admin/token/';
$ch = curl_init();
$data = array("username" => "admin", "password" => "admin"); //Admin Login details
$data_string = json_encode($data);
$ch = curl_init($adminUrl);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_string)));
$token = curl_exec($ch);
$token= json_decode($token);
$headers = array("Authorization: Bearer $token","Content-Type: application/json");
$skus = array('100001' => 66,'100002' => 99); //Here 100001 and 100002 are SKU and 66 and 99 are Qty
foreach ($skus as $sku => $stock) {
$requestUrl='http://localhost/magento2/rest/V1/products/' . $sku . '/stockItems/1';
$sampleProductData = array("qty" => $stock);
$productData = json_encode(array('stockItem' => $sampleProductData));
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $requestUrl);
curl_setopt($ch,CURLOPT_POSTFIELDS, $productData);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
unset($productData);
unset($sampleProductData);
}

areto api payment gateway

I am trying to implement the Areto API payment gateway, but it returns response with authentication error such as :
Authentication failed - invalid ID/Session/IP combination.
I am try to first time implement (this type) payment gateway.
how to implement Areto API payment gateway.
Just have use the code like this:
<?php
$url = 'https://pay.aretosystems.com/api/sale/v1';
$api_session = 'ZXUKwKG97WCEdyYBZxnBgFOutVj5qdO7yWaYxT5T9CAbPMn4tamzUpH0HgtdIn6b';
$api_id = '6mK+KXQ5dadlu+4qnxpY3jtH/Hg56AgMhhpOMWXP0/TCmbE6OhXZkG/QRjE/dNjQ';
$transaction = array(
"Authentication" => array(
"Id" => $api_id,
"Session" => $api_session
),
"Order" => array(
"OrderId" => "TESTSALE",
"Amount" => "0.01",
"CurrencyCode" => "EUR"
),
"CardDetails" => array(
"CCVC" => "123",
"CCExpiryMonth" => "01",
"CCExpiryYear" => "2017",
"CCName" => "Wdp",
"CCSurname" => "Tech",
"CCNumber" => '4200000000000000',
"CCType" => "VISA",
"CCAdress" => "542, surya nagar",
"ClientCity" => "Jaipur",
"ClientCountryCode" => "US",
"ClientZip" => "302017",
"ClientEmail" => "wdpjaipur#gmail.com",
"ClientExternalIdentifier" => "MytestUserName1",
"ClientIP" => "162.158.50.205",
"ClientPhone" => "1234567890"
)
);
$data_string = json_encode($transaction);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$http_status . PHP_EOL;
$responceData = json_decode($response, TRUE);
echo '<pre>';
print_r($responceData);die;
?>
This part of the API is not very well documented, but after we found this question we were finally able to find a way to solve the problem:
The key is to have all the properties you want to send concatenated into a string divided by & characters and send them as plain text via POST.
If you want to try it out in Postman:
1) enter the properties as url parameters
2) copy the string from the url
3) and paste it in the request body, setting the type to plain text.
error_reporting(1);
$url = 'https://pay.aretosystems.com/api/sale/v1';
$api_session = 'ZXUKwKG97WCEdyYBZxnBgFOutVj5qdO7yWaYxT5T9CAbPMn4tamzUpH0HgtdIn6b';
$api_id = '6mK+KXQ5dadlu+4qnxpY3jtH/Hg56AgMhhpOMWXP0/TCmbE6OhXZkG/QRjE/dNjQ';
$clientIP = $_SERVER['REMOTE_ADDR'];
$request_arr = array(
'Id'=>$api_id,
'Session'=>$api_session,
'OrderId'=>time(),
'Amount'=>'4.0',
'CurrencyCode'=>'EUR',
'CCVC'=>'123',
'CCExpiryMonth'=>'12',
'CCExpiryYear'=>'2017',
'CCName'=>'wdp',
'CCSurname'=>'technologies',
'CCNumber'=>'4200000000000000',
'CCType'=>'VISA',
'CCAddress'=>'surya nagar',
'ClientCity'=>'Ajmer',
'ClientCountryCode'=>'IN',
'ClientZip'=>'302018',
'ClientEmail'=>'wdpjaipur1#gmail.com',
'ClientExternalIdentifier'=>'Wdp tech',
'ClientIP'=>$clientIP,
'ClientPhone'=>'1234567890',
'ClientDOB'=>'1989-11-05'
);
$ch = curl_init();
$post_variables = '';
foreach ($request_arr as $key => $value) {
$post_variables .= "{$key}={$value}&";
}
$post_variables = rtrim($post_variables, '&');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_variables);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
$responceData = json_decode($response, TRUE);

Updating Event Details using Eventrite API v3

I'm trying to edit Eventbrite event using version 3 of the API but I always returns false.
$request_url = 'https://www.eventbriteapi.com/v3/events/xxxxxx';
$options = array(
'http' => array(
'method' => 'POST',
'header'=> "Authorization: Bearer xxxxxxxxxx"
),
'name' => array(
'text'=>'Hi',
'html'=>'<p>Hi</p>'
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $options);
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$json_data = curl_exec($ch);
$resp_info = curl_getinfo($ch);
curl_close($ch);
var_dump($json_data);
This always returns me :
boolean false
What am I doing wrong?
You don't need to create an options array with curl as you are setting those options in curl_setopt. Just make a data array and submit it.
<?php
$request_url = 'https://www.eventbriteapi.com/v3/events/xxxxxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
'name' => array(
'text'=>'Hi',
'html'=>'<p>Hi</p>'
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$json_data = curl_exec($ch);
$resp_info = curl_getinfo($ch);
curl_close($ch);
var_dump($json_data);
Though according to the docs there is a minimum amount of data to create an event.

How to login using mediawiki API?

$ch=curl_init();
$postfield = "action=login&lgname=d&lgpassword=Password&format=json";
$url = "http://wiki.signa.com/api.php"; //url to wiki's api
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = json_decode(curl_exec($ch));
curl_close($ch);
print_r($output);
$token = $output->login->token;
$session = $output->login->sessionid;
$ch=curl_init();
$postfield = "action=login&lgname=d&lgpassword=Password&lgtoken={$token}";
$url = "http://wiki.signa.com/api.php"; //url to wiki's api
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfield);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
print_r($output);
die;
With the first request I get this object:
stdClass Object
(
[login] => stdClass Object
(
[result] => NeedToken
[token] => ad61fadb829e5cd44b0062463b7cc2d2
[cookieprefix] => wikisign_mediawiki
[sessionid] => ebb892881eed27554161234916d00480
)
)
I'm using the token to do a second request, but I get result = NeedToken. It should be success since I'm sending the token now.
I noticed the documentation says:
Send a login request with POST, with confirmation token in body and the session cookie (e.g. enwiki_session) in header as returned from previous request.
I'm not totally clear on that. I'm assuming I'm having issues because I'm not sending the session cookie in the header. Do I need to set a cookie prior to the second request?
Yes, you need to process all Set-Cookie Headers to login succesfully.
Documentation is very specific on this:
This request will also return a session cookie in the HTTP header
(Set-Cookie: enwikiSession=17ab96bd8ffbe8ca58a78657a918558e; path=/;
domain=.wikipedia.org; HttpOnly) that you have to return for the
second request if your framework does not do this automatically
A successful action=login request will set cookies needed to be
considered logged in. Many frameworks will handle these cookies
automatically (such as the cookiejar in cURL). If so, by all means
take advantage of this. If not, the most reliable method is to parse
them from the HTTP response's Set-Cookie headers.
It's an old subject, but I'll answer for those who are interested :)
In fact you need to keep your cookies in a file and use them again in your second attempt to login.
Something like that :
$path_cookie = 'connexion_temporaire.txt';
if (!file_exists($path_cookie)) touch($path_cookie);
$postfields = array(
'action' => 'login',
'format'=> 'json',
'lgname' => $login,
'lgpassword' => $pass
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $lienTestWiki);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIEJAR, $path_cookie); // you put your cookie in the file
$connexion=curl_exec($curl);
$json_connexion = json_decode($connexion, true);
$tokenConnexion=$json_connexion['login']['token']; // you take the token and keep it in a var for your second login
// /!\ don't close the curl conection or initialize a new one or your session id will change !
$postfields = array(
'action' => 'login',
'format'=> 'json',
'lgtoken' => $tokenConnexion,
'lgname' => $login,
'lgpassword' => $pass
);
curl_setopt($curl, CURLOPT_URL, $lienTestWiki);
curl_setopt($curl, CURLOPT_COOKIESESSION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
curl_setopt($curl, CURLOPT_COOKIEFILE, $path_cookie); //get the previous cookie
$connexionToken=curl_exec($curl);
var_dump($connexionToken);
When running this you should see a success this time :)