can anyone help with an API
I having an API that should get parameters in
https://app.wappapi.in/api/send.php?number=9198480xxxxx&type=text&message=test-message&instance_id=609ACF283XXXX&access_token=e10adcxxxxba59axxx56e0xxxxxxxxxx
in post method
the question is if I send it like using this god will it get it like needed?
<?php
$curl = curl_init();
$number=$_POST['type'];
$message=$_POST['type'];
$id=$_POST['type'];
$token=$_POST['type'];
curl_setopt_array($curl, array(
CURLOPT_URL => "https://app.wappapi.in/api/send.php",
CURLOPT_POSTFIELDS => "number={$number}type=text&message={$message}&instance_id={$id}&access_token={$token}",
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST"));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
Don't use CURLOPT_POSTFIELDS, because the query parameters come with the URI
Instead:
CURLOPT_URL => "https://app.wappapi.in/api/send.php?number={$number}"
."&type=text&message={$message}&instance_id={$id}&access_token={$token}",
CURLOPT_POST => 1
Hope it solved your problem.
I have this function to send message
Code:
public static function send($mobile,$otp,$country_code){
$message = "Your 2-way authentication OTP is $otp";
$curl = curl_init();
$authKey = App::environment('MSGAUTH');
$senderId = App::environment('SENDERID');
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.XXX.com/api/sendhttp.php?authkey=".$authKey."&mobiles=".$mobile."&country=$country_code&sender=".$senderId."&route=3&message=$message",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => array(
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return false;
} else {
return true;
}
}
Issue is i'm getting blank quotes in the error part and this code is working on my local system but on server control is going in the else part. When i print $err i get this output
Any solution to resolve this issue.
Thanks
Hi guys Please someone to help me fix an issue with an sms API. Here is the entire code given by the sms API provider:
I don't know what is wrong and I don't know how to fix the 415 issue. The API provider doens't give coding support
/*
*:: How to generate Token in PHP using our Restful API
*/
"https://restapi.bulksmsonline.com/rest/api/v1/sms/gettoken/username/MYUSERNAME/password/MYPASSWORD",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
/*
*::: How to send sms with your generated Token
*/
"https://restapi.bulksmsonline.com/rest/api/sms/send",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"from\":\"Sender Name\",\"to\":[\"16813000014\",\"16813000014\"],\"type\":\"Text\",\"content\":\"Sample SMS Content To Be Sent\"}",
CURLOPT_HTTPHEADER => array(
"token : USER TOKEN GENERATED FROM GET TOKEN API",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
And here is the code I developped:
$curl=curl_init("https://restapi.bulksmsonline.com/rest/api/v1/sms/gettoken/username/xxxxx/password/xxxxx");
curl_setopt_array($curl,[
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
$ch = curl_init("https://restapi.bulksmsonline.com/rest/api/v1/sms/send");
$field = array('from'=>'From me', 'to'=>'237668426982', 'type'=>'Text', 'content'=>'message');
$head = array('token'=>'$response', 'content-type'=>'application/json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING,"" );
curl_setopt($ch, CURLOPT_MAXREDIRS,10 );
curl_setopt($ch, CURLOPT_TIMEOUT,30 );
curl_setopt($ch, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST,'POST' );
curl_setopt($ch, CURLOPT_POSTFIELDS,$field );
curl_setopt($ch, CURLOPT_HTTPHEADER,$head );
$output = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $output;
}
Here is the response displayed:
{"type":"https://tools.ietf.org/html/rfc7231#section-6.5.13","title":"Unsupported Media Type","status":415,"traceId":"|54541add-41130078fe10574f."}
Please help me to fix that.
Thks
Change your post fields and headers as per the API provider's sample. The post fields should be JSON string, not an array. The headers array is not an associative array, it is an array of strings.
$headers = ["token: {$response}", "content-type: application/json"];
$fields = ['from' => 'From me', 'to' => ['237668426982'], 'type' => 'Text', 'content' => 'message'];
$postFields = json_encode($fields);
And then use them for the cURL request,
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
On another note, in your code, you have this 'token'=>'$response', a PHP variable inside single quotes; this will not work. If the variable has a string literal, then you do not need the quotes at all. If you have to use quotes, then use variables inside double quotes.
I hope this helps.
I am making a request for api chart to be automatically redirected, without password, after redirection, receive the following alert:
SCRIPT
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => "3000",
CURLOPT_URL => "http://localhost:3000/d/BSFmuV5Zz/dash?orgId=1",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Authorization: Bearer api-key-here"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "CURL Error #:" . $err; ?>
<?php } else {
echo $response;
}
?>
Operating System: Windows
Download Link: https://grafana.com/grafana/download?platform=windows
When I make a request with cURL gives error "cannot resolve host URL". Should I encode URL? After I encoded Google API URL, it still gives error.
https://developers.google.com/people/api/rest/v1/contactGroups/batchGet
GET https://people.googleapis.com/v1/contactGroups:batchGet
Where is the problem?
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://people.googleapis.com/v1/contactGroups:batchGet",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"Cache-Control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
I don't see anything wrong with the code, and I tested it and it worked fine.
I guess it's some issue with the DNS that can't resolve the host.