Replicating POST request in POSTMAN - api

I'm trying to use Postman and replicate the following POST request from this link:
https://www.msc.com/en/track-a-shipment?params=dHJhY2tpbmdOdW1iZXI9YXNkYSZ0cmFja2luZ01vZGU9MA%3D%3D
The payload necessary to get a response from this API is something like:
{trackingNumber: "asda", trackingMode: "0"}
With the following payload, I expect to receive the following response:
{IsSuccess: false, Data: "Container not found"}
Here, you can see my Postman request:
All I seem to get from this is an empty string, which is not the same result I would see If I checked my Network tab from developer tools.
I'm wondering what do I need to do in order to get the same result. Change headers? Change payload format? What else could it be?

The request works for me, what's the difference that depends. But the easiest way to find the correct answer is to import the request as is from the Developer Tools.
Find the request on the request list and click Copy as cURL (bash):
Then on Postman click Import (top left main window) and select the Raw Text option:
The request will be on the current window and you can just click Send:
So you can now diff your request with this one. There's a lot of headers so I would remove them one by one and see where the request fails. Without having the API at hand, this is really a trial-and-error exercise.
Hope this helps.

Related

How do I use/read an api documentation to send a simple request?

I know this is probably strictly case-specific, but I do feel like I encounter this problem a lot so I will make an effort to try and understand it better.
I am new to using APIs, but I have never succeeded in using one without copying someone's code. In this case, I can't even find any examples on forums, nor in the API documentation.
I'm trying to pull my balance value from my investment bank "NordNet" to scroll, amongst other things, on an Arduino display I've made. Right now I use python Selenium to automatically but "physically" login to NordNet and grab my balance from the DOM. As I'm afraid I might get "punished" for such botted behavior, and because the script is fairly high maintenance (as the HTML changes over time), I would obviously much rather get this information through NordNet's new API.
Link to NordNets API doc
Every time I try to utilize an API doc it's always the same, it looks easy, but I can never get it to work.
This time I tried to just play a little with the API before exploring further.
I use PostMan to send the simplest request:
https://www.nordnet.se/api/2
And I get a successful code 200 JSON response.
I then try to take it a step further to access my account data using this endpoint:
https://www.nordnet.se/api/2/accounts
For this one, I obviously need some authentication of some sort
The doc looks like this:
So I set my PostMan client up like this and get the response showcased:
I've put my NordNet login into the "Auth" tab as "basic auth" and I then see PostMan encrypts this info some way, in the "Headers" tab.
I'm getting an unauthorized response code and I have no idea why. Am I using PostMan wrong (probably)? Is the API faulty (probably not)? There is a mention of a session_id that should contain both password and username? Maybe something completely else...
I hope you can help
The documentation says to use session_id as username and password for that api ,
so try logging in and then get the session id (try with both sid and ssid) . from network tab and pass it as username and password for authorization .
sid- is for http and ssid for https i guess , try with both

How to put the following soapUI request into Karate?

Media type: Multipart/form-data and value as query type
Refer to the attached file for more detail
Please refer to multipart field: https://github.com/intuit/karate#multipart-field
And if you have query params, use param. But it is hard to understand from just a screenshot.
If you are still stuck, please provide a cURL command (you can export from Postman, browser etc.) and we can figure this out.

HERE API request returns view instead of JSON

I'm trying to use the Places (Search) API (or any HERE API for that matter) for the first time. I tried the example in this page and got this page as a response:
https://places.cit.api.here.com/places/v1/browse?app_id=YOUR-APP-ID&app_code=YOUR-APP-CODE&in=52.521,13.3807;r=2000&cat=petrol-station&pretty
I don't know what I'm missing here but, I expected to get a plain JSON/XML response (orange rectangle), like this example of the Routing (Isoline) API which outputs this to the browser:
https://isoline.route.cit.api.here.com/routing/7.2/calculateisoline.json?mode=fastest;car;traffic:disabled&jsonAttributes=1&rangetype=time&start=34.603565,-98.3959&app_id=YOUR-APP-ID&app_code=YOUR-APP-CODE&range=1800
this way I could consume the service using the JSON/XML output.
I already tried both examples above in my Spring (JAVA) app and the second one works as expected, while the first one throws error (as expected).
HERE API newbie here, help appreciated.
PS: this project app of mine is just about finding nearby POIs (e.g: gyms, coffee shops, pharmacies, cinemas, etc). So, any suggestions on what API is best to go with for this, also very appreciated.
I don't know the HERE api but from having a quick look it seems they generate your results depending on the Accept header in your http request.
By default my chrome sends this accept header:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
If I use Postman to send the request without any Accept header or Accept: application/json it returns the json results.
If I add an Accept: text/html header to the request in Postman it sends me the PlayPen in html.
You can also see in their documentation that they use the appropriate Accept: application/json
I suggest you use Postman to test and play with the API's.

Capturing Postman requests in a report

I was checking on Postman and newman and how to automate the api testing. I have checked on assertions and the report generations that show results of assertion failures and pass status. We can check the status code by writing a an assertion. But is there a way where in we can capture the request and response directly for an api and generate a report that shows (say) 3 apis were tested and the requests agve 200 for first call 201 fro second an d then 400 for third without writing any assertions. The overall result will show request url and corresponding response code for the api.
This will be helpful in a way when we run a collection and then can see a html report stating the response code corresponding to the request url.
Thank you all in advance for your patience reading and extremely helpful insight to the problem. Thank You.
this already exists in Postman, through its command line interface Newman.
Have a look here and here as well.
You'll be able to set options, depending on the kind of reports you want.
Personaly I can use newman in TFS and get JUnit style reports that fit for my continuous integration purpose. You can generate also HTML reports.
Check the different options.
To handle response data, have a look here :
This takes place in the Tests tab of the Postman request, though
You can obtain informations about HTTP code (responseCode.code), description (responseCode.detail), etc.
You can also parse the JSON body to get more information
var jsonData = JSON.parse(responseBody);
You can output this data in the console

Google Spreadsheet API: Post request fails

I have a Google spreadsheet published to the web, and I'm trying to read and write list-based feeds. I have not authenticated.
I can read data using a GET request just fine.
curl https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDsadfwerF4RE0M/1/public/full
However, all my post requests to write data come back with an error
curl --data '' https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDlN3mMaBfF4RE0M/1/public/full
curl --data '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended"><gsx:id>1</gsx:id><gsx:status>1</gsx:status><gsx:user_email>1</gsx:user_email><gsx:url domain>1</gsx:url domain><gsx:highlighted_text>1</gsx:highlighted_text><gsx:complete_text comments>1</gsx:complete_text comments><gsx:created_date>1</gsx:created_date><gsx:updated_date>1</gsx:updated_date><gsx:created_by>1</gsx:created_by><gsx:updated_by>1</gsx:updated_by></entry>' https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDlN3mMaBfF4RE0M/1/public/full
The error I'm getting is: "Sorry, the file you have requested does not exist. Please check the address and try again."
Do POST request require authentication? I can't find anything in the docs that say so.
Any help would be appreciated. Thanks.
Two things:
I think you need to use the private feed (.../private/full), not the public one (.../public/full) like you're using now. More on the private-versus-public distinction is in the API docs.
You will need an Authorization header. (That process gets pretty complicated, but there's a lot of good info here. Remember to select the appropriate scopes.)
Both are mentioned in the example about adding a list row in the Sheets API docs. (I'd link directly, but I don't have enough rep to add more than two links. Just search for "Adding a list row".)