0

I have two array of objects that I want to post to an API but it displays an error missing value for parameter: productDC

it seems that i have to pass ProductDc and buyerDC along with their data. for this I also tried

 $data_string = array({ProductDc"product_name" => "Electronics","price" => "200 usd"}, buyerDC{"buyer_name" => "john mark","address" => "17 more strret"}); 

below is the informations

1.) ProductDC pass it as array of objects **product_name(string)

price (string)**

2.) buyerDC pass it as array of objects **buyer_name(string)

address (string**)

here is my code

<?php $data_string = array("product_name" => "Electronics","price" => "200 usd", "buyer_name" => "john mark","address" => "17 more strret"); $data = json_encode($data_string); //$data = $data_string; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "myapi.com", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "$data", CURLOPT_HTTPHEADER => array( "accept: application/json", "content-type: application/json; charset=utf-8" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?> 
1
  • If any API is giving you a response saying that some 'xyz' parameter is missing then it is pretty simple that you are not passing that parameter in the API call. In your case if it is saying that you are missing ProductDc or buyerDC parameter then you need to pass them in the POST data which you are not doing if we see the values you have put inside $data_string array. Read their API document properly to find out the proper set of parameters which is required in the API request and pass all parameters in the request. Commented Feb 22, 2018 at 9:09

1 Answer 1

1

Considering below information that you have provided if they want a data in the format in which -

1.) ProductDC should be an array of objects containing -

product_name(string)

price (string)

2.) buyerDC should be array of objects containing-

buyer_name(string)

address (string)

Probably they are expecting the data in a different form which you may get by changing $data_string value as below -

$data_string = array( "ProductDc"=>array( "product_name" => "Electronics", "price" => "200 usd" ), "buyerDC"=>array( "buyer_name" => "john mark", "address" => "17 more strret" ) ); 

Change your $data_string value to the one I posted above and check.

Sign up to request clarification or add additional context in comments.

1 Comment

Please check if you are enclosing the values of "ProductDc" and "buyerDC" inside array(...) after => while creating $data_string array

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.