1

I need to make a POST request to claim voucher. At API docs I find this:

POST /vouchers/{voucherId}/claim

{
    "Participant": {
        "FirstName": "John",
        "LastName": "Jones",
        "Telephone": "99999 127 127",
        "EmailAddress": "[email protected]",
        "PostCode": "HP18 9HX",
        "HouseNameNumber": "2",
        "Street": "Bridge Road",
        "Locality": "Ickford",
        "Town": "Lodnon",
        "County": "Bucks"
    },
    "ExperienceDate": "2015-10-01T00:00:00"
}

Now I, using Laravel guzzle library I make this request:

 public function testclaim()
    {

$client = new GuzzleHttp\Client;
$headers = ['Content-Type' => 'application/json'];

$res = $client->post('https://apidev.asdasd.com/vouchers/11989898_1-9FDD/claim', [
    'headers'=>$headers,
     'auth' => [
        'PET_RES', 'asdasdasd111111'
    ],
    'form_params' => [

        'FirstName' => 'Peter',
        'LastName' => 'Alexo',
        'Telephone' => '8888888888888'

    ]
            ]);
$res = json_decode($res->getBody()->getContents(), true);

dd($res);

    }

but what I get is:

400 Bad Request

{ "Message": "The request is invalid.", "ModelState": { "claim": [ "An error has occurred." ] (truncated...)

What is the right way to send a request to the API with following data?

1 Answer 1

3

try this

...
'form_params' => [
    'Participant' => [
        'FirstName' => 'Peter',
        'LastName' => 'Alexo',
        'Telephone' => '8888888888888'
    ],
    'ExperienceDate' => '2015-10-01T00:00:00'
]
...

if your api just accept json, try replace form_params with json

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.