This request requires Basic Auth: user and password.
Headers with two fields.
and xml body.
This API is tested working in Postman.
But I am not sure how to make this work in Laravel, I only work with JSON before.
Any suggestion how can I get started? or any package I can use?
You can use http post
$http=Http::withHeaders([
'Content-Type'=>'application/xml',
'SOAPAction'=>'balance'
])->post(url,$xmlBodyContent);
return response($http->body())
->withHeaders([
'Content-Type' => 'text/xml'
]);
for xml doc notation
Ref:https://www.php.net/manual/en/simplexml.examples-basic.php
Related
I'm trying to make a Http request with a url like
https://{{api_key}}:{{api_password}}#{{store_name}}.myshopify.com/admin/api/{{api_version}}/products.json
But the Http response is throwing *** replacing the api_password, even if I hardcode it.
This is all done in a Laravel app and is failing with 400 Bad Request.
The request is working using postman.
Is the password actually being stripped out of the request, or is it just being hidden in the response?
Try using HTTP CLIENT
This is how it works:
Import use Illuminate\Support\Facades\Http;
Http::post(
"https://${api_key}:${api_password}#${store_name}.myshopify.com/admin/api/${api_version}/products.json",
[
"foo" => "bar"
]);
Http::post automatically converts headers to content-type: application/json.
HTTP CLIENT helps you to make less error and it also using guzzle.
Problem:
I am trying to get the content / body from a text/plain POST request in a Controller in Laravel 8.
Nothing in the docs or numerous google searches worked.
I have tried:
$request->input();
$request->all();
$request->json();
json_encode($request);
All of these seem to show that the request is completely empty.
Context
This may not be relevant to the solution, but might help other's who are trying to google this problem: The request I am trying to handle with my controller is being sent by navigator.sendBeacon on the client side. The request body is actually stringified JSON, but sendBeacon does not allow you to send requests with content-type JSON. Devtools show the content-type header for this request as 'text/plain'.
My Answer:
Use $request->getContent() to get the content of a text/plain HTTP request.
And then, if you are in a situation like mine where the text is actually JSON, use json_decode($request->getContent(),true) to get a standard PHP array from the content which you can use in your Controller.
It turned out to be quite simple, but the information was not in the docs, or in any online searches so I thought it would be worthwhile to post to SO anyways...
You can send the data as JSON like this instead
data = new Blob([JSON.stringify(data)], {type : 'application/json'})
navigator.sendBeacon('/your/route/here', data)
I have a server needing to update a shared Google Sheet. It generates special tokens for offline use so doesn't work with PHP quickstart module.
I am trying to setup request in Postman for this action:
https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update
But get the following result:
Is it possible to use HTTP for this API?
Turns out I had to add ?valueInputOption=RAW on the end of my URL request and removed valueInputOption from the request body JSON.
The valueInputOption should be passed as params to the POST URL, it should not be in the request body.
Also the sheetID and the range should be sent in the URL.
I suppose it should be a POST call not PUT.
i want to have authorization access, for google drive api calls.
I use ruby, and HTTParty gem.
I followed this quickstart sample: https://developers.google.com/drive/v3/web/quickstart/ruby
Then, i want to used HTTParty for use this API, and i understand that i have to get an authorization with the user's access_token obtained with the credentials above, but when i tried this code HTTParty.get('https://www.googleapis.com/drive/v3/about', headers: {'Authorization' => "Bearer #{service.authorization.access_token}"})
i've got this error status :
...."code"=>400, "message"=>"The 'fields' parameter is required for this method."}}, #response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>,....
My goal is to make some tests about the usage of Google Drive API.
How should i have an authorization access for this API?
I found the answer to my question !
My error was not on the Authorization, but on the fields request parameter that i'd forgot!
HTTParty.get('https://www.googleapis.com/drive/v3/about?fields=kind,user', headers: {'Authorization' => "Bearer #{service.authorization.access_token}"}) for example.
thank's to this documentation:
https://developers.google.com/drive/v3/web/performance?authuser=0#partial
see you !
I am developing an API using CodeIgniter and the RestServer for CI (see below). I am also using the Firefox RestClient plugin to test the API.
What I am wondering is how to do the test post (what format).
Tried {"desc":"value"} but it did not work. The API is not "seeing" the incoming post fields.
http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/
the post body doesn't need to have a specific format, but the most convenient is to encode the body in the same way web browsers encode form data, specifically Content-Type: application/x-www-form-urlencoded. In particular, the Host and Content-Length headers are not optional, and the Content-Type header is usually needed to tell the server how to interpret the body. A well formed POST request will look like:
POST /path/to/resource HTTP/1.0
Host: example.com:80
Content-Length: 21
Content-Type: application/x-www-form-urlencoded
key=value&key2=value2
It's still up to the server to recognize the content-type header and parse the body that way.
Note that the data is after all the headers, not as part of the request path (in the first line).
Optionally, you can use Proxy Library which i wrote for CI. With that, you can simulate any of possible call to your API(its works for popular REST API too), with more simple syntax instead using cURL...
// An example call to your API end point using POST, will be simply
$this->load->library('proxy');
$this->proxy->http('POST', 'http://somesite.com/api/users', array('username' => 'foo', 'password' => 'bar'));
You can define whatsoever HTTP header too (like API Key or whatever else).