Level Of Difficulty: Intermediate
Welcome to this tutorial where you will learn how to perform authentication with API requests that require it.
For this demonstration let’s use the Shopify API as an example.
Shopify is one of the most popular E-Commerce store creation platforms and has an advanced API which allows users to control all aspects of their stores.
Here’s an example Shopify store created for this demonstration:
and here is the Shopify Developer’s page where the complete Shopify API is thoroughly documented. You can access the Shopify API by visiting this page.
The first objective is to understand how the API works and how to authenticate a request.
To do this let’s head over to the Concepts dropdown menu and select ‘Using Shopify APIs’, followed by the Authentication option. Here’s a link to this page.
As you can see there are two types of authentication, OAuth and Basic HTTP Authentication.
For this example, select the Basic Authentication option.
As you can see below, it is stated that authentication will require the generation of a set of credentials.
This needs to be done through the Shopify store’s admin panel.
To do this, let’s head over to the Shopify store and click on the Apps option in the sidebar menu.
On this page scroll down and click on the Manage private apps link.
This is the page where you can generate the credentials required for Basic HTTP Authentication.
Let’s click on ‘Create New Private App’.
As the Private app name let’s enter Integromat (this can be anything you like). And for Emergency developer email enter your email.
Below you can select the permissions that the authenticated client will have when performing an API request to this store. For this example let’s give ‘Read and Write’ access to the customers option. This provides access to all the customer data stored inside the Shopify store.
Click save to generate the credentials. As you can see the credentials have been generated.
Now, let’s create a new Integromat scenario and begin setting up an HTTP request.
Let’s add the HTTP app to the scenario and as a module select Make a Basic Auth Request.
This module is required because a request to a Shopify API endpoint requires Basic Authentication.
This module is very similar to the ‘Make a request‘ module, however at the top there is an extra field called Credentials. This is where the credentials generated from the Shopify account will be pasted in.
To add these credentials let’s click on the Add button. Let’s enter a key name ‘Shopify Account’.
and then in the username field you need to paste the API key from your Shopify API credentials. Similarly paste the password from your Shopify API credentials to the password field.
Click on ‘Create a key‘ to proceed.
Now this request will be authenticated. Next, let’s setup the request endpoint and parameters.
For this information let’s head over to the Shopify API documentation and this time click on the Docs option on the menu and select Admin API followed by REST reference.
On this page you will be presented with a breakdown of the complete API that allows you to control every aspect of your Shopify store. For this demonstration, let’s select the ‘Customers’ option from the sidebar and then select ‘Customer’ from the dropdown.
This page features all the information regarding the API request that can be made to the customer data on the Shopify store. Let’s scroll all the way down to the Endpoints section. Here you can see the endpoints that requests can be performed to.
The first endpoint with request method GET is used to retrieve all the customers that are currently stored in the the Shopify store’s database as well as all their data. Let’s make this request inside Integromat.
However, this URL is incomplete. There is an important element missing. This is the store’s subdomain which needs to be added at the beginning on every API request. This store’s subdomain can be found at the URL of the Shopify store.
The next step is to select the request method, which as seen earlier is of type GET. Finally, it is important to parse the response of this request so the data retrieved is automatically converted to an Integromat-friendly format that can be mapped to other modules.
Now, let’s save this scenario and execute is once! If everything works correctly this request should be successfully authenticated and all the customer data should be retrieved.