CURL to POSTMAN

1k views Asked by At
$ curl https://api.blockscore.com/question_sets/536c1532627463780b000000/score \
  -u sk_test_n5049aa6053c9a0217bea78070fbf501: \
  --header "Accept: application/vnd.blockscore+json;version=4" \
  -d 'answers[][question_id]=1' \
  -d 'answers[][answer_id]=3' \
  -d 'answers[][question_id]=2' \
  -d 'answers[][answer_id]=2' \
  -d 'answers[][question_id]=3' \
  -d 'answers[][answer_id]=2' \
  -d 'answers[][question_id]=4' \
  -d 'answers[][answer_id]=2' \
  -d 'answers[][question_id]=5' \
  -d 'answers[][answer_id]=5'

how to set this parameters in getpostman?

what is equivalent of -u, --header, -d?

1

There are 1 answers

0
Paul Samsotha On BEST ANSWER

The default Content-Type in cURL is application/x-www-form-urlencoded. In Postman, you can just select the x-www-form-urlencoded button and start typing in your key value pairs, i.e.

            Key                 Value
    answers[][question_id]         1

For --header, there's a Headers button at the top right. When you click it, you will see fields to type in header value pairs also. Just type Accept on the left, and the type value on the right.

          Header                       Value
          Accept     application/vnd.blockscore+json;version=4

The default authentication is Basic for cURL. When you do -u username, you get prompted for the password. This is to protect against any shell storage of the password. You could alternatively use -u username:password, but this will store the password in the shell history, and is not recommended. Either way, cURL will set the Authorization header to Basic base64encode(username:password).

You need to actually base64 encode username:password. There are online places you can do so, like here. For example if you type in username:password then encode it, it will return dXNlcm5hbWU6cGFzc3dvcmQ=

So basically, in Postman, you should set a header Authorization as the name, then Basic dXNlcm5hbWU6cGFzc3dvcmQ= (that is if the username is username and the password is password). Yours will be different of course.

          Header                       Value
       Authorization       Basic dXNlcm5hbWU6cGFzc3dvcmQ=