Shopify
The Shopify example solution showcases how to connect a Teneo solution with the Shopify REST API. The example flows in the solution demonstrate how products can be retrieved as well as how to filter, create, update or delete products on Shopify.
Solution contents
Shopify integration
The solution contains a Shopify backend integration containing methods for authentication, retrieval of products as well as for filtering, creating, updating and deleting products. Since the source code of the integration is embedded in the solution, it can be easily extended or used as a starting point for new methods.
Example flows
For each core method in the Shopify integration, the solution contains a corresponding example flow:
- User asks to retrieve products from Shopify app
- User asks to filter products by status
- User asks to create a product in Shopify
- User asks to update product in Shopify app
- User asks to delete product from Shopify app
- Bot asks an user to login into Shopify
- User asks to logout from Shopify
Authentication flow
Shopify provides a support for OAuth authentication, API token based authentication and basic authentication methods that allow a Teneo bot to interact with Shopify on the user's behalf. Which authentication method to use depends on factors like use case and channel. This example solution contains flow to demonstrate API token based authentication approach.
Getting started
Prerequisites
These instructions assume you have a Shopify admin account. Alternatively, you can signup for a free user account on Shopify.
These instructions assume you have downloaded and imported the Shopify solution. See instructions below.
Create a Shopify free trial account and a private application
It's time to create a private app in Shopify portal in order to perform and experience some CRUD operations by using Shopify Teneo bot
- Using your administrator account, log in to your Shopify portal.
- After login, Click on Apps menu located at the left side menu panel of Shopify portal
- Click on Manage private apps link located in the bottom most section of page
- Click on Enable private app development button and select the check-boxes as applicable and click on 'Enable private app development' button one more time
- Click on 'Create private app' button and enter a Private app name and Emergency developer email as you wish.
- Expand the 'Admin API permissions' window and change the settings for 'Orders' and 'Products' to Read and write.
- Choose 'Webhook API version' as 2021-04.
- Select a checkbox 'Allow this app to access your storefront data using the Storefront API' and select everything underneath
- Click on Save button and then click on the 'Create app' button
- Copy the private app access credentials such as API key, Password, URL (URL alone copied from your registered email inbox) and store it securely as this requires for you to login to Shopify Teneo bot to perform various operations
- Your Shopify merchant store app setup is completed now
Add credentials to your solution
The solution contains a global variables Shopify_sPassword, Shopify_sAPIKey and Shopify_sInstanceEndPointUrl in which various credentials we have collected should be stored. We’re interested in our instance password and API key. People may try to use their Shopify password and API key accordingly. The value of the global variable should be a type of String like this:
Variable Name | Example value | Description |
---|---|---|
Shopify_sPassword | shppa_bdxxxxxxxxefbc1xxxxxxxx717xxx | Shopify API private app password. |
Shopify_sAPIKey | 70fxxxxxxx3aa8xxxxxxxxx5eb | Shopify private app API key. |
Shopify_sInstanceEndPointUrl | https://xxxxxxxxxxxx.myshopify.com | Base URL of Shopify instance end point. |
To update the global variables, proceed as follows:
- In a text editor, update each of above global variables by pasting in the values you have collected in the steps above.
- In your Shopify solution, click the 'Solution' tab and select 'Globals' in the purple navigation bar.
- Select the 'Variables' tab at the top, select the variables called Shopify_sPassword, Shopify_sAPIKey and Shopify_sInstanceEndPointUrl.
- In the panel on the right, click 'Edit'. You can now update the value of the variable by pasting the updated string values.
- When done, click 'Save All' in the top left corner.
Test in Try Out
Your solution is now ready. You can test this in Try Out by asking I want to login
followed up with I need to retrieve products from Shopify app
. The Teneo bot would then provide the products list, which are available in your Shopify portal.
Example conversations
User: I want to login
Bot: Hi there! I'm a Shopify Connector virtual assistant from Artificial Solutions.
Bot: Please enter an API key provided by Shopify.
User: 70fxxxxxxx3aa8xxxxxxxxx5eb
Bot: Please enter a password.
User: shppa_bdxxxxxxxxefbc1xxxxxxxx717xxx
Bot: Please enter an instance url provided by Shopify. Example :https://xxxxxxxxxxxx.myshopify.com
User:https://xxxxxxxxxxxx.myshopify.com
Bot: Hi there! Your login has been successful!
User: Can I create a product in shopify app
Bot: Please enter the title of product.
User: Test product
Bot: Please enter the description of product.
User: This is a test product for the connector.
Bot: Please choose one of the following product statuses, Active or Draft
User: Active
Bot: New product #56749433 has been created in your Shopify merchant store app successfully.
User: I need to retrieve products from Shopify app
Bot: Below are list of products available in your Shopify merchant store app. 56749433, 56749434, 56749435
User: Can I filter products by status
Bot: Please choose one of the following product statuses, Active, Draft or Archived
User: Draft
Bot: Below are list of products available in your Shopify merchant store app for chosen filter criteria. 56749434, 56749435
User: I want to update a product in Shopify app
Bot: Please choose one of the following product id, Test product - 56749433, Second test product - 56749434, Thirds test product - 56749435
User: 56749433
Bot: Please choose one of the following product fields. Title, Description, Status
User: Title
Bot: Please enter a title.
User: First test product
Bot: Title field has been updated in product 56749433 successfully!
User: Can I delete a product from Shopify app
Bot: Please choose one of the following product id, Test product - 56749433, Second test product - 56749434, Thirds test product - 56749435
User: 56749435
Bot: Shopify product 56749435 has been deleted successfully!
User: I want to logout
Bot: Your logout has been successful!
More on authentication
Shopify offers multiple authentication methods including OAuth authentication, Basic authentication, API token key based authentication by using password and API key that developers can use to allow their users to authenticate with Shopify. Which authentication flow to use depends on the type of application and the use case.
This Shopify solution contains a flow called 'Bot asks an user to login into Shopify'. This flow is responsible to set a value of global variable called Shopify_bHasUserLoggedIn which is included at the beginning of each other flows that checks the user's authentication to access the flows. This flow checks if the global variables Shopify_sPassword, Shopify_sAPIKey and Shopify_sInstanceEndPointUrl contains an values which is needed to perform API requests. If the Shopify_bHasUserLoggedIn variable is false, this flow answers an user authentication failure message.
By default, the Shopify 'Bot asks an user to login into Shopify' flow uses the stored credentials from global variables to authenticate the user. This flow uses Shopify's API key based authentication mechanism, which provides instructions in the getting started section on this page explain how to prepare your solution using this authentication approach.
This authentication uses stored credentials from global variables Shopify_sPassword, Shopify_sAPIKey and Shopify_sInstanceEndPointUrl to prepare an authentication with Shopify and it generates a Base64 encoded authorization header value on another global variable Shopify_sBasicAuthToken and checks an access against Shopify instance URL stored on Shopify_sInstanceEndPointUrl and return a successful authentication. The value generated for global variable Shopify_sBasicAuthToken looks like this:
Variable Name | Example value | Description |
---|---|---|
Shopify_sBasicAuthToken | 'Basic Qwtr3exxxxxxxxx84dg45vxs' | Basic auth token (Base64 encoded) to access Shopify resources via REST API |
This Base64 encoded value is then stored in the global variable Shopify_sBasicAuthToken, so it can be used for subsequent requests that require authentication across flows in the Shopify solution. The global variable is used by the Shopify integration for the various REST requests.
The solution uses the stored credentials approach by default, mostly because it is easiest and quickest to get started. However, because this authentication flow passes the user’s credentials back and forth it is advised to use this authentication method for development purposes only. Additionally, using stored credentials means that all objects created by the bot are created by the same user. Therefore, it might be preferred to implement an authentication flow that enables Teneo to interact with Shopify on the user's behalf.
However, this authentication flow can still be used in production grade only when a front-end connector or a channel connector supplies necessary user credentials instead of hard coding them in Teneo in a more secured way by using any industrial standard encryption techniques.
The authentication flow for the API Key based authentication in combination with Teneo roughly looks like this:
Download
- Download the solution here.
- Import the solution into Teneo. For more details see: How to import solutions.