221

I am using Postman to test some Curl requests to an API server. The API developers gave us the curl command, but I can't send it from the Postman. How to make such a request from the Postman?

curl -X POST "https://api-server.com/API/index.php/member/signin" -d "{"description":"","phone":"","lastname":"","app_version":"2.6.2","firstname":"","password":"my_pass","city":"","apikey":"213","lang":"fr","platform":"1","email":"email@example.com","pseudo":"example"}"

--0xKhTmLbOuNdArY
Content-Disposition: form-data; name="userfile"; filename="profil.jpg"
Content-Type: image/jpeg
Content-Transfer-Encoding: binary

<ffd8ffe0 00104a46 49460001 01010048 ... a00fffd9>

—0xKhTmLbOuNdArY—
Marin Bînzari
  • 3,490
  • 2
  • 23
  • 39

8 Answers8

583

A simpler approach would be:

  1. Open POSTMAN
  2. Click on "import" tab on the upper left side.
  3. Select the Raw Text option and paste your cURL command.
  4. Hit import and you will have the command in your Postman builder!
  5. Click Send to post the command

Hope this helps!

Onkaar Singh
  • 6,267
  • 1
  • 11
  • 22
  • 7
    I never knew you could do this until I saw this post. Thanks! – austinthedeveloper May 25 '16 at 19:30
  • 5
    This is exactly what I wanted. Thanks! – Joshua Dance Dec 02 '16 at 21:03
  • 3
    I tried it and it worked partially. This is my curl request: `curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"customer_id":"812122", "event":"add_to_cart", "email": "abc@def.com", }' -u 9f4d7f5445e7: https://api.myapp.com/api/event` After importing the body got imported correctly, the headers and the Url also got imported. Only the api key 9f4d7f5445e7 which is `-u 9f4d7f5445e7: https://api.myapp.com/api/v1/event` in the curl request did not import or may be Postman skipped it. Any idea how to resolve it? – Rito Jun 21 '17 at 08:48
  • 1
    I figure it out to import curl cmd by myselft. But took me sometime to find out where is the page with my imported curl, it looks like nothing happen when import a file/cmd. You then need click on the "code" button on the top right side (under save button). Then you will see whether your curl is loaded or not. – zhihong Oct 03 '17 at 13:50
  • This approach didn't utilise the credentials I coded into it, so had to add those manually using Auth > Basic Auth ,inside the actual request using mouse & dropdowns. Worth mentioning I think, since the software's behaviour is such that it appears to have accepted & utilised the creds:all you get is a "please supply valid credentials" rather than "please supply some credentials". – olisteadman Feb 27 '19 at 11:16
  • @Onkaar can't we import other than cURL? – Premraj Apr 23 '19 at 14:13
  • @Rito in my case, I have to specify key and value in 'params' tab – Muhammad Ashfaq Oct 21 '19 at 12:01
  • If this doesn't work for you then review your command for any non-functional paramters and remove them. In my case a `curl ... -vv` wouldn't work, until the `-vv` was removed. – STW Nov 11 '19 at 15:21
  • [About a failure case][ "curl -X POST "http://localhost:8000/api/workflows/v1" -H "accept: application/json" -F "workflowSource=@simple-hello.wdl" ] if there is a file info in the curl command, it will fail when importing it into the postman. You need to fix the 'workflowSource' field by choosing the target file. – 蔡宗容 Apr 21 '20 at 01:32
  • flawless answer Onkaar! – Gaurav Apr 08 '21 at 06:35
16
In addition to the answer
1. Open POSTMAN
2. Click on "import" tab on the upper left side.
3. Select the Raw Text option and paste your cURL command.
4. Hit import and you will have the command in your Postman builder!
5. If -u admin:admin are not imported, just go to the Authorization 
   tab, select Basic Auth -> enter the user name eg admin and password eg admin.
This will automatically generate Authorization header based on Base64 encoder
electricalbah
  • 1,897
  • 1
  • 18
  • 34
8

1) Put https://api-server.com/API/index.php/member/signin in the url input box and choose POST from the dropdown

2) In Headers tab, enter:

Content-Type: image/jpeg

Content-Transfer-Encoding: binary

3) In Body tab, select the raw radio button and write:

{"description":"","phone":"","lastname":"","app_version":"2.6.2","firstname":"","password":"my_pass","city":"","apikey":"213","lang":"fr","platform":"1","email":"email@example.com","pseudo":"example"}

select form-data radio button and write:

key = name Value = userfile Select Text key = filename Select File and upload your profil.jpg

hello_harry
  • 1,175
  • 1
  • 11
  • 21
8

I tried the approach mentioned by Onkaar Singh,

  1. Open POSTMAN
  2. Click on "import" tab on the upper left side.
  3. Select the Raw Text option and paste your cURL command.
  4. Hit import and you will have the command in your Postman builder!

But the problem is it didn't work for the Apis which requires authorisation.

This was my curl request:

curl -v -H "Accept: application/json" -H "Content-type:
application/json" -X POST -d ' 
{"customer_id":"812122", "event":"add_to_cart", "email": "abc@def.com", }' 
-u 9f4d7f5445e7: https://api.myapp.com/api/event

After importing the body got imported correctly, the headers and the Url also got imported. Only the api key 9f4d7f5445e7 which is

-u 9f4d7f5445e7: https://api.myapp.com/api/v1/event 

in the curl request did not import.

The way I solved it is, -u is basically used for Authorization. So while using it in Postman, you have to take the API key (which is 9f4d7f5445e7 in this case) and do Base64 Encode. Once encoded it will return the value OWY0ZDdmNTQ0NWU3. Then add a new header, the key name would be Authorization and key value would be Basic OWY0ZDdmNTQ0NWU3. After making that changes, the request worked for me.

There are online Base64 Encoders available, the one I used is http://www.url-encode-decode.com/base64-encode-decode/

Hope it helps!!!

Rito
  • 2,232
  • 1
  • 18
  • 33
4

sometimes whenever you copy cURL, it contains --compressed. Remove it while import->Paste Raw Text-->click on import. It will also solve the problem if you are getting the syntax error in postman while importing any cURL.

Generally, when people copy cURL from any proxy tools like Charles, it happens.

Ankit Gupta
  • 627
  • 4
  • 11
1

When you use Chrome copy as cURL (bash) and import in Postman, you need to do the following things:

  1. Remove --compressed option
  2. Replace --data-raw with -d

Otherwise you will get invalid format for cURL error.

Derek Liang
  • 927
  • 1
  • 13
  • 21
0

As mentioned in multiple answers above you can import the cURL in POSTMAN directly. But if URL is authorized (or is not working for some reason) ill suggest you can manually add all the data points as JSON in your postman body. take the API URL from the cURL.

for the Authorization part- just add an Authorization key and base 64 encoded string as value.

example:

curl -u rzp_test_26ccbdbfe0e84b:69b2e24411e384f91213f22a \ https://api.razorpay.com/v1/orders -X POST \ --data "amount=50000" \ --data "currency=INR" \ --data "receipt=Receipt #20" \ --data "payment_capture=1" https://api.razorpay.com/v1/orders

{ "amount": "5000", "currency": "INR", "receipt": "Receipt #20", "payment_capture": "1" }

Headers: Authorization:Basic cnpwX3Rlc3RfWEk5QW5TU0N3RlhjZ0Y6dURjVThLZ3JiQVVnZ3JNS***U056V25J where "cnpwX3Rlc3RfWEk5QW5TU0N3RlhjZ0Y6dURjVThLZ3JiQVVnZ3JNS***U056V25J" is the encoded form of "rzp_test_26ccbdbfe0e84b:69b2e24411e384f91213f22a"`

small tip: for encoding, you can easily go to your chrome console (right-click => inspect) and type : btoa("string you want to encode") ( or use postman basic authorization)

Shekhar
  • 365
  • 4
  • 10
0

As per the above answers, it works well.

If we paste curl requests with Authorization data in import, Postman will set all headers automatically. We only just pass row JSON data in the request body if needed or Upload images through form-data in the body.

This is just an example. Your API should be a different one (if your API allows)

curl -X POST 'https://verifyUser.abc.com/api/v1/verification' \
    -H 'secret: secret' \
    -H 'email: user@gmail.com' \
    -H 'accept: application/json, text/plain, */*' \
    -H 'authorizationtoken: bearer' \
    -F 'referenceFilePath= Add file path' \
    --compressed
djm.im
  • 2,652
  • 3
  • 24
  • 40
akshay_sushir
  • 657
  • 4
  • 7