After executing the PHP Script, I am getting the following error – Any help is appreciated. Based on my understanding, I created an array based on the bugzilla documentation - Thanks in advance

{"code":32000,"error":true,"message":"Could not parse the 'params' argument as valid JSON. Error: malformed number (no digits after initial minus), at character offset 1

 $url =""; $data = array( "product" => "TestProduct", "component" => "TestComponent", "version" => "unspecified", "summary" => "'This is a test bug - please disregard", "alias" => "SomeAlias", "op_sys" => "All", "priority" => "P1", "rep_platform" => "All" ); $str_data = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Accept: application/json")); $username = '[email protected]'; $password = 'incrc'; curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password); $result = curl_exec($ch); curl_close($ch); echo $result 
3

3 Answers

You have this:

 curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 

which sends your array of data as a conventional key=value form submission, when you should have

 curl_setopt($ch, CURLOPT_POSTFIELDS, $str_data); ^^^^^ 

which would send your JSON-encoded array instead.

0

You send $data in CURLOPT_POSTFIELDS but I think you need to give it $str_data which is encode in JSON

0

I think you have to replace

curl_setopt($ch, CURLOPT_POSTFIELDS,$data); 

with

curl_setopt($ch, CURLOPT_POSTFIELDS, $str_data); 

to transfer the json encoded array instead of the raw php array.

0

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.