<?php
$url = "https://www.example.com";
$data = array(
"email" => "vicky#gg.com",
"firstname" => "firstname",
"lastname" => "lastname",
"password1" => "123456",
"password2" => "123456",
"key" => "d12121c70dda5edfgd1df6633fdb3"
);
$data_string = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
$output = json_decode($result,true);
curl_close($ch);
echo $output;
?>
Use
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
to disable SSL check.
Related
I would like to send a message with the chatwoot api.
https://www.chatwoot.com/developers/api/#tag/Messages/operation/create-a-new-message-in-a-conversation
I tried this code:
<?php
$ch = curl_init("https://mydomain.de/api/v1/accounts/1/conversations/100/messages");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(
array(
"content" => "string",
"message_type" => "outgoing",
"private" => true,
"content_type" => "cards"
)
));
curl_setopt($ch, CURLOPT_HTTPHEADER,
array (
'api_access_token: XXX'
),
);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
echo '<pre>';
print_r($response);
echo '</pre>';
?>
Response:
Array
(
[errors] => Array
(
[0] => You must log in or register before you can proceed.
)
)
Any idea?
Good day! I'm trying to load an image using the method appWidgets.saveAppImage. In the beginning I receive URL the server for loading -> getAppImageUploadServer, there all ok!
I receive a hash and an image, send them a POST request and get an error. Here is my code:
$token = "Service_access_key";
$tmp_image = file_get_contents('https://www.ejin.ru/wp-content/uploads/2017/12/667108931864_667108931864-150x150.jpg');
file_put_contents(dirname(__FILE__).'/tmp.jpg',$tmp_image);
$img_path = dirname(__FILE__).'/tmp.jpg';
$post_data = array("image" => "#".$img_path);
$upload_url = file_get_contents("https://api.vk.com/method/appWidgets.getAppImageUploadServer?v=5.85&image_type=50x50&access_token=".$token);
$url = json_decode($upload_url)->response->upload_url;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$result = json_decode(curl_exec($ch),true);
$safe = file_get_contents("https://api.vk.com/method/appWidgets.saveAppImage?v=5.85&hash=".$result['hash']."&image=".$result['image']."&access_token=".$token);
echo $safe;
echo:
"error_code":129,"error_msg":"Invalid photo: file not found, from upl_850128?act=app_widget_image"
what's my mistake?
<?
$request_params = array(
'image_type' => '510x128',
'access_token' => 'xxx',
'v' => '5.92'
);
$t = json_decode(file_get_contents('https://api.vk.com/method/appWidgets.getAppImageUploadServer?'. http_build_query($request_params)));
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $t->response->upload_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("image" => new CURLFile(dirname(__FILE__).'\img.jpg')));
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
$result = json_decode(curl_exec($ch));
curl_close($ch);
$request_params = array(
'hash' => $result->hash,
'image' => $result->image,
'access_token' => 'xxx',
'v' => '5.92'
);
print_r(file_get_contents('https://api.vk.com/method/appWidgets.saveAppImage?'. http_build_query($request_params)));
?>
All,
I'm trying to do a simple "post" to Mailchimp using the 3.0 API; however I'm just getting a bool(false) response from the below code. I know the MAILCHIMP_API_KEY and LIST_ID variables are correct... Help?
All I want to do is add an email & first name to a specific list.
$auth = base64_encode( 'user:'.MAILCHIMP_API_KEY);
$data = array(
'apikey' => MAILCHIMP_API_KEY,
'email' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $name
)
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.NEW_LIST_ID.'/members/');
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_POSTFIELDS, $json_data);
$result = curl_exec($ch);
var_dump($result);
die('<br /><br />Mailchimp executed');
Just missed the dot after $server in the URL, and also should be email_address rather than email. But below is a working example if anyone needs it:
$auth = base64_encode( 'user:'.MAILCHIMP_API_KEY);
$data = array(
'apikey' => MAILCHIMP_API_KEY,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $name
)
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'.api.mailchimp.com/3.0/lists/'.NEW_LIST_ID.'/members');
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_POSTFIELDS, $json_data);
$result = curl_exec($ch);
die('<br /><br />Mailchimp executed');
i want to pass parameter for using web services. how can i pass this. i have passed like this. is this correct...?
$TemplateId = $_POST["template_id"];
$MetafamilyId = $_POST["metafamily_id"];
$MatchType = $_POST["match_type_name"];
$name = trim($_POST["name"]);
$password = md5(trim($_POST["password"]));
$data = array("TemplateId" => $TemplateId,
"MetafamilyId" => $MetafamilyId,
"MatchType" => $MatchType,
"name" => $name,
"password" => $password );
$postData= json_encode($data);
$url="http://google.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST,count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
$getdata=curl_exec($ch);
echo $getdata;
curl_close($ch);
i have problem with this website api,
i used this code to generate a shorturl by this api but always i got a White Page Screen without any content!
Please Help me to generate a url:
<?php
function bucksapi($longUrl)
{
$bucksapi = 'myapipass';
$sinoone = 'myusername';
$adts = '2';
$contype = '1';
$domainss = 'linkbucks.com';
$postData = array('originalLink' => $longUrl, 'user' => $sinoone, 'apiPassword' => $bucksapi, 'contentType' => $contype, 'adType' => $adts, 'domain' => $domainss);
$jsonData = json_encode($postData);
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, 'https://www.linkbucks.com/api/createLink/single');
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
//As the API is on https, set the value for CURLOPT_SSL_VERIFYPEER to false. This will stop cURL from verifying the SSL certificate.
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curlObj, CURLOPT_HEADER, 0);
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
curl_setopt($curlObj, CURLOPT_POST, 1);
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
$response = curl_exec($curlObj);
$json = json_decode($response);
curl_close($curlObj);
return $json->link;
}
?>
and this for printing the short link:
<?php
$long_url = "http://google.com";
echo bucksapi($long_url);
?>
Based on your work.
<?php
function curl($url, $cookies= NULL, $post = NULL)
{
$ch = #curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
if (!empty($cookies)) {
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if (!empty($post)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 25);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 25);
$page = curl_exec($ch);
var_dump($page);
curl_close($ch);
return $page;
}
function bucksapi($longUrl, $bucksapi, $sinoone, $adts = '2', $contype = '1')
{
$postData = array(
'originalLink' => $longUrl,
'user' => $sinoone,
'apiPassword' => $bucksapi,
'contentType' => $contype,
'adType' => $adts,
'domain' => 'linkbucks.com'
);
$json = json_decode(
curl(
'https://www.linkbucks.com/api/createLink/single',
NULL,
json_encode($postData)
)
);
var_dump($json);
return $json->link;
}
var_dump( bucksapi( "LINK_URL", 'API_KEY', 'USER_NAME' ) );
?>