CyberSource / cybersource-rest-client-dotnet

.NET client library for the CyberSource REST API
Other
16 stars 42 forks source link

Transaction Search API not working as documented #52

Open xantari opened 4 years ago

xantari commented 4 years ago

There is an undocumented “feature” in your Transaction Search API.

https://developer.cybersource.com/api/reference/api-reference.html

According to above URL it indicates that only 201, 400, 502 should be valid response codes.

For successful responses it is infact 201.

However for a search on a merchant reference code (clientReferenceInformation.code) that does not exist, it returns a 404 error response. With data indicating there was nothing found (count:0 in response JSON).

This doesn't seem to be proper API design, as 404 indicates errors in most frameworks / librarys and should not be used to mean "not found" of a search request. Even in your .NET REST client in this GIT repo it fails to parse this response properly and throws an exception.

Is this an API design bug since it isn't documented?

Can you fix the .NET REST client to behave properly in this condition and return the response body without throwing an exception?

Example in LIVE CONSOLE showing this issue:

image

xantari commented 4 years ago

Just got this email yesterday that went out to all cybersource customers! Looks like they are making a change in the API design to follow what is documented online.

Dear Merchant: Cybersource is updating the HTTP response code returned by the Transaction Search REST API in certain scenarios.
When your search criteria does not match any transactions, the API currently responds with a response code of 404. With the upcoming update, we will change the response code to 201, in conformance with the published API specification. As part of this change, the API response will contain a "totalCount" field with a value of ‘0’, which indicates to the client that there were ‘0’ transactions that matched the search criteria. This update will go into effect early September. For more information about Transaction Search API, see the API Developer Guides in the Cybersource Developer Center.

Regards, CyberSource Customer Support

For your reference, in the “no transactions found” scenario, see this sample JSON response body which accompanies an HTTP 201 response code. Sample 201 Response:
{
"_links": {
"self": {
"href": "https://apitest.cybersource.com/tss/v2/searches/5106e95c-024b-4237-adc7-test123456",
"method": "GET"
}
},
"searchId": "5106e95c-024b-4237-adc7-test123456",
"save": false,
"name": "MRN",
"query": "clientReferenceInformation.code:invalidMRN AND submitTimeUtc:[NOW/DAY-7DAYS TO NOW/DAY+1DAY}",
"count": 0,
"totalCount": 0,
"limit": 100,
"offset": 0,
"sort": "id:asc,submitTimeUtc:asc",
"timezone": "America/Chicago",
"submitTimeUtc": "2019-08-21T18:27:19Z"
}