PayPal API V2 Create Invoice Wrong Response/Status Code - paypal

I'm getting the wrong response/status code when creating an invoice using PayPal API V2. I'm getting status code 200 instead of 201 that produces the following response. According to the docs should be returning a Created status code 201 and a JSON response body that shows invoice details
"rel" => "self"
"href" => "https://api.sandbox.paypal.com/v2/invoicing/invoices/INV2-2LMY-9VSE-KKRR-RGYP"
"method" => "GET"

200 and 201 are essentially interchangeable. The documentation states:
A successful request returns the HTTP 200 OK status code and a JSON
response body that shows template details if you set
prefer=return=representation.
The format of that HTTP header string should be Prefer: return=representation
The default is return=minimal, which will only contain the GET link.

Related

Does postman mock server can return status code 449

I try to use Postman to mock server functionality to mock an API call that will return status code 449. For some reason, the good response body is return, but the status code stays at 200.
I can change the example to return 404, 422, 451, and others, but as soon as I set 449 for the status code, it returns 200.
Is there a way to make the mock server return status code 449?
Edit:
I add a collection and environment that reproduce the problems
https://github.com/freddycoder/PostmanStatusCode
449 is not an official status code.
https://dynomapper.com/blog/254-the-6-types-of-http-status-codes-explained#:~:text=A%20449%20error%20appears%20when,order%20to%20fulfill%20a%20request.
The below site shows the officially assigned status codes. it seems like as of now unassigned ones are not supported in postman expect apache status code 509. Maybe mock servers use apache and 449, 450 etc are windows specific status codes.
https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
You can test the specific usecase with the x-mock-response-code request header
On setting this header postman returns response only if the example of mock server has status code set as 449.
else you will get 404 mockRequestNotFoundError .
so in your test you can set pm.response.code = 449 if response code is 200;
To do this in pre reqeust set :
pm.response.code===200?pm.response.code=449:null
pm.response.code===449?pm.response.status="Retry With":null
console.log(pm.response.code,pm.response.status)

Trying to do some assertion from request, which will be present in response

I am passing the request as in my feature file and i am trying to do assert from request to response.
I have tried must contains queries but i am not sure if i am doing it correct, could you please help.
**Background:**
* configure headers = read('classpath:merchantServiceheaders.js')
Given url MservUrl
And path '/spapis/rest/sp-ms-engine/sp/ms/v1/engine/scanandredact'
Scenario Outline: ACH Low Value Payment Rips Services Summary
]
}***
What i would like to do is assert what i have in my request to what i will get back in response.
Since i am passing subject in request the same subject should be present in response
Possible in 0.9.3: https://github.com/intuit/karate#scenario-outline-enhancements
First change the Examples: column header to data!
And request data
When method post
Then status 200
And match response contains data
In 0.9.2 and earlier, with the Examples: column header as data
* def data = <data>
And request data
When method post
Then status 200
And match response contains data

The post rest call returns 201 as response code but location header in response contains NULL

The response code for POST REST call is 201 but the location header in response contains the NULL as ID for newly created row. I don't understand how can this happen. Any help will be appreciated.
The 201 status code, may return a location in the header, but when null, you must use the same URI to acces your newly created resource.
Ref : status code 201

For a POST or PUT request, in my request payload if a mandatory parameter is missing then, what is the HTTP status code to be returned?

My Request Payload for a POST or PUT request is as follows:
{
"domainId": 1,
"roleId": 1,
"date": "2017-1-5",
"downloadStatus": "true"
}
All the parameters in the above payload are mandatory. If one or more mandatory parameters are missing in the payload, then which HTTP Status code is to be returned?
From the W3C page related to Status Code Definitions:
10.4.1 400 Bad Request
The request could not be understood by the server due to malformed
syntax. The client SHOULD NOT repeat the request without
modifications.

Which HTTP code should be return from REST API?

im currently working on a website which has Spring at backend and Angularjs at front side and we had discussed about back end responses to handle frontend's message dialogs and i have a question to ask:
Lets say i have an API :
GET : /getstatistics
Request params : fromTime,toTime ( in timestamp format)
And if client make a request with invalid params like a string, which response code should be returned from server ? HTTP 400 bad request and response body with a message " fromTime and toTime should be in timestamp format" or HTTP 200 with same message?
I saw some Google's APIs for example Oauth, they're returning code 200 for a request with invalid access_token but ,in our project my opinion it should be HTTP 400 because Javascript has success and error callbacks, is it better for it just pop a red color dialog with message inside rather than a HTTP 200 code then still need to check the content of the message?
Any advides and opinions are appreciated.
Thanks!
You should be returning a 400 error for bad request. Check out this reference.
The server cannot or will not process the request due to something
that is perceived to be a client error (e.g., malformed request
syntax, invalid request message framing, or deceptive request
routing).
Please have a look at RFC7231#section-6
A client MUST understand the class of any status code, as indicated by
the first digit
and,
4xx (Client Error): The request contains bad syntax or cannot be
fulfilled
Bad syntax can be something like you've mentioned in your question (making a request with invalid parameters, like a string).
I keep these two references handy whenever I'm designing RESTful APIs, might be helpful for you too:
https://httpstatuses.com/
http://www.restapitutorial.com/httpstatuscodes.html
Yes you are right, the http code should be 400 in your case. Your discussion here normally should be whether you need to return 400 or 422. For this you can check the accepted response for this SO question 400 vs 422 response to POST of data
I think it has something to do with how the parameters are used. If you use the resource, then a 404 should return. If the data is simply not valid then we decide to set a 409 Status to the request. It can't full fill it at 100% because of missing/invalid parameter.
HTTP Status Code "409 Conflict" was for us a good try because it's
definition require to include enough information for the user to
recognize the source of the conflict.
Reference: w3.org/Protocols/
Edit:
In any case, the status code 200 is incorrect here because there is an error. In response, you can then return specific information like this:
{
"errors": [
{
"userMessage": "Sorry, the parameter xxx is not valid",
"internalMessage": "Invalid Time",
"code": 34,
"more info": "http://localhost/"
}
]
}