Posting data using Guzzle

339 Views Asked by At

I am trying to post data using Guzzle 6,

The request which I am generating dynamically looks as below:

$postRequest = Array(
    'headers' => array(
        ['x-api-key'] => 'srDxd39M2FQxxvfvxxcIohcLfKDcdcRUU'
    )
    'form_params' => array(
            [0] => Array ( 
                ['name'] => 'function_key' 
                ['contents'] => 'REGISTER' 
            ) 
            [1] => Array ( 
                ['name'] => 'email' 
                ['contents'] => '[email protected]' 
            ) 
            [2] => Array ( 
                ['name'] => 'password' 
                ['contents'] => 'test' 
            ) 
            [3] => Array ( 
                ['name'] => 'name' 
                ['contents'] => 'tester' 
            ) 
            [4] => Array ( 
                ['name'] => 'is_org' 
                ['contents'] => 'N' 
            ) 
        )
)
// Sending Request using 'POST' Method                        
$client = new GuzzleHttp\Client();
$response = $client->request('POST','abcdxyz.com',$getRequest);  

Now my problem is, The Response which I am receiving after sending the above request says "API 'function_key' is missing". But I am sending 'function_key' as part of request, then What I am missing here ?? Why it is not able to find 'function_key'

Any help is Appreciated

TIA

1

There are 1 best solutions below

3
On

Try formating it as follows:

$postRequest = [
    'headers' => [
        'x-api-key' => 'srDxd39M2FQxxvfvxxcIohcLfKDcdcRUU'
    ],
    'form_params' => [
        'function_key' => 'REGISTER',
        'email' => '[email protected]', 
        'password' => 'test', 
        'name' => 'tester', 
        'is_org' => 'N' 
     ]   
]