Use Thunder Client (VS Code) instead of Postman !

For years I have been using Postman in order to get information about my XC environments and data. And for years I have been tired of this memory-hungry elephant where I just needed a simple REST client.

It looks like that, unlike U2, I have now found what I’m looking for šŸ™‚

The solution is a Visual Code Extension called Thunder Client. Easy to install, just search for it in the Marketplace, or install it from its website

The resultat of the installation is a new circle icon in the list of extensions.

It looks like the authors of this extension tried to mimick the way we use to work in Postman, as we have the same concepts of Collections and Environments.

How can I use XC Postman collections in Thunder Client ?

Basically, you can import Environments and Collections the same way you did with Postman, with the same files provided by Sitecore in Sitecore Commerce Engine SDK

To import an environment file, click on “Env”, then on the menu (the three horizontal lines under “Env”) and choose “Import”.

Here I chose to import “Habitat Environment.postman_environment.json”

It worked great !

We can also import Collections the same way. Click on Collections and choose “Import” in the menu.

CatalogAPISamples and CartAPISamples are the one that I tested and they imported without problem.

But Authentication.postman_collection didn’t work. I got a message “Failed to Import”.

As this one is fairy important to have in our environment, let’s create it manually. You can also download my own version here.

Let’s create a new collection called Authentication, and as it should be in Sitecore’s own postman collection, we’ll have a folder Sitecode and a request called “GetToken”.

While the menu Collections is highlighted, click on the side menu and choose “New Collection”

Name your new collection “Authentication”. It is created in the list of collections.

Create a folder “Sitecore” right under it.

And create a New Request called GetToken under the Sitecore folder.

Change the method, URL, Headers and Body for this GetToken request as they appear in Postman

Make sure you add the parameters in Body/Form-encode

Now if you have correctly updated your environment, clicking on Send should get a new token from Sitecore.

In order to save this token to the environment variable SitecoreIdToken, click on the tab called “Tests” and add

Now when you do a GetToken request, the resulting token is saved in the variable SitecoreIdToken.

Let’s now test some API that we just imported from Sitecore. Let’s begin with listing all the SellableItems (request in CatalogAPISamples/Catalog – API/Sellable Items). Open it and click on Send.

Unfortunately, we have an error

Looking in the headers, we see that we try to create a header called “Authorization” with the variable {{SitecoreIdToken}}. As it works in Postman, the way to authorize a request in Thunder Client is to use the “Auth” tab. We need to write this SitecoreIdToken in the Bearer tab of Auth.

It is now working !

So to use an imported Postman request, just add a Bearer Authentication with the bearer token {{SitecoreIdToken}}.

As an example, I have converted all the REST APIs for CatalogAPISamples.

Happy RESTing !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: