Sammy
Sammy

Reputation: 953

Convert cURL to Postman REST Call

How can I convert the following cURL command to a Postman rest call?

curl -X POST abc.com/input.import 
        -H 'content-type: application/x-www-form-urlencoded'
        --data-urlencode "apiKey=123-456"
        --data-urlencode "secret=12/her"
        --data-urlencode "userKey=ApUR"
        --data-urlencode "[email protected]"
        --data-urlencode "profile={'firstName':'John','lastName':'Kira'}" 

I tried the following:

URL: (POST) abc.com/input.import

Header: Content-Type:application/json

Body:

{
    "apiKey":"123-456",
    "userKey":"ApUR",
    "secret":"12/her",
    "email":"[email protected]",
    "profile": {
        "firstName":"John",
        "lastName":"Kira"
    }
}

EDIT: Raw-body format in Postman is required. Import creates the request in "x-www-form-urlencoded" form

Upvotes: 22

Views: 31529

Answers (3)

Vladyslav
Vladyslav

Reputation: 1

--data-urlencode means that this is a query parameter

In the image you can see an example of how this can be done in postman

Also, if you do not use the query body, then you do not need to change the coding of that query body

Upvotes: 0

Paul Samsotha
Paul Samsotha

Reputation: 208944

The content-type is not application/json, it's application/x-www-form-urlencoded. What you need to do is in the body tab, select application/x-www-form-urlencoded. The content-type header will automatically be set for you. The just start adding the key/value pairs (the --data-urlencoded arguments)

enter image description here

UPDATE

Unrelated, but for those looking for a way to post JSON (which is very common), you would use the "raw" radio button and then you would manually type in the JSON to the window they provide. Also you would set the Content-Type header to application/json.

Upvotes: 33

Sammy
Sammy

Reputation: 953

I finally found: I have to url-encode every key value and send it with Content-Type:application/x-www-form-urlencoded.

Header:application/x-www-form-urlencoded Body:

{
  "apiKey":"123-456",
  "userKey":"ApUR",
  "secret":"12%2Fher",
  "email":"fakeImportedAccount%40example.com",
  "profile":{
     "firstName":"John",
     "lastName":"Kira"
  }
}

Upvotes: -1

Related Questions