• Resolved ninievy

    (@ninievy)


    Hi Dominik,

    Thanks a lot for your great plugin!

    I achieve to get a result with postman, but when I do it from curl with php, I get this error:

    {“code”:”no_email”,”message”:”You must provide an email address.”,”data”:{“status”:400}}

    Here is my code:

    	$curl = curl_init();
    
    		$header = array();
    		$header[] = 'Content-length: 0';
    		$header[] = 'Content-type: application/json';
    		$header[] = 'Accept: application/json';
    		$header[] = 'Authorization: Bearer < my token here >';
    
    		$postRequest = array(
        	'email' => $fields['email'],
    		);
    		
    		 curl_setopt_array($curl, array 
    			  (  
    				  CURLOPT_URL => '< my base url here >/wp-json/bdpwr/v1/reset-password',
    				  CURLOPT_POST => true,
    				  CURLOPT_POSTFIELDS => $postRequest,
    				  CURLOPT_RETURNTRANSFER => true,
    				  CURLOPT_ENCODING => '',
    				  CURLOPT_MAXREDIRS => 10,
    				  CURLOPT_TIMEOUT => 0,
    				  CURLOPT_FOLLOWLOCATION => true,
    				  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    				  CURLOPT_HTTPHEADER => $header,
    				  ));          
    
    		  $response2 = curl_exec($curl);
    		  curl_close($curl);  
    		  error_log($response2);

    Hope you’ll see what I did wrong.

    Just so you know Ive done other curl get requests with another API and it’s working and I’ve checked the variable I send for the email ($fields[’email’]) and it’s the right one. Just to see if it came from there, I tested to encode it with urlencode_deep and still not working. But I believe I don’t need to encode it to make it work, because from postman I didn’t have to do it.

    Thanks a lot

    • This topic was modified 1 year, 10 months ago by ninievy.
    • This topic was modified 1 year, 10 months ago by ninievy.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author dominic_ks

    (@dominic_ks)

    Hello,

    Thanks for the support ticket, and thanks for using the plugin!

    I’m not an expert in writing cURL requests in PHP, but I believe your issue is this line:

    $header[] = 'Content-length: 0';

    I think this tells your server to expect the body of your request to be 0 characters long, so it can’t read the email address. When I tried your code with this line removed, it worked fine.

    Cheers!

    Thread Starter ninievy

    (@ninievy)

    Thanks so much, it’s working. I also had to encode the array that I passed in json.

    Have a great day and thanks for your help.

    Plugin Author dominic_ks

    (@dominic_ks)

    Hey, no problem at all!

    If you have a moment spare and wouldn’t mind leaving a review for the plugin, I’d be much obliged – https://www.ads-software.com/support/plugin/bdvs-password-reset/reviews/

    Cheers!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Bad request 400 – no email’ is closed to new replies.