Integration: Active Collab - Zoho Projects
I'm trying to create a new Time entry under a task in Zoho Projects, using the API.
I've already synced up tasks and projects. But I'm having a hard time creating a time entry.
I've tried with php and with postman. On both ends I get the same error:
Response HTTP Status Code : 400
{"error":{"code":6500,"message":"General Error"}}
Here's my request:
$request_parameters = array(
'authtoken' => 'APITOKEN',
'date' => '02-20-2018',
'bill_status' => 'Billable',
'hours' => '02:22'
);
These are being passed as URL parameters.
If I change any of the parameters the error code changes.
I'm using the example provided in the Zoho Project documentation page:
Not sure what's up.
Here's the request URL:
https://projectsapi.zoho.com/restapi/portal/hidden_portal_id/projects/1167980000000355033/tasks/1167980000000355033/logs/?authtoken=hidden_api_token&date=02-20-2018&bill_status=Billable&hours=02%3A22
I've found a similar thread but could not figure it out based on that
Thanks.
Here's the full code:
/* Set the Request Url (without Parameters) here */
$request_url = 'https://projectsapi.zoho.com/restapi/portal/hidden_portal_id/projects/'.$endpoint;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$request_parameters = array(
'authtoken' => 'hidden_api_key',
'date' => '02-20-2018',
'bill_status' => 'Billable',
'hours' => '02:22'
);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));
//I've added this line because I've found a similar error 6500 thread see the link above
$request_url .= '?'. http_build_query($request_parameters);
/* Here you can set the Response Content Type */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
/* Let's give the Request Url to Curl */
curl_setopt($ch, CURLOPT_URL, $request_url);
/* Allows Curl to connect to an API server through HTTPS */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
d($request_parameters,$request_url);
/* Let's get the Response ! */
$response = curl_exec($ch);
$response_info = curl_getinfo($ch);
/* Don't forget to close Curl */
curl_close($ch);
Related
I am working on Zoho Projects API. I have got an API key when sending an HTTP post. While sending the post request I am getting an error.
API CALL CODE
$request_url ='https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/'.$proj_id.'/bugs/?';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$request_parameters = array(
'authtoken' => 'token',
'title' =>'Meter No '.$msn.'_'.$issue_name,
'assignee'=>$assigne_name,
'flag'=>'Internal',
'classification_id'=> $class_id,
'module_id'=>$module_id,
'severity_id'=>$sevr_id,
'CHAR2'=>$ref_no,
'LONG1'=>$msn,
);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));
/* Here you can set the Response Content Type */
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
/* Let's give the Request Url to Curl */
curl_setopt($ch, CURLOPT_URL, $request_url);
/*
Yes we want to get the Response Header
(it will be mixed with the response body but we'll separate that after)
*/
curl_setopt($ch, CURLOPT_HEADER, TRUE);
/* Allows Curl to connect to an API server through HTTPS */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
/* Let's get the Response ! */
$response = curl_exec($ch);
/* We need to get Curl infos for the http_code */
$response_info = curl_getinfo($ch);
/* Don't forget to close Curl */
curl_close($ch);
/* Here we get the Response Body */
$response_body = substr($response, $response_info['header_size']);
// Response HTTP Status Code
echo "Response HTTP Status Code : ";
echo $response_info['http_code'];
echo "\n";
// Response Body
echo "Response Body : ";
echo $response_body;
The response I am getting is
Response HTTP Status Code : 400
Response Body : {"error":{"code":6500,"message":"General Error"}}
A solution is mentioned here. But it's not helping me anymore.
Zoho its self is providing a PHP Example that I am using.
Update 1
Ok, I added $request_url .= '?' . http_build_query($request_parameters); after curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request_parameters));
and then again checked the response. The URL is below
https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/[PROJECTID]/bugs/?authtoken=key&title=Meter+No+002999000368_Site+Comm+Issue&assignee=Laar+Circle&flag=Internal&classification_id=1139168000000297069&module_id=1139168000000019372&severity_id=1139168000000007003&CHAR1=farhan_javaid&CHAR2=20372210038297U&LONG1=002999000368
There is + Sign in between the spaces which is causing a problem. There should be empty spaces in between the words. Like Meter+No+002999000368_Site+Comm+Issue should be Meter No 002999000368_Site Comm Issue.
How to get rid of this error. Any help would be highly appreciated.
If the above code is what you exactly used then you might have to change the [PORTALID] in the $request_url to the actual portal id that you have assigned,
$request_url ='https://projectsapi.zoho.com/restapi/portal/[PORTALID]/projects/'.$proj_id.'/bugs/?';
see here how to get the portal_id.
EDIT
As you are having the problem due to the encoding of the spaces into + which is due to the encoding used by http_build_query(), you can use urlencode() for the title inside the $request_parameters so that it uses %20 instead of + although the rules say that
You should have %20 before the ? and + after.
otherwise, you might have to remove the spaces from the 'title' =>urlencode('Meter No '.$msn.'_'.$issue_name), if the API does not allow you anyhow
$request_parameters = array(
'authtoken' => 'token',
'title' =>urlencode('Meter No '.$msn.'_'.$issue_name),
'assignee'=>$assigne_name,
'flag'=>'Internal',
'classification_id'=> $class_id,
'module_id'=>$module_id,
'severity_id'=>$sevr_id,
'CHAR2'=>$ref_no,
'LONG1'=>$msn,
);
I am trying to the Instagram PHP API to get friends photos. I registered as a sandbox user as well as a dummy user with few random images posted.Then, I invited the dummy user to grant the app in sandbox to connect his account.
To get access token I send a request to get code and then get access token with scope:
https://api.instagram.com/oauth/access_token?client_id=CLIENT_ID&client_secret=SECRET_STRING&grant_type=authorization_code&redirect_uri=http://localhost/&code=CODE&scope=basic+public_content+comments+likes`
PHP code:
$url = 'https://api.instagram.com/oauth/access_token';
$payload = [
$GLOBALS['KEY_CID'] => $GLOBALS['VAL_CID'],
$GLOBALS['KEY_CECRET'] => $GLOBALS['VAL_CECRET'],
'grant_type' => 'authorization_code',
'redirect_uri' => 'http://localhost/',
'code' => $param_code,
'scope' => 'basic+public_content+comments+likes'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); // url
curl_setopt($ch, CURLOPT_POST, true); // POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); // POST DATA
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN RESULT true
curl_setopt($ch, CURLOPT_HEADER, 0); // RETURN HEADER false
curl_setopt($ch, CURLOPT_NOBODY, 0); // NO RETURN BODY false / we need the body to return
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // VERIFY SSL HOST false
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // VERIFY SSL PEER false
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
After I got access token successfully.
I try to get images from a sandbox user which is a dummy account I created for testing:
https://api.instagram.com/v1/users/fane.leee/media/recent?access_token=ACCESS_TOKEN
PHP code for retrieving image:
$url = 'https://api.instagram.com/v1/users/fane.leee/media/recent?access_token='.$ACCESS_TOKEN;
$ch = curl_init(); // initializing
curl_setopt( $ch, CURLOPT_URL, $url ); // API URL to connect
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return the result, do not print
curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
$response = json_decode(curl_exec($ch), true); // connect and get json data
curl_close($ch);
The problem
The $response of the get image request is NULL without error message. Anyone got any ideas about the problem?
Thanks.
Reference
Instagram development doc authentication and authorization.
Instagram development doc about user endpoints
Another StackOverflow post about Instagram web API
Development environment:
Ubuntu 16.04
Apache2
PHP 7.0.8
MySQL 14.14
Edit 1: Add the PHP code calling cUrl functions.
Edit 2: If I replace the user id 'fane.leee' by using 'self', I am able to retrieve the images I posted. I also followed the user 'fane.leee'. Any else I should do to retrieve the friends' media?
The fane.leee is a username. Instagram requires a user id in the API caller.
To get a user id by calling a instagram API function, we could use
https://www.instagram.com/{username}/?__a=1
Another way to get the user id is to use a 3rd party website. It is able to retrieve an Instagram user id from a username. It is here
Reference:
An answer from Thinh Vu in this thread - Not the accepted answer, but the answer underneath. P.S the accepted answer is not working anymore.
I have an API in postman. I want to create a CURL Request and get proper response with it. This is my POSTMAN API.
I am successfully getting this response with it.
"{\"Request\":{\"state\":\"Manama\",\"address\":\"406 Falcon Tower\",\"address2\":\"Diplomatic Area\",\"city\":\"Manama\",\"country\":\"BH\",\"fullname\":\"Dawar Khan\",\"postal\":\"317\"},\"Response\":{\"status\":\"Success\",\"code\":100,\"message\":\"Address is verified\"}}"
Now I want to use this API Call inside my PHP Code. I used this code.
$data = array(
'Request' => 'ValidateAddress',
'address' => test_input($form_data->address),
'secondAddress' => test_input($form_data->secondAddress),
'city' => test_input($form_data->city),
'country' => test_input($form_data->country),
'name' => test_input($form_data->name),
'zipCode' => test_input($form_data->zipCode),
'merchant_id' => 'shipm8',
'hash' => '09335f393d4155d9334ed61385712999'
);
$data_string = json_encode($data);
$url = 'myurl.com/';
$ch = curl_init($url);
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))
);
$result = curl_exec($ch);
curl_close($ch);
$json_result = json_decode($result, true);
echo '<pre>';print_r($json_result);echo '</pre>';
But I can't see my $json_result. It just echoes <pre></pre> in the view. Can anyone guide me? Thanks in advance. I want to get my Response.
UPDATE
I used curl_error and it gives me the following error.
Curl error: SSL certificate problem: self signed certificate in certificate chain
It is Very Simple Just Click on Code you will get the code in php.
you will get the code in many language like php,java,ruby,javascript,nodejs,shell,swift,pythom,C# etc.
Answer updated as per updated question.
There are two ways to solve this issue
Lengthy, time-consuming yet clean
Visit URL in web browser.
Open Security details.
Export certificate.
Change cURL options accordingly.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/CAcerts/BuiltinObjectToken-EquifaxSecureCA.crt");
Quick but dirty
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
We are configuring cURL to accept any server(peer) certificate. This isn’t optimal from a security point of view.
Excerpt from very detailed and precise article with screenshots for better understanding. Kindly refer the same before actually implementing it in production site.
I have to implement form on a webpage, that sends data to Microsoft Dynamics CRM when submited. The data needs to be saved to a certain lead.
I have created simple PHP script that uses curl to communicate with CRM server but I always get 401 status code that indicates authorization has failed.
define('MS_CRM_URL', 'https://______.crm.dynamics.com/');
define('MS_CRM_USER', 'user#domain.com');
define('MS_CRM_PASS', 'password');
$method = '/api/data/v8.0/accounts?$select=name&$top=3';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, MS_CRM_URL . $method);
curl_setopt($ch, CURLOPT_USERPWD, MS_CRM_USER .':'. MS_CRM_PASS);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept' => 'application/json',
'OData-MaxVersion' => '4.0',
'OData-Version' => '4.0',
'Content-Type' => 'application/json',
));
$server_output = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$json = array();
if ((int)$status_code === 200) {
$json = json_decode($server_output);
}
echo '<pre>';
var_dump($status_code);
var_dump($json);
echo '</pre>';
The $method var contents are taken from an example that I've found somewhere on Microsoft documentation site. The documentation was not very helpful to me.
Have you seen this yet? http://jlattimer.blogspot.com/2015/02/soap-only-authentication-using-php.html
Also, it looks like there's an ADAL library for PHP. https://github.com/jamesmcq/azure-activedirectory-library-for-php You should be able to authenticate using that.
You can do it using SOAP Authentication. I have same requirement where we need to send data to Dynamics 365 online from PHP website. I have achieved it using source code from below link :
https://bitbucket.org/nigelheap/msdynamicsphp-master
We're updating our Mailchimp implementation from 1.3 to 3.0. We succesfully updated our code to subscribe someone to a list. Now we're trying to add an ecommerce order. In API v1.3 we did this with the function campaignEcommOrderAdd. I found the function to this with in v3.0: /ecommerce/stores/{store_id}/orders(website link).
But I can't get it to work. When posting to Mailchimp I get an 404 error, but I don't know what I'm doing wrong. Below is my code.
$apiKey = "xxx"; //xxx for privacy reasons
$json = json_encode(array(
'id' => $mailchimp_order['id'],
'customer' => array(
'id' => $mailchimp_order['email_id'],
),
'campaign_id' => $mailchimp_order['campaign_id'],
'currency_code' => "EUR",
'order_total' => $mailchimp_order['total'],
'tax_total' => $mailchimp_order['tax'],
'lines' => $mailchimp_order['items'],
));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/ecommerce/stores/'.$mailchimp_order['store_id'].'/orders';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
This is the output of my $json var:
{
"id":"10000003",
"customer":{
"id":"a90f52f710"
},
"campaign_id":"641657",
"currency_code":"EUR",
"order_total":"56.90",
"tax_total":"47.02",
"lines":[
{
"id":"224",
"product_id":"4427",
"product_title":"Product name",
"product_variant_id":0,
"quantity":"1",
"price":"49.95"
}
]
}
And this is the error I get:
object(stdClass) {
type => 'http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/'
title => 'Resource Not Found'
status => (int) 404
detail => 'The requested resource could not be found.'
instance => ''
}
Without knowing more I would try a few things here. One (you may have already tried this, but check the output of $url) to make sure that all that is getting set correctly. Secondly I would make sure that the store instance you are posting this order to is reachable/exists by making a GET request to, what would be:
$url = 'https://'.$dataCenter.'.api.mailchimp.com/3.0/ecommerce/stores/'.$mailchimp_order['store_id']'
Lastly I would verify that both the campaign and product instances associated with the order are reachable using:
GET https://{dc}.api.mailchimp.com/3.0/campaigns/641657
GET https://{dc}.api.mailchimp.com/3.0/ecommerce/stores/{store_id}/products/4427
Also if you are doing a lot of updating to 3.0 for your app it might be useful to implement a library that abstracts out a lot of this code I use this one:
https://github.com/Jhut89/Mailchimp-API-3.0-PHP
My reputation score wont let me post more links to those endpoints but they should be easily found in the MailChimp documentation. Hope that helps out.