I'm trying to send the following data to a REST API with Guzzzle
{
"documents": {
"id_proprietaire": 28,
"nom_proprietaire": "rash",
"prenom_proprietaire": "rash",
"code_identification": "9LS9PB094MIL9CPL",
"dossier_initial": "path_to_data"
},
"dossier_final": null
}
But I don't find how to use multipart and json requests together. Can someone help?
This is what I have done and I got a 404 bad request error field documents is required
$httpClient = new Client();
$token = 'Token 7480ea9a692f98ad943e810820ced48aa09ca174';
$response = $httpClient->post('http://127.0.0.1:8000/api_memoire/signed/', [
'headers' => [
'Authorization' => $token,
'Accept' => 'application/json',
],
'multipart' => [
[
'name' => 'documents',
'contents' => json_encode(
[
'id_proprietaire' => $id_demande,
'nom_proprietaire' => $demande->nom,
'prenom_proprietaire' => $demande->prenoms,
'code_identification' => $code,
'dossier_initial' => $document,
]
),
],
[
'name' => 'dossier_final',
'contents' => null,
]
]
]);