I'm getting this error using Amazon Advertising API while trying to create new keywords:
"code":"422"
This is my PHP Code:
curl_setopt($ch, CURLOPT_URL, $std_url . "/v2/sp/keywords");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data_string = array(
"campaignId" => "111111111111",
"adGroupId" => "2222222222222",
"state" => "enabled",
"keywordText" => "YetAnotherKeyword",
"matchType" => "broad",
"bid" => "0.05");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$headers = array();
$headers[] = "Content-Type:application/json";
$headers[] = ("Authorization: Bearer " . $accesstoken);
$headers[] = ("Amazon-Advertising-API-ClientId: ". $client);
$headers[] = ("Amazon-Advertising-API-Scope: " . $API_Scope);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
echo $result;
I've got the solution. The array needs to be modified like this:
$data_string = array(array(
"campaignId" => "111111111111",
"adGroupId" => "2222222222222",
"state" => "enabled",
"keywordText" => "YetAnotherKeyword",
"matchType" => "broad",
"bid" => "0.05"));
Related
UPDATE*
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_ENV["https://cf6307f08afef7f0f9f449a55c6fd79b#api.dialmycalls.com/2.0/service/text"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = array (
'name' => 'Dorothy',
'keyword_id' => '351aa984-9a7b-11e8-a4d5-0cc47ab3cb58',
'messages' => 'test123456',
array ("contacts" => array(
array(
"phone" => "12294622255"
))));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
I am still getting
`Error: malformed`
So maybe a little more information about the json construction might help
These are the required fields
name - > name of broadcast
keyword_id - > 351aa984-9a7b-11e8-a4d5-0cc47ab3cb58
messages - > list format but only sending single message "test123456"
contacts - > List format with substring of phone: then number 1234567891
ORIGINAL QUESTION
So i am trying to setup a php page with DialMyCall's API just to sent text with the variables
$numbers (Command Delimited)
$message (message of SMS)
The example that DialMyCode gives is
curl -i -H "Content-Type: application/json" -X POST -d "{\"keyword_id\": \"dfe49537-a0a8-4f4a-98a1-e03df388af11\", \"send_immediately\": true,\"messages\": [\"Testing testing\"], \"contacts\": [{\"phone\":\"1116551235\"},{\"phone\":\"1116551234\"}]}" https://$API_KEY#api.dialmycalls.com/2.0/service/text
I have tried to convert this into php but i cannot get it to work
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_ENV["https://APIKEY#api.dialmycalls.com/2.0/service/text"]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array (
'name' => 'Dorothy',
'keyword_id' => '351aa984-9a7b-11e8-a4d5-0cc47ab3cb58',
'message' => 'test123456',
'contacts' => 'phone: 1234567891',
));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
?>
Error recieved
Error: malformed
What i should get is a success message in JSON and a text message sent.
You need to send your data as a JSON string. When you pass an array to CURLOPT_POSTFIELDS, it formats/passes it like form data. Here, you want to pass a json object as the body, so use something like this below:
$data = array (
'name' => 'Dorothy',
'keyword_id' => '351aa984-9a7b-11e8-a4d5-0cc47ab3cb58',
'messages' => array('test123456'),
'contacts' => array(
array('phone' => '1234567891')
)
);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
I have been trying to get the list of subscribers from drip account. I am trying to do so with the curl php I am unable to do so.
Official example
curl -H 'User-Agent: Your App Name (www.yourapp.com)' \
-u f4ff6a200e850131dca1040cce1ee51a: \
-d status=active \
https://api.getdrip.com/v2/9999999/campaigns
My Code
$TOKEN='f69444e104aea5b77a969bb313852dc1';
$ch = curl_init('https://api.getdrip.com/v2/1186104/subscribers');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'TestApp (laflechee#gmail.com)');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $TOKEN
));
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $data;
I am adding a new subscriber in drip with the below code. You can follow it.
$ch = curl_init();
//YOUR-ACCOUNT-ID replace it with your account id
curl_setopt($ch, CURLOPT_URL, 'https://api.getdrip.com/v2/YOUR-ACCOUNT-ID/subscribers');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$data = array(
'subscribers' => array(
array(
'email' => 'myemail#domain.com',
'first_name' => 'Mohsin',
'last_name' => 'raza'
),
),
);
$post = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
//YOUR-API-TOKEN-HERE replace it with your api-token
curl_setopt($ch, CURLOPT_USERPWD, 'YOUR-API-TOKEN-HERE' . ':' . '');
$headers = array();
//replace with your app name and registered domain with drip account
$headers[] = 'User-Agent: YOUR-APP-NAME (www.your-domain.com)';
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
echo $result;
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
My PHP script looks like this:
<?php
$reg_id = "d8Sq53-gteU:APA91bGFcbSrcWY6J9fVBhUJVci4YHgktjoTOTbRjMXi7uY6ss-kLM39GpSt16cMmwsm2k4n9y3_YrcyBT7o9bpsN2QFS_bVceMcV-WThbThXMCWSiwaaP7p5LAJlb_01mzPbHb6xq1X1";
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'to' => $reg_id ,
'priority' => "high",
'data' => array(
"title" => "Android Learning",
"message" => "Test",
"image"=> "dsdsd",
"tag" => "dsdsd"
)
);
$headers = array(
'Authorization:key = AIzaSyC6ld4WBRmk8W6DZgMqevu1Na3dcQdQDBIA ',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
print_r($result);die;
?>
This is the response I am getting:
{"multicast_id":7558168491201020947,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1484883356821016%9bd11ceef9fd7ecd"}]}
But in Android I am unable to get the data that I am posting through the notification. Is there a problem with PHP script that I am using, Is the response that I am getting through PHP script correct. Or there is some problem with the android code. Can anyone help me please.
**Please check below .php file it will working fine for me.**
**You just need to pass firebase id "fcm_token" parameter to this php file**.
<?php
require_once __DIR__ . '/config.php';
// need to pass Firebase Register ID.
$registration_ids=$_POST["fcm_token"];
$title='hello';
$message='Please check the Details';
$is_background=FALSE;
$image='';
$payload='Its Payload';
$timestamp='10:15';
$arr = array('title' => $title, 'is_background' => $is_background, 'message' => $message, 'timestamp' => $timestamp, 'image' => $image,'payload'=> $payload);
$arr1 = array('data' => $arr);
$json = $arr1;
$fields = array('to' => $registration_ids,'data' => $json,);
//echo json_encode($fields);
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=' . FIREBASE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
echo 'its Not done bro';
}else{
echo 'its done bro';
}
// Close connection
curl_close($ch);
?>
Finally got the code which is working for me-
`
$filename = 'Fav_Icon.png';
$title = "thisis title";
$coupon_id = 1;
$url = 'https://fcm.googleapis.com/fcm/send';
$msg = array
(
'message' => 'We have added a new Coupon. Please have a look !!!',
'title' => $title,
'smallIcon' => base_url().'uploads/icons/'.$filename,
'type' => 'Coupon',
'coupon_id' => $coupon_id
);
$res = array();
$res['data']['title'] = "Coupon Name";
$res['data']['message'] = "We have added a new Coupon. Please have a look !!!";
$res['data']['image'] = base_url().'uploads/icons/'.$filename;
$res['data']['tag'] = "Coupon";
$res['data']['coupon_id'] = $coupon_id;
$fields = array(
'to' => $reg_id ,
'priority' => "high",
'data' => $res
);
$headers = array(
'Authorization:key = AIzaSyC6ld4WBRmk8W6DZgMqevu1Na3dcQdQDBIER ',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
print_r($result);
return $result;
?>`
How to update user profile picture in Quickblox using php codeigntier ?
Documentation found at
http://quickblox.com/developers/Users
after found rest api i have found the solution for how to upload profile picture to quickblox user.
there are three 3 steps for uploading content as per quickblox rest api
First you generate token from the quickblox and then perform these 3 steps
Create file
https://quickblox.com/developers/Content#Create_a_file
$strFilename = '2.jpeg';
$post_body = http_build_query(array(
'blob[content_type]' => 'image/jpeg',
'blob[name]' =>$strFilename,
));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, QB_API_ENDPOINT.'blobs.json');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_body);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/x-www-form-urlencoded',
'QuickBlox-REST-API-Version: 0.1.0',
'QB-Token: ' . $token
));
$response = curl_exec($curl);
$error = curl_error($curl);
if ($response) {
return $response;
} else {
return false;
}
curl_close($curl);
After this curl call you have got the response and in response got the response like this
[blob] => Array
(
[id] => 7178102
[uid] => f9cc9d7938c4468f8bdccdcb68fb5d8c00
[content_type] => image/jpeg
[name] => 2.jpeg
[size] =>
[created_at] => 2017-02-07T10:35:38Z
[updated_at] => 2017-02-07T10:35:38Z
[ref_count] => 1
[blob_status] =>
[set_completed_at] =>
[public] => 1
[last_read_access_ts] =>
[lifetime] => 8600
[account_id] => 56721
[app_id] =>
[blob_object_access] => Array
(
[id] => 7178102
[blob_id] => 7178102
[expires] => 2017-02-07T11:35:38Z
[object_access_type] => Write
[params] => https://qbprod.s3.amazonaws.com/?Content-Type=image%2Fjpeg&Expires=Tue%2C%2007%20Feb%202017%2011%3A35%3A38%20GMT&acl=public-read&key=f9cc9d7938c4468f8bdccdcb68fb5d8c00&policy=eyJleHBpcmF0aW9uIjoiMjAxNy0wMi0wN1QxMTozNTozOFoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJxYnByb2QifSx7ImFjbCI6InB1YmxpYy1yZWFkIn0seyJDb250ZW50LVR5cGUiOiJpbWFnZS9qcGVnIn0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7IkV4cGlyZXMiOiJUdWUsIDA3IEZlYiAyMDE3IDExOjM1OjM4IEdNVCJ9LHsia2V5IjoiZjljYzlkNzkzOGM0NDY4ZjhiZGNjZGNiNjhmYjVkOGMwMCJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFJWTdLRk0yM1hHWEo3UjdBLzIwMTcwMjA3L3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE3MDIwN1QxMDM1MzhaIn1dfQ%3D%3D&success_action_status=201&x-amz-algorithm=AWS4-HMAC-SHA256&x-amz-credential=AKIAIY7KFM23XGXJ7R7A%2F20170207%2Fus-east-1%2Fs3%2Faws4_request&x-amz-date=20170207T103538Z&x-amz-signature=5e236c3da60a922951c8ab6281ae82af3a88e37c15d8630ad6ff590610a87fd8
)
)
Upload file
so you have to used the params url parameters and make another call for uploading file
$strFilename = '2.jpeg';
$url = 'https://qbprod.s3.amazonaws.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'Content-Type' => $arr['Content-Type'],
'Expires'=>$arr['Expires'],
'acl'=>$arr['acl'],
'key'=>$arr['key'],
'policy'=>$arr['policy'],
'success_action_status'=>$arr['success_action_status'],
'x-amz-algorithm'=>$arr['x-amz-algorithm'],
'x-amz-credential'=>$arr['x-amz-credential'],
'x-amz-date'=>$arr['x-amz-date'],
'x-amz-signature'=>$arr['x-amz-signature'],
'file' => new CurlFile('2.jpeg', $arr['Content-Type'], $strFilename)
));
$response = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 204) {
echo 'Success!';
} else {
$error = substr($response, strpos($response, '<Code>') + 6);
echo substr($error, 0, strpos($error, '</Code>'));
}
return $response;
so by using this code your content file will be uploaded and you got the location of the file and used as profile picture or etc .
Declare file
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.quickblox.com/blobs/" . $strId . "/complete.xml"); // strId is blod id return by 1 step
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "blob[size]=10000"); //your file size
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
$headers = array();
$headers[] = "Quickblox-Rest-Api-Version: 0.1.0";
$headers[] = "Qb-Token: " . $token;
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $result;
Please let me know the any issue regards the same.
Thanks
Im trying to get this API working in PHP
The API documentation is here
https://studio.azureml.net/apihelp/workspaces/3e1515433b9d477f8bd02b659428cddc/webservices/aca8dc0fd2974e7d849bbac9e7675fda/endpoints/cb1b14b17422435984943d41a5957ec7/score
Im really stuck and im so close to getting it to work. Below is my current code if anyone can spot any errors. I have also included my API key as it will be changed once working.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$url = 'https://ussouthcentral.services.azureml.net/workspaces/3e1515433b9d477f8bd02b659428cddc/services/cb1b14b17422435984943d41a5957ec7/execute?api-version=2.0&details=true';
$api_key = '5ve72/xxLuzaexQu7LyRBl1iRdGqAQiQ1ValodnS7DG+F0NzgHkaLyk1J30MXrlWFovzPzlurui/o5jeH7RMiA==';
$data = array(
'Inputs'=> array(
'input1'=> array(
'ColumnNames' => ['Client_ID'],
'Values' => [ [ '0' ], [ '0' ], ]
),
),
'GlobalParameters' => array()
);
$body = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$api_key, 'Accept: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
echo 'Curl error: ' . curl_error($ch);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
im still getting no error from curl_error and the var dump just says bool(false)
You had an issue with the element GlobalParameters, declare it as a StdClass instead of an empty array. Try this :
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$url = 'https://ussouthcentral.services.azureml.net/workspaces/3e1515433b9d477f8bd02b659428cddc/services/cb1b14b17422435984943d41a5957ec7/execute?api-version=2.0&details=true';
$api_key = '5ve72/xxLuzaexQu7LyRBl1iRdGqAQiQ1ValodnS7DG+F0NzgHkaLyk1J30MXrlWFovzPzlurui/o5jeH7RMiA==';
$data = array(
'Inputs'=> array(
'input1'=> array(
'ColumnNames' => ['Client_ID'],
'Values' => [ [ '0' ], [ '0' ], ]
),
),
'GlobalParameters' => new StdClass(),
);
$body = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$api_key, 'Accept: application/json'));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $body . PHP_EOL . PHP_EOL;
echo 'Curl error: ' . curl_error($ch);
curl_close($ch);
var_dump($response);
You have to run curl_error() after curl_exec() because curl_error() does return a string containing the last error for the current session. (source : php.net)
So go this way
$response = curl_exec($ch);
echo 'Curl error: ' . curl_error($ch);
And you should have a error telling you what is wrong.