A really simple one today, but one I had need of, and wasn’t sure was possible. That is to take a cURL request and import it in to Postman.
The clue is in italics above. However, I didn’t know this feature existed, and judging by the replies I got internally on Slack, neither did anyone else on the team. So I figured I’d share it here, and spread the love.
OK, so I can’t actually share the real request I needed this for. But it doesn’t matter, as the process is identical regardless.
You probably already know that you can convert a Postman request from the Postman client into other formats by clicking the </>
code icon on the right hand side bar:
And there are a bunch of code snippet formats available:
One of the formats is cURL:
And cURL is most useful as you can run the command from your CLI and rule out any ‘funk’ in your own code. Essentially if the cURL request succeeds, you know the API / remote system is not at fault.
But what about when you have the cURL request and you want to run that from Postman.
I encounter this problem a lot when working with other people’s systems. It might be web scraping, or trying to reverse engineer some client code, or any other reason I can’t think of right now. Needless to say, this happens quite a lot.
How To Find Your Request in cURL Format
If you open Chrome developer tools, and find yourself an XHR request – something like you would find from a bit of JavaScript calling a remote API – then you can grab that request in a variety of formats:
From the Network tab, right click on the request you are interested in, then go to Copy > Copy as cURL.
Now, with this in your clipboard, go back to Postman and press the Import button:
Depending on how new your Postman client is, you will see different things here.
On my Mac I got a simple text input field to paste in my request.
On Linux I get a full on pop-up box with a variety of options:
From there I have to select Raw Text:
And when I do that, I get prompted to … do what I already thought I was doing:
After which I see all the hard work is done for me:
And all I need to do is test the POST
request:
Which behaves as expected:
I know this is in the docs, and a quick Google would have likely told me the answer. I just thought it was super neat and is exactly the kind of seemingly useless trivia I pick up when scanning other people’s blogs, that one day I will need and think, a-ha, I remember when that boring guy who never shuts up about trivial things told me all about how to do that!