Reputation: 9279
I'm working on Laravel 5.2
with Guzzle 6.2
, and I have this CURL request :
curl -X POST "https://api.lifebot.fr/letters" \
-u "test_12345678901234567890:" \
-d '{
"description": "Demo Letter 1",
"to": {
"name": "LIFEBOT",
"address_line1": "30 rue de la république",
"address_city": "Paris",
"address_postalcode": "75015",
"address_country": "France"
},
"color" : "color",
"postage_type" : "prioritaire",
"from": {
"name": "LIFEBOT",
"address_line1": "30 rue de la république",
"address_city": "Paris",
"address_postalcode": "75015",
"address_country": "France"
},
"source_file": "<html style=\"padding-top: 3px; margin: 0.5px;\">Lettre HTML for {{name}}<\/html>",
"source_file_type": "html",
"variables" : {
"name" : "Lifebot"
}
}'
This request is OK if KI use a terminal for testing.
So, the params -u is my API key, and -d is datas to sent to the API. How can I convert this with Guzzle ?
I tried something like :
$result = $client->request('GET',
'https://api.lifebot.fr/', [
'u' => 'test_12345678901234567890'
]);
Wha'ts the syntax with Guzzle for add my param -u and my param -d ?
Upvotes: 0
Views: 486
Reputation: 4937
I would say that you should keep making the same request type (e.g., POST
instead of GET
). Regarding curl -u
param, this is the authentication param, so you can translate to guzzle to auth
with username set to apiKey and null password. Curl -d
param is just the body content sent in the post request. So I believe that it would be something like the following:
$client->request('POST',
'https://api.lifebot.fr/',
[
'auth' = [ 'test_12345678901234567890', '' ],
'body' => '{
"description": "Demo Letter 1",
...
"name" : "Lifebot"
}
}'
]);
Upvotes: 1