jonathanraftery / bullhorn-rest-client

Simple client for the Bullhorn REST API
MIT License
11 stars 14 forks source link

Improve PUT/POST request interface #3

Open AigarsABCD opened 6 years ago

AigarsABCD commented 6 years ago

Hello. I am trying to send a PUT request which requires additional parameters. I have the request like $response = $client->request( 'PUT', 'entity/Candidate', ["firstName" => "Alanzo", "lastName" => "Smith", "status" => "Registered"] );

But I get back this error message from Bullhorn - No content to map to Object due to end of input. Can you advise what I am doing wrong?

jonathanraftery commented 6 years ago

The client uses GuzzleHTTP for requests, and the parameters to the request method match those to create a request object in Guzzle. The third parameter is the request options, one of those options being "body", as described at http://docs.guzzlephp.org/en/stable/request-options.html#body.

Set the body option to the JSON content of the request such as: (NOTE: untested code)

$response = $client->request(
    'PUT',
    'entity/Candidate',
    [
        'body' => json_encode(['firstName' => 'Alanzo', 'lastName' => 'Smith', 'status' => 'Registered'])
    ]
);

Clearly, this is a poor interface, and the documentation is completely lacking on this. I will add this example to the readme, and leave this issue outstanding as a possible enhancement for better PUT support.

AigarsABCD commented 6 years ago

Thank you for the reply. It solves my problem and I am able to do a PUT request. Thanks for your help!