skip to Main Content

I’m currently learning to use REST API (from WooCommerce in this case) and got some basic questions:

How to see complete request string in Postman software?
I’m testing a simple GET request which works great with for example:

<host>/wp-json/wc/v3/products

to receive the product list. In this case I use the authorization tab to enter my user/pass as Basic Auth.
I also tested curl.exe using another simple Windows command prompt. This also returned product list:

curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret

What is the difference between them? The last example is a simple GET, i assume, although it’s not stated. How about POST or DELETE etc? This is what i don’t understand: A https request can only have an address and eventual parameters. Where and how does "GET" come into the picture?!
If possible, I would like the see the complete URL request (as one string) from the working Postman example?

My last question is about testing the same method on another server/service which is not WooCommerce. Afaik this service is created with something called swagger:

curl "<host>/orderapi/item" -H "accept: application/json" -H "X-Customer: <customer>" -H "X-ApiKey: <mykey>" -H "X-ApiSecret: <mysecret>" -H "Content-Type: application/json"

This also returns a list of, in this case orders instead of products. All good.

But for this example I haven’t figured out how to achieve the same request in Postman. What auth method should I use?
And again, I don’t understand the GET/POST/DELETE thing. And I also would like to see the complete request as one-string.

2

Answers


  1. 1) How to see complete request string in Postman software? I would like the see the complete URL request (as one string) from the working Postman example

    On version 9.x.x:

    The code window(image) shows the choosen method (yellow mark) and the code window(red arrow), where you get the actual
    curl code(image)

    2) What is the difference between them? The last example is a simple GET, i assume, although it’s not stated. How about POST or DELETE etc? Where and how does "GET" come into the picture?

    From the curl documentation:

    -X, –request

    (HTTP) Specifies a custom request method to use when communicating
    with the HTTP server. The specified request method will be used
    instead of the method otherwise used (which defaults to GET). Read the
    HTTP 1.1 specification for details and explanations. Common additional
    HTTP requests include PUT and DELETE, but related technologies like
    WebDAV offers PROPFIND, COPY, MOVE and more.

    GET is the default method for curl, which means:

    curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret
    

    is the same as:

    curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret -X "GET"
    

    so, for a POST/DELETE/… you should change your ‘-X’ parameter for example:

    curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret -X "POST" [...otherOptions]
    

    (Assuming that you can receive a POST on the url above)

    3) [On another server/service] I haven’t figured out how to achieve the same request in Postman. What auth method should I use?

    The -H specify the header parameter you are passing. You have those in your example:

    • accept: application/json
    • X-Customer:
    • X-ApiKey:
    • X-ApiSecret:
    • Content-Type: application/json

    You need to add those in your postman on the headers(image) tab. In this case you don’t need to specify a auth method, once you’re sending the ApiKey on the header. In addition to that, you can specify the authorization Type to be "Api Key" and put X-ApiKey as key and your apikey value on the value field(image). It’ll generate the same request as shown in the headers image.

    Login or Signup to reply.
  2. curl, at least the GNU one on Linux, uses GET method by default. If you want to change a HTTP method in your request, there’s -X option, for example:

    $ curl -X DELETE https://example.com
    

    Postman has something called Postman Console which you can open by pressing Alt + Ctrl + C:

    enter image description here

    and where you can see more details about requests and responses.

    Postman also lets you import curl commands, so you don’t need to manually prepare the request, you can only paste the curl command in Postman.

    There are many resources online on the specifics, e.g. how to import a curl command.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search