Post an array in a HTTP request

When asking your question, please include:

:footprints: The steps you have taken
:camera_flash: Relevant screenshots
:link: Any links you have
[ Code { "and": "JSON", "in" : "code block"} ]
:x: Exclude Personal Information.

Hello,
I am a bit confused on how to send a Http post so I would appreciate if someone could help me.
The API documentation says for required variable:

Name Type Validation

emisor array Required
tipodoc string Required
servicio integer Required

Captura1

and I have an documentatio example using PHP and Guzzle HTTP:

$data = [
‘emisor’ =>
[
‘tipodoc’ => ‘39’,
‘servicio’ => 3,
],
‘detalles’ =>
[
[
‘codigo’ => ‘10001’,
‘nombre’ => ‘Pan’,
‘cantidad’ => 1,
‘precio’ => 500,
‘exento’ => false,
],
],
‘expects’ => ‘all’,
];

$client = new GuzzleHttp\Client;

$response = $client->post(‘Lioren Enterprises’, [
‘headers’ => [
‘Accept’ => ‘application/json’,
‘Authorization’ => 'Bearer '.$accessToken,
‘Content-Type’ => ‘application/json’
],
‘body’ => json_encode($data),
]);

$responseBody = json_decode((string) $response->getBody(), true);

I have tried different configurations and I get a Status code 200 but with an error that says “emisor must be an array” (I believe an array).

Any idea how to fix it?
Best regards

you need to add json object in Body/json module in http request box
Best Regards
Expert Help Pro_Tanvee

3 Likes

Hi @ipoblete ,

Adding to what @Pro_Tanvee has mentioned in the earlier reply, what you want to do is pass the JSON body inside the HTTP Module’s Request Content instead of Query Parameters.

So, Something like this should do the trick,

And, JSON will look like this from your example code snippet,

{
	"emisor": {
		"tipodoc": "39",
		"servicio": 3
	},
	"detalles": [{
		"codigo": "10001",
		"nombre": "Pan",
		"cantidad": 1,
		"precio": 500,
		"exento": false
	}],
	"expects": "all"
}
3 Likes