Instead of body you need to use form_params as the error message suggests!
This is because you use a newer version of Guzzle!
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I want to make a post request to an API but its appearing an error:
Passing in the "body" request option as an array
to send a POST request has been deprecated.
Please use the "form_params" request option to
send a application/x-www-form-urlencoded request,
or the "multipart" request option to send a multipart/form-data request.
The code:
public function createClient()
{
$client = new \GuzzleHttp\Client();
$array = ['invoice' => [
'date' => date('Y-m-d H:i:s'),
'due_date' => date('Y-m-d H:i:s'),
'client' => ['name' => 'John', 'code' => ''],
'items' => [
'item' => [
'name' => 'item1',
'description' => 'item1 desc',
'unit_price' => '10',
'quantity' => '1.0'
],
'item' => [
'name' => 'item2',
'description' => 'item 2 desc',
'unit_price' => '10',
'quantity' => '1.0'
]
]
]];
$result = ArrayToXml::convert($array);
$response = $client->request('POST', 'https://testname.app.invoicexpress.com/invoices.xml', [
'query' => ['api_key' => '...'], 'body' => [ $result],
]);
dd($response->getStatusCode());
}
Instead of body you need to use form_params as the error message suggests!
This is because you use a newer version of Guzzle!
Please or to participate in this conversation.