0

I m try to update some data on mongodb using cms api

on terminal i can update information like this

curl -X PUT -d name=12345a https://api1.MYWEBISITE.com/api/v1in/user/2039/?t=mytoken

now using PHP i have try so many ways and no one looks to work for me

tried like this

class Curl {
public function put($url, $data_string){

    $ch = curl_init($url);                                                                      
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); 
    curl_setopt($ch, CURLOPT_FAILONERROR, true);                                                                    
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string))                                                                       
    );                                                                                                                   

    $result = curl_exec($ch);
    return $result;
}


}

$curl = new Curl;

$data_string = '{"name" : "name123"}';

$url = "https://api1.MYWEBSITE.com/api/v1in/user/2039/?t=mytoken";

echo $curl->put($url, $data_string);

also i tried like this

$data = array( "name"   =>  '12344');

$url = "https://api1.mywebsite.com/api/v1in/user/2039/?t=mytoken";
$curl = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$result     = curl_exec($curl);
$response   = json_decode($result);
var_dump($response);
curl_close($curl);

both php solutions dont works, nothing is updated, no error msg is showing

any help?

Alvaro Louzada
  • 433
  • 1
  • 6
  • 23

0 Answers0