1
Well I have a small problem sending the data via Curl, when sending the data to the API returns me that there is one of the fields that is not an array: {"errors":["items deveria ser um Array"]}
Code:
$user = 'xxxxxxxxxxxxxxxxxxxxxxxx';
$pass = '';
$data = array(
"email" => "[email protected]",
"due_date" => "2018-10-08",
"items" => array(
"description"=>"carro",
"quantity"=> 1,
"price_cents"=>150000
),
"payer"=>array(
"cpf_cnpj"=>"644.620.920-74",
"name"=>"Jeison",
"phone_prefix"=>"31",
"phone"=>"991872520",
"address"=>array(
"zip_code"=>"30520240",
"number"=>"109",
"street"=>"blenda"
)
)
);
$data_string=json_encode($data);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://api.iugu.com/v1/invoices/' );
curl_setopt( $ch, CURLOPT_HEADER, 1 );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . base64_encode( $user . ':' . $pass ) ) );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch,CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$return=curl_exec( $ch );
curl_close( $ch );
header("Content-Type: text/json; charset=utf8");`
I did here but the error continues, I did so:"items" => array( array( "Description"=>"car", "Quantity"=> 1, "price_cents"=>150000 ), array( "Description"=>"moto", "Quantity"=> 3, "price_cents"=>150000 ) ) converted to json and tbm failed.
– Jeison Guimarães
@user9806474 I updated the answer with other points you should change
– Gabriel Heming
It worked, very sheltered guy!! saved me in the internship!!
– Jeison Guimarães
@user9806474 mark the answer as correct and, if possible, +1
– Gabriel Heming