I have just started swagger for documented api. I am using Swagger inspector for execute the api, before that I was using Postman. I am passing the data in Swagger body but not getting the data, same thing works in Postman but not working here.
Moreover get request works with Swagger but post is not working properly.
Getting response in Postman:
Same thing not working in Swagger:
I have already set the header, but not getting my parameter in post.
That's because you are not setting the Request Headers Content-Type in swagger, as you need to send the POST request you need to send the data via the Body tab and to send the data you need to specify the content type for the request body so do the following
Add a Content-Type : application/json header from the Authentication&Headers tab like below
if you are using any authentication headers for the request when using postman add them too
Now go to the Body tab
and add the following
{
"userName": "123",
}
That's all you need to do now click send and it will show you the data sent, just select any format for the request Headers and then provide the data in that format. Below are the supported formats
Related
I m using lumen api 5.6.
This is my route
$router->PUT('collections/{collectionId}'
In postman i m calling this api like this.
and this is the body of that request
See here i have CollectioPoints here but its failing in validation.
the data i m sending through formdata is not able to recognized in validation.
But if i send the route from put to post [$router->POST('collections/{collectionId}'], all the data i m sending through form data are recognized and i m getting correct response as below
Why this is happening. Cant i send form data through put request?
Thaank you.
Laravel(Lumen) cheats because html forms only support GET and POST, but it does understand a real PUT/PATCH request.
In Postman You should send POST and set _method to PUT (same as sending forms) to make your data and files visible
_method = "PUT"
Or
If you don't have any file only have data then you can write you parameter in choose below option in Postman
x-www-form-urlencode
Or
You want use PUT method for send Data with form-Data option you should use stuff like this https://gist.github.com/devmycloud/df28012101fbc55d8de1737762b70348
Example
Headers: Content-Type application/x-www-form-urlencoded
_method = "PUT"
an your controller
return $request->file('avatar');
image example
I am writing a RESTful API in the CakePHP framework. Using the POSTMAN app I am testing a delete method with the headers set as follows:
Content-Type application/json
I am sending my data in the body as RAW:
{"id":"8"}
MY API is routing the request as I would expect to my controller, and I'm reading the body with:
json_decode(file_get_contents('php://input'),'true');
This gives me empty data with the above parameters. However if I change the method type to POST or I remove the content type form the headers then I get content in the body.
Any ideas, seems like strange behaviour!
I was trying to hit a rest API URL which using POST request. It receives "ACCEPT" as "application/json" and "Content-Type" as "application/xml". The response from sever says "Content-Type → application/octet-stream;charset=UTF-8". But what now am getting is some kind of encrypted text as below
N4+8ByEFqdMY+fgXAeMQIe93TUKGNXerqeWOGDWm3IoDK5j7YysPB93ebN3IOBCOXlSOlkOV7Vr6 Cz0+nQnWVp09OmB1Xbazz33uWZrJqzzZ8Z7Zdnj0ZfIWMPKDKrymhR8SbXODr+DPj2b3Mv6kI8uo Q3Bx+AtQ8pCVqZQ5sutIOGvJdLhHNSLDNoWZOs87i3eDjGUobNUEiJFaavfKF7l4XJTtVng2TAqN VU9SF5PAlq16syqxTQ2qdk/NU+BOBv8mIYpoCn5gRhuNgpqyPI3b/EhRHLTCo23gRSTi6vwPHeQf vLLTEqtXJnE80xRNyRc9/XvnxBXzaCuW5JJ19GtBzzeJjRwf79WxFbdR50KTgt98T4fpzT42BWJa 6E7w/D7kH+kPO4GkhR6pB7JsC/PBxahvFsEV2tR1dQpCtWQUI9nmMt85bazfRwY4zOWWS5I/rZdN snKn2Zq+Xc2nzIG+imbAoSjIlp8+m/FSzB5fezLHF91fwTM/D1oDUaia11uLtqN8s1pHaH4K8Vkm Ll6pT5KEe+wqZD92gYiEButwXJpxKW4lEhTRdUtffU/6
How can I read it into plain text for some form of readable text like JSON or XML?
try using below line:-
response.setCharacterEncoding("utf-8");
I am using the following cURL request to localhost which runs fine:
curl -u admin:e4d4face52f2e3dc22b43b2145ed7c58ce66e26b384d73592c -d "{\"jsonrpc\": \"2.0\", \"method\": \"feed.list\", \"id\": 1}" http://localhost/minifluxR/jsonrpc.php
But when I send the same request using Postman instead of cURL, I am getting:
{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}
In Postman I used a GET request and sent the following as headers:
url:http://localhost/minifluxR/jsonrpc.php
username:admin
api_token:e4d4face52f2e3dc22b43b2145ed7c58ce66e26b384d73592c
method: feed.list
The following is the PHP function I am trying to trigger:
$server = new Server;
$server->authentication(array(
\Model\Config\get('username') => \Model\Config\get('api_token')
));
// Get all feeds
$server->register('feed.list', function () {
return Model\Feed\get_all();
});
Please help me to correct these errors.
When using cURL, the -u option (or --user) is used to supply the credentials for HTTP Basic authentication. This sets the Authorization header to contain the necessary data to authenticate with the server.
These steps apply to Postman's packaged app. For steps for the legacy app, view this of revision this answer.
To use HTTP Basic authentication as you were in your cURL command, click the Authorization tab and enter your credentials. Clicking Update Request will add the necessary Authorization header for you.
To submit the JSON data in the same way that you did with cURL, use a POST request, select raw under the Body tab, and enter your data like so:
To debug this I used Fiddler - a free web debugging proxy.
I used cURL's --proxy option to make it send its requests through Fiddler like so:
curl \
--proxy http://localhost:8888 \
-u foo:bar \
-d "{\"jsonrpc\": \"2.0\", \"method\": \"feed.list\", \"id\": 1}" \
http://localhost
Now that the request goes through Fiddler, I can select it from the session list, and use the "raw" inspector to see the raw request:
This shows me that the cURL is making a POST request with HTTP Basic authentication and application/x-www-form-urlencoded content. This type of data normally consists of keys and values, such as foo=bar&hoge=fuga. However, this cURL request is submitting a key without a value. A call to var_dump($_POST) will yield the following:
With a = at the end of the data (like so: {"jsonrpc": "2.0", "method": "feed.list", "id": 1}=) the var_dump will yield the following:
However, it seems that JsonRPC will use file_get_contents('php://input') in your case. This returns the data that was submitted with the request, including a =, if the data ends with it. Because it will try to parse the input data as a JSON string, it will fail if the string ends with a =, because that would be invalid JSON.
Using the FoxyProxy extension for Chrome, I created a proxy configuration for Fiddler (127.0.0.1:8888), which allowed me to easily debug the data being sent by Postman's POST request. Using x-www-form-urlencoded with a key of foo with no value, the data sent was actually foo=, which would result in your JSON string being invalid.
However, using "raw" input will allow for the specified data to be sent without a = being added to the end of it, thus ensuring the data is valid JSON.
Curl is using HTTP Basic authentication by default. Your headers set in Postman are something different. Try using Basic Auth in Postman. It is in top panel, you fill in username and password and authorization header will be generated.
I'm a building a RESTful API using Zend Framework 2 and Apigility by Zend Framework.
For testing, I use the chrome extension Postman REST-Client.
I can do GET requests and POST requests without problems by sending form-data without problems.
But when I try to do a PUT, PATCH or DELETE request, I get the following error:
{
"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title":"Unsupported Media Type",
"status":415,
"detail":"Invalid content-type specified"
}
Accept whitelist in Rest-Service-Config of Apigility:
application/vnd.timber-ms.v1+json, application/hal+json, application/json
Content-Type whitelist:
application/vnd.timber-ms.v1+json, application/json
The content-type of the response is application/problem+json
What can I do to fix this and do successfull PUT/PATCH requests?
Is this a problem with Postman or Apigility?
You're getting the 415 error of Unsupported Media Type when Apigility cannot deserialize the data coming from the client. This recently was called out in the documentation.
I suspect your problem is due to the content-type being sent from postman. Pay special attention to the Content-Type Whitelist listed for the service and make sure it contains the content-type you are sending.
For example, if your service has only has application/json in the Content-Type Whitelist and you send the PUT/PATCH with postman as x-www-form-urlencoded, you will get a 415 error of Unsupported Media Type. If you change postman to send the PUT/PATCH with a content-type of application/json and the request body contains valid JSON, Apigility should accept the request.
You can check the content-type postman is sending by clicking on the "Preview" button just to the right of the "Send" button.
I was having a similar issue in Postman with the unsupported media type responses. However, I experienced this response on both PUT and POST requests using my company's API.
I verified that Postman was the problem here and not the request/API in use by running the same request with another similar Chrome extension called Advanced REST Client. I'm not familiar with Apigility, but pretty sure that Postman is the culprit here.
Hoping there is a fix for this issue as Postman and its collections feature is much easier to use than that of Advanced REST Client.
on postman go to normal tab (or other auths tab) and add header:
Content-Type application/json (or any type you need)
make sure that on the raw tab include the json data
{
"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html",
"title":"Unsupported Media Type",
"status":415,
"detail":"Invalid content-type specified"
}
I had the same problem,
My solution was to write my data to [Body] in the [raw] in json format. Like this:
{"message": "UPDATED First Post!"}
And in [Headers] :
[KEY] Content-Type
[Value] application/json