I'm trying to call ConvertAPI.com/Word2Pdf, but with no success.
My sample code is:
$fileToConvert = 'test.docx';
$apiKey = *******;
$postdata = array('OutputFileName' => 'test.pdf', 'ApiKey' => $apiKey, 'File' => $fileToConvert);
$ch = curl_init("http://do.convertapi.com/Word2Pdf");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
var_dump($result);
I'm getting as a result something like: "HTTP/1.1 100 Continue HTTP/1.1 400 The 'File' parameter cannot be null. Please set value. Cache-Control: no-cache, no-store Pragma: no-cache Content-Type: text/html..."
What I'm doing wrong here?
Try this using http://unirest.io/php.html library
$response = Unirest::post(
"http://do.convertapi.com/Word2Pdf?ApiKey=<Your api key>",
array(
"File" => "#/tmp/file.path",
"OutputFormat" => "pdf",
)
);
Related
I am trying to use Thycotic PAM API. According to their documentation, The following is a sample HTTP POST request. The placeholders shown need to be replaced with actual values.
POST /SecretServer/webservices/SSWebservice.asmx/GetUser HTTP/1.1
Host: 192.168.3.242
Content-Type: application/x-www-form-urlencoded
Content-Length: length
token=string&userId=string
I can get token string and user ID from the app. With this data, following is the PHP code I am trying
$url = 'https://192.168.3.242/SecretServer/webservices/SSWebservice.asmx/GetUser';
$data = array(
'token' => 'token_string',
'userId' => 8
);
// use key 'http' even if you send the request to https://...
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = json_decode(file_get_contents($url, false, $context));
if ($result === FALSE) { /* Handle error */ }
var_dump($result);
I also tried this way:
function curl_get_contents($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'https://192.168.3.242/SecretServer/webservices/SSWebservice.asmx/GetUser?token=token_string&userId=8 HTTP/1.1';
$json = json_decode(curl_get_contents($url));
var_dump($json);
Both of them are returning nothing. Any suggestion is much appreciated.
curl_setopt($ch ,CURLOPT_POST, 1);
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch ,CURLOPT_POSTFIELDS, "token=string&userId=string");
you must use this parameters
Below is my code to add contact to the mailchimp. I am getting mailchimp api key and list id from the env file in laravel. Also $data involves all the input.
$apiKey = env('MAILCHIMP_APIKEY');
$listId = env('MAILCHIMP_LIST_ID');
$auth = base64_encode( 'user:'.$apiKey);
$mailChimpdata = array(
'apikey' => $apiKey,
'email_address' => $data['email'],
'status' => $data['status'],
'merge_fields' => array(
'FNAME' => $data['firstname'],
'LNAME' => $data['lastname']
)
);
$json_data = json_encode($mailChimpdata);
$ch = curl_init();
$memberId = md5(strtolower($data['email']));
$url = 'https://us19.admin.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
But I am getting this below error
HTTP/1.0 501 Not Implemented
Server: AkamaiGHost
Mime-Version: 1.0
Content-Type: text/html
Content-Length: 334
Expires: Wed, 07 Apr 2021 08:49:45 GMT
Date: Wed, 07 Apr 2021 08:49:45 GMT
Connection: close
Set-Cookie: _abck=471ED28A26F6757CE57AC9E4318E7BD6~-1~YAAQHdcLF/keKqt4AQAASPOFqwWS/EeAKXso+2igviRTfIMw3pqbDMndhfZPfoX+eQn3Iv8iqfbogtNFmkU4lRDRQLdAWAYBhq2oOhDTiK ▶
Set-Cookie: bm_sz=5CBD698E96AC9E2B62898990FF45E196~YAAQHdcLF/oeKqt4AQAASPOFqwsLVm8fKmxtToeWU99vCUWske+XMuRtEjiCpzXhPE5xe8jGoh6EfYe8WG6zjMaaI2jPZos0gb2ER9jykveOE ▶
<HTML><HEAD>
<TITLE>Unsupported Request</TITLE>
</HEAD><BODY>
<H1>Unsupported Request</H1>
PUT to http://us19.admin.mailchimp.com/3.0/lists/applevendor/members/b642b4217b34b1e8d3bd915fc65c4452 not supported.<P>
Reference #8.1dd70b17.1617785385.68d39e
</BODY></HTML>
Please help me out to resolve this issue.
Based on Mailchimp documentation they use URL to add contact
"https://us20.api.mailchimp.com/3.0/lists/$list_id/members/"
but you have
"https://us19.admin.mailchimp.com/3.0/lists/$listId/members/$memberId"
with $memberId. I guess that id is their internal identificator.
I don't know if this topic is still relevant but here is my method using php / Guzzle:
$client = new Client();
$client->request('PUT', 'https://us9.api.mailchimp.com/3.0/lists/{list_id}/members/{subscriber_hash},
[
'json' => [
'email_address' => $email,
'status_if_new' => "unsubscribed",
],
'headers' => [
"Authorization" => "Basic YOUR_API_KEY"
]
]);
subscriber_hash => hash MD5
I did exactly as shown in the API documentation
http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingList
but when i call it returns this error
HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: application/json Date: Sat, 04 Jun 2016 06:23:48 GMT Connection: close Content-Length: 2 {}
and here is my code in PHP
<?
$url = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/';
$data = array('apiKey' => 'de995438234178656329029769192274', 'country' => 'BR', 'currency' => 'BRL',
'locale' => 'pt-BR', 'originplace' => 'SDU-iata', 'destinationplace' => 'GRU-iata', 'outbounddate' => '2016-09-23',
$headers = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
printf($result);
?>
any idea what is going wrong?
thanks in advance for any kind
So I think the PHP is sending the wrong request type, because the HTTP headers were being sent as an array (so defaults to 'multipart/formdata'). If you use http_build_query on that array, it is sent correctly as 'x-www-form-urlencoded'.
I've tidied things up, removed some duplication in the curl options, and correctly get a 201 response on your example now:
<?
$url = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/';
$data = array('apiKey' => 'de995438234178656329029769192274', 'country' => 'BR', 'currency' => 'BRL',
'locale' => 'pt-BR', 'originplace' => 'SDU', 'destinationplace' => 'GRU', 'outbounddate' => '2016-09-23', 'locationschema' => 'Iata', 'adults' => 1);
$httpdata = http_build_query($data);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpdata);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>
Hope that helps, I'll keep an eye on the thread in case of anything else - feel free to drop us a query or check the FAQs here: https://support.business.skyscanner.net/hc/en-us
I have tested the codes from this and this
but it doesn't work.
The event is created successfully but the image is not published.
Here is my actual code:
require_once '../admini/config.php';
$t = getToken('appID', 'appSecret');
$file = 'Koala.jpg';
$arrData = array(
'name' => 'Test Event',
'start_time' => '2015-07-04', //ISO-8601 format - With Time - 2012-07-04T19:00:00-0700
//'end_time' => '', //optional
'description' => 'Das erste Test-Event',
'location' => 'Deggendorf', //Just a name
'location_id' => '103091806397289', //place id - inserts a link to place fb page
'ticket_url' => 'url', //URL to buy a ticket for the event
'no_feed_story' => FALSE, //TRUE = dont display on page
'access_token' => 'token',
'picture' => '#'. realpath($file),
);
$createUrl = 'https://graph.facebook.com/page_id/events';
$test = fbcurl($createUrl, 'POST', $arrData); //Returns the event id
echo '<pre>';
print_r($test);
echo '</pre>';
function fbcurl($url, $method, $fields = array(), $auth = array()){
foreach($fields as $key => $value){
if(!is_string($value)){
$fields[$key] = json_encode($value);
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data'));
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
// if(count($auth)===2)
// curl_setopt($ch, CURLOPT_USERPWD, $auth['user'].':'.$auth['pass']);
// }
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if(count($fields)>0){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields, null, '&'));
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//curl_setopt($ch, CURLOPT_TIMEOUT, 60);
//curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php-3.2');
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Content-Type: multipart/form-data");
//file_put_contents('fbcurllocal.txt', print_r(http_build_query($fields, null, '&'), true)."\n".$url);
$r = curl_exec($ch);
curl_close($ch);
if($r!=''){
$p = explode("\r\n\r\nHTTP/", $r);
$p = (count($p) > 1 ? 'HTTP/' : '') . array_pop($p);
list($h, $b) = explode("\r\n\r\n", $p, 2);
return array('header' => $h, 'body' => $b);
}else{
return array('header' => '', 'body' => 'error');
}
}
If you read the documentation, ther's no such field picture with \POST /{page-id}/events.
So, while creating an event you can not publish a cover picture along with it. So it's a two-step procedure-
Create event
API: \POST /{page-id}/events - Reference
This you've already done, just delete the picture parameter from there.
Upload cover picture
API: \POST /{event-id}/events - Reference
Give the image to the parameter: source
This way you can upload the cover pic to an event. Hope that helps.
Edit
The method to upload cover photo that I've mentioned will not work as of now (you can subscribe to this bug to get the update), instead you'll be needing a link to the image and make the call-
\POST /{event-id}
Parameter: cover_url
This works. I've tested!
look at the commtens before to understand it.
'asdf' => '#'. realpath($file).';type=image/jpeg',
(
[header] => HTTP/1.1 200 OK
x-fb-rev: 1200162
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: application/json; charset=UTF-8
Date: Thu, 10 Apr 2014 14:26:20 GMT
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Debug: nLKpXn4cbeF4AMa8kiOVMAfcKG5EFvQZmqvxFJXYC88=
Connection: keep-alive
Content-Length: 4
[body] => true
)
i tested this
'source' => '#'. realpath($file).';type=image/jpeg',
and this
'source' => '#'. realpath($file),
bevore
I need to read the size of a file but the server is forcing me to download it first.
I note one of the response headers is Content-Type: application/force-download and that seems to bypass my curl inputs...
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch,CURLOPT_TIMEOUT,1000);
curl_exec($ch);
$bytes = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
curl_close($ch);
Any ideas?
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
These two lines reset CURLOPT_NOBODY.
CURLOPT_NOBODY changes method to HEAD and CURLOPT_POST changes it to POST.
Source: http://php.net/manual/en/function.curl-setopt.php
Curl conforms with the force-download header, but file_get_contents can be used to limit the file download download to only 1 byte. This solved the problem!
$postdata = http_build_query(
array(
'username' => "",
'password' => ""
)
);
$params = array(
'http' => array
(
'method' => 'POST',
'header'=>"Content-type: application/x-www-form-urlencoded\r\n",
'content' => $postdata
)
);
$ctx = stream_context_create($params);
file_get_contents($url,false,$ctx,0,1);
$size = str_replace("Content-Length: ","",$http_response_header[4]);