Sample Bulk PHP – CURL

Image Description
//API Url
$url = '';

//Initiate cURL.
$ch = curl_init($url);

//The JSON data.
$jsonData = array(
   'action' => "bulk_put",
   'user' => "xxxx",
   'password' => "xxxxx",
    'msg'=>"Test Message",


//Encode the array into JSON.

try {
    $jsonDataEncoded = json_encode($jsonData);
catch(Exception $e) {
    echo 'Message:1 ' .$e->getMessage();

try {
    curl_setopt($ch, CURLOPT_POST, 1);
    //Tell cURL that we want to send a POST request.
 catch(Exception $e) {
     echo 'Message:2 ' .$e->getMessage();

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

}catch(Exception $e){
    echo 'Message:3 ' .$e->getMessage();


//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 

}catch(Exception $e){
    echo 'Message:4 ' .$e->getMessage();

echo " Input Json:<br>";
echo $jsonDataEncoded;
echo "<br>";
echo "<br>Response:<br>";
//Execute the request
$result = curl_exec($ch);

Was this article helpful to you?

Yes No

Related Articles