Home > Mobile >  Sending multidimensional array as key with Laravel http client request
Sending multidimensional array as key with Laravel http client request

Time:02-04

I want to use the HelloSign API to let users sign contracts through our Laravel application. To make the API calls I use Laravel's Http Client which is build around the Guzzle Http Client.

In order to assign a signer to a HelloSign transaction the API expects the following parameter:

signers[Agent][name]

Now when I run this in postman. It works like a charm. But when I use the parameters like this in Laravel's HTTP client I receive the following error message: Invalid parameter: signers[Agent][name]. But when I use the same exact structure using cURL it workins like a charm.

HTTP Client:

Http::withBasicAuth($key, '')->post($url, [
            'test_mode' => '1',
            'template_id' => $template_id,
            'signers[Agent][name]' => 'John Doe',
            'signers[Agent][email_address]' => '[email protected]'
        ]);

cURL:

    CURLOPT_POSTFIELDS => array(
            'test_mode' => '1',
            'template_id' => $template_id,
            'signers[Agent][name]' => 'John Doe',
            'signers[Agent][email_address]' => '[email protected]'
        ),

How can I make the HTTP client work?

CodePudding user response:

Try to use multidimensional array:

Http::withBasicAuth($key, '')->post($url, [
    'test_mode' => '1',
    'template_id' => $template_id,
    'signers' => [
        'Agent' => [
            'name' => 'John Doe',
            'email_address' => '[email protected]'
        ]
    ]
]);
  •  Tags:  
  • Related