Curl To Postman



To create a cURL command in Postman, Create a request in the Postman builder as you normally would. Click on the code icon. Choose cURL from the drop down. Typeform, Bukalapak, and PedidosYa are some of the popular companies that use Postman, whereas cURL is used by Kosada, mytaxi, and immmr. Postman has a broader approval, being mentioned in 1755 company stacks & 2238 developers stacks; compared to cURL, which is listed in 5 company stacks and 7 developer stacks.

  1. Postman Export Code
  2. Curl To Postman
  3. Curl Post To Postman

Everyone has their preferred scripting language in which you are comfortable, others not so much, and this is especially true in the IT infrastructure space. I occasionally meet people who are proficient in many languages and these people tend to be programmers, annoying gits, or both (joking, it’s jealously really). Like many people who started out as windows admins I’m strong in PowerShell and I’ve learned how to work with REST APIs. But, what happens when you’re trying to use a modern REST API via swagger and the only example given is in cURL? In this post I’m going to give you 2 simple solutions to this problem.

The first solution is a bit of a cheat and isn’t reallyconverting it, but it is useful if you are running on Windows 10. You can simplyinstall the Windows Subsystem for Linux, load the disti of your choice (I usedUbuntu) then copy the cURL example direct into the terminal/shell:

One catch is that I see many cURL examples from REST APIs don’tgive you the full script needed to run the command. The curse of “presumedknowledge” in IT will catch you out. They think that you know exactly what elseis required to get the cURL command to work, but you’re a PowerShell user. Thisisn’t your bag. So, here’s an example from the Rubrik swagger UI:

This command is missing credentials for authentication and handling of an untrusted certificate (common in IT infrastructure). What you need is­­:

Postman Export Code

If you installed the Linux subsystem and followed my example you’ve now successfully run a cURL command in Windows. But I promised you conversion to PowerShell and so that’s what we will do next.

I recommend using PowerShell 6+ as it natively handles untrusted certificates and TLS 1.2. For interacting with REST APIs the equivalent of cURL in PowerShell is Invoke-RestMethod. Using this, here’s the same cURL command converted:

Let’s breakdown what I did here with the help of a diagram:

Postman

To explain:

  1. cURL natively converts credentials into a base64 string, in PowerShell you need to convert it with this command (this is the most complex difference) and embed the credentials in the header.
  2. The cURL equivalent for interacting with REST APIs in PowerShell is Invoke-RestMethod.
  3. With cURL the credentials are specified using -u which it in turns uses to construct the header, we already constructed the header in step 1 so we don’t need a credential flag in PowerShell.
  4. The method (GET ,POST, PUT etc) is signified by -X in cURL, in PowerShell its -Method.
  5. In cURL we are adding the content type to the header, in PowerShell we specify the content with -ContentType.
  6. To bypass warning on insecure certificates on the URL we are working with use –insecure in cURL, in PowerShell 6.0 we use -SkipCertificateCheck.
  7. In cURL we are just specifying the URL at the end of the command. In PowerShell you should specify it after -uri (Uniform Resource Identifier, this case the URL)
  8. The endpoint in my example doesn’t require any data so we are specifying null with -d. We could remove this section from cURL and if we were to specify this in PowerShell it would be with -Body.
PostmanPostman to curl command

Next time anybody says PowerShell isn’t as simple as cURL for working with REST APIs you can now call them out. The only major difference is PowerShell needs a little help converting the credentials to base64, whereas its native in a shell script.

The final example I’ll give covers converting cURL to PowerShell 5.1. Admittedly this isn’t as pretty if the endpoint is using an untrusted certificate and requires TLS 1.2, both native to PowerShell 6.0+. Accommodating for both these scenarios here is the script and cURL command converted to PowerShell 5.1:

Let me know via the drift chat if you have any questions or need more examples. Happy scripting,

If you found this content useful then this small donation would help keep this blog advertisement free and the content flowing. Think about how much time it just saved you! Thanks in advance.

Related

The other day, I found myself making some changes to a network request for our application.

By navigating to a specific page, I knew I’d trigger the call, so that’s what I was doing. At some point, I needed some help and one of the more senior engineers made a comment that I could just copy the cURL into Postman.

I didn’t know what that meant, so I did some digging. Here are the why and how to use Postman for your API testing.

Moving the process to Postman, I get several benefits. The two biggest for me are:

  1. I speed up my testing cycle - since I don’t have to load the entire page, but can focus on just my one call, each test can be done much more quickly
  2. Inspecting the response is easier - I don’t have to navigate through the network tab in Dev Tools each time to find the call I’m interested in, but can use Postman’s UI which is much more suited to the process

Curl To Postman

How to use postman chrome

Curl Post To Postman

  1. Navigate to the web page that you know will trigger the network call
  2. Open the Dev Tools (The Mac keyboard shortcut for Chrome is + + i)
  3. Go to the Network tab
  4. Find the request that you’re interested in replicating, and right click on it. The cURL can be found in Copy> Copy as cURL
  5. Open up Postman
  6. Use Postman’s Import functionality and paste the copied request into the Raw text section, File > Import > Raw Text. (The keyboard shortcut is + o)Note, by copying the cURL, you will also bring in all of your headers - including any authorization that may be necessary.