How to create custom function in zoho crm? - zoho

Please help me in how to create the custom function to search records from custom module in zoho crm.
I am new to zoho crm so I do not have any idea about how to code for this.
The workflow triggers on Event create.
In custom module LEADID is inserted into Lead Id field and I want to search record by Lead Id fields value from custom module.
In function I passed the lead id for search record.
Below is sample code which I create but it does not work .
Lead_id=input.LeadID.toString();
Event_id=input.EventID.toString();
rec = zoho.crm.getRecordById("Events",input.EventID);
resp = zoho.crm.searchRecords("CustomModule1","Lead Id",input.LeadID);
for each ele in resp
{
mp=map();
mp.put("Event Created Time",rec.get("Created Time"));
contactId=ele.get("CUSTOMMODULE1_ID");
updateResp = zoho.crm.updateRecord("CustomModule1",contactId,mp);
}

Here is sample API method using PHP ,code for getting record from Lead module using Lead ID
$auth = "*************************";// Auth Keys
$id="****************";// Record Id
////////////get data by Id from Zoho Lead Module ///////////
$get_url = "https://crm.zoho.com/crm/private/json/Leads/getRecordById?";
$get_query = "authtoken=".$auth."&scope=crmapi&id=".$id."";
$get_curl = curl_init();
curl_setopt($get_curl, CURLOPT_URL, $get_url);
curl_setopt($get_curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($get_curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($get_curl, CURLOPT_TIMEOUT, 60);
curl_setopt($get_curl, CURLOPT_POST, 1);
curl_setopt($get_curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($get_curl, CURLOPT_POSTFIELDS, $get_query);
$get_response = curl_exec($get_curl);
$jfo = json_decode($get_response);
echo "<pre>";
curl_close($get_curl);
print_r($jfo);

Related

How to send multiple files under the same name using CURL in php7+

Hi am trying to send multiple files in a php Curl operation. I am using PHP7.2 and trying to send 15 images under the same key.
If I am trying to send just 1 file its working just fine.
$post["image"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
But when I am trying to put multiple files its not working anymore.
Already tried
$post["image[0]"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
And
$post["image_0"] = new \CurlFile('image_full_path.png', 'image/png', 'file.png');
Does not work
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"url");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: multipart/form-data"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
$path = '/var/www/download/download.pdf';
file_put_contents($path, $response);
echo $response;
I believe you just need to create an associative array to send multiple images with the same key.
$post["image"] = [
new \CurlFile('image_full_path1.png', 'image/png', 'file1.png'),
new \CurlFile('image_full_path2.png', 'image/png', 'file2.png'),
];
It seems like the issue is with my destination of the request. The end point of the curl is written on Python Flask and it seems like if we send it like we do in php, flask dont understand it.
So in php
image[0] => 'image1.png'
image[1] => 'image2.png'
Can be valid and we will get both the files under image key in the request,
in python they are coming in different keys like
image[0] and image[1].
If we are tring to look for image in the request it will give an error, but image[0] and image[1] as a string are working fine.
The solution was to send the files as base 64encoded url in an associative array.
P.S. I am not an expert in Python, so my explanation can be wrong. If some one knows python and is aware if this issue please comment here.
Thank you.

Return a file in my controller that is downloaded from an API

I would like to return a file in my controller that is downloaded from an API (who needs a basic auth).
This API returns the file and the problem is I can't use ajax because of Access-Control-Allow-Origin, even when I add the basic auth in the header, it returns this error. And I don't have access to this API so I can't change it the config.
So I found another way! I call this API from my controller with the header and the basic auth. It's working! I can access this API and I don't have the error message: Access-Control-Allow-Origin.
But the problem is the API returns heavy files, and I have this exception OutOfMemoryException. It's normal.
So I would like to returns in my controller just a redirect link to this API with the header and basic auth to download the file. Do you think it's possible?
An example of what I want (But it's not working):
public function indexAction()
{
// API
$url = "http://api-who-callback-a-file.com/api/file";
//Create header
$curl = curl_init();
$url = sprintf("%s?%s", $url, http_build_query(false));
// Optional Authentication:
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:admin");
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Get file (Problem here because the file is to heavy to be downloaded by the server)
$result = curl_exec($curl);
curl_close($curl);
// Return the file
return $this->file($result);
}
In this example, it's not working because the server download the file and it's too heavy. Me I just want to return the URL with the Header to the client, and he will download the file.
Thank you

How to integrate third party api in my site magento

I am using Magento ver. 1.9.2.1.
I don't have any idea to integrate third party api in magento. I have to integrate the api for website.com, for that they provide the login details and a doc.
In that doc, it is mentioned to integrate
1. Search Service Availability API
2. Order Creation API
3. Tracking API
For each above API, they provide code,details and json response.
I have created a user and role from admin. And create a file test.php in root folder and put their code and checked in browser, but it shows blank
Given code in doc for Search Service Availability API:
<?php
ob_start();
error_reporting( 0 );
ini_set('display_errors', 'off');
$pickup_pincode = ‘110001’ // pass pincode
$delivery_pincode =’110001’; // Pass the Parameters Here pincode
$service=’Online’ // Cod or Online
$weight=’1’ // pass weight
$service_name = ‘Standard’ // standard / Priority / Economy
$request_url ='http://avnbiz.co.in/test/AVNBIZ/webservice/test_search_service.php';
$post_data =
'&pickup_pincode=$pickup_pincode&delivery_pincode=$delivery_pincode&weight=$w
eight&service=$service&service_name=$service_name'';
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $request_url);
curl_setopt($post, CURLOPT_POST,TRUE);
curl_setopt($post, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($post, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($post);
curl_close($post);
print_r($response);
$result = json_decode($response, true);
print_r($result);
?>
response
[{"Service Name":"Standard","partner_id":"2","partner_name":"DOT
ZOT","price":"0","status":"PRICE NOT AVAILABLE "},{"Service
Name":"Standard","partner_id":"9","partner_name":"GATI","price":"0","status":"PRICE
NOT AVAILABLE "},{"Service
Name":"Standard","partner_id":"324","partner_name":"Fedex TSCI Pvt
Ltd","price":"50","status":"Success"},{"Service
Name":"Standard","partner_id":"327","partner_name":"GATIKWE EXPRESS PVT
LTD","price":"50","status":"Success"},{"Service
Name":"Standard","partner_id":"335","partner_name":"demo","status":"NO SERVICE
AVAILABLE"}]
If anyone has any idea, please let me know where I am making a mistake.

How to add segment that is a certain subgroup using Mailchimp API v3

I want to create a subgroup that is a subgroup, using API v3, and I'm not sure how to set the condition in the request. For some reason I can't get to the Playground today, so I can't play with it.
I'm thinking something like:
function createSegment($apikey, $dc, $list_id, $name) {
$data = array(
"name"=> $name,
**CONDITION**
);
$data = json_encode($data); // API requires JSON objects
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://".$dc.".api.mailchimp.com/3.0/lists/".$list_id."/segments");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true); // declare request is POST type
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // set POST data
curl_setopt($ch, CURLOPT_USERPWD, "user:".$apikey); // HTML Basic Auth
$output = curl_exec($ch); // execute and capture response
curl_close($ch);
}
This is what the API Support had to say:
With the release of version 3.0 of our API we made some changes to the structure of how we use IDs. In this case there are currently 2 sets of IDs that groups can be referenced by, depending on which version of the API you are using.
In version 2.0, the group ID is an integer and can be retrieved using the /lists/interest-groupings call here:
https://apidocs.mailchimp.com/api/2.0/lists/interest-groupings.php
With version 3.0, the group ID is a hash and is returned by making a GET request to the Lists Interest Collection endpoint here:
http://kb.mailchimp.com/api/resources/lists/interest-categories/interests/lists-interests-collection
When creating a segment however, we currently only accept the group ID returned in version 2.0 of the API, regardless of whether that segment call is being made with 2.0 or 3.0. For this reason, when segmenting by groups, a call would need to be made to the 2.0 endpoint to retrieve those groups IDs. These IDs are static though, so if they are expected to be updated, they would only need to be requested once and can then be stored locally.

Codeigniter session sometimes kicking me out after completing call to a third party API

I got this strange problem for long and have been trying to solve it without any success.
I got a CI site based on CI 1.7.2. It works fine for most of the time. But many a time it does not.
The problem is, we fill up up a form with many fields and submit it to a method in the controller which does the checking. It then posts the data to the third party web service using curl.
I have a error/order response tracker setup, which mails me every time I get response back from the API. The mail content is of the format:
Order ID: 5876 Result length - 8056 or
Order ID: 5877 Result length - 1121 ....and so on for each order.
Now, many a time I get mail like:
Order ID: Result length - 34441 (Please note the order id is missing here)
Order ID: Result length - 9700
Now , the code for my mail happens to be
mail('myemail#xyz.com','Order ID: '.$this->session->userdata('SITE_ORDER_NO').' Result length - '. $lengthResponse , $orderResult, $headers);
So its seems the,
$this->session->userdata('SITE_ORDER_NO')
segment of the code does not have the Order ID any more. As such the API response is not getting saved in the database . Also I got few reports that the user was logged out of the website after it transferred him to the next page , after the response came back.
My session setup is:
$config['sess_cookie_name'] = 'cisessionJHGJHSOMECAPITALLETTERS';
$config['sess_expiration'] = 7200;
$config['sess_encrypt_cookie'] = TRUE;
$config['sess_use_database'] = TRUE;
$config['sess_table_name'] = 'user_sessions';
$config['sess_match_ip'] = TRUE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
The code of the helper function is:
function call_order_curl($postVars){
$posturl = "API_URL";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $posturl);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,300);
curl_setopt($ch,CURLOPT_TIMEOUT,600);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVars);
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
return $response;
}
I would really appreciate any help on this. Thank you.

Resources