Home SalesforceIntegration How to Seamlessly Integrate Shopify with Salesforce

How to Seamlessly Integrate Shopify with Salesforce

by Dhanik Lal Sahni
Salesforce Shopify Integration - Salesforce

Shopify is an excellent platform to start an e-commerce business with ease. It provides tools and features for setting up a website, managing products, processing payments, handling shipping, and tracking sales. Businesses also want to track Shopify orders in Salesforce to provide better customer service to the customer. For this, we have to sync Shopify orders into Salesforce. This post will explain how to integrate Shopify with Salesforce CRM seamlessly.

We can integrate Shopify with Salesforce using Apex REST API to manually sync Shopify orders and other related records or set up a webhook in Shopify to notify newly created data to Salesforce. We have another post-Shopify integration with Salesforce using Webhook that shows how to integrate Shopify and Salesforce using Webhook. This post will integrate Shopify using REST API callout in Salesforce.

Use Case to Integrate Shopify with Salesforce

We want to sync Shopify products into the Salesforce Product object. Records should be synced daily to update quantity information.

Solution

To handle the above requirement we will follow the below steps and Integrate Shopify with Salesforce.

  1. Setup Shopify and get API Credential
  2. Setup Named and External Credentials in Salesforce
  3. Prepare a Custom Object for the Product Sync
  4. Create Apex Class to Integrate Shopify
  5. Test Functionality

1. Setup Shopify and get API Credential

We need an API credential to integrate Shopify into Salesforce. We can get these details from Shopify Admin. If you want to set up yourself then follow these steps in Shopify.

1. 1 Create a Developer App in Shopify

Open Shopify admin and go to the settings page. Select Apps and sales channels menu to open the App creation page.

Shopify App Creation for Salesforce Integration - Salesforce Shopify Integration

Click the Develop Apps button to create a new application for Salesforce integrations. Click Create an app button to create a new Salesforce integrations app.

Shopify App Creation for Salesforce  -  Shopify Salesforce Integration

1. 2 Setup Admin Access

Once the App is created, open its configuration page. We will provide access to this app so that Salesforce or any third-party application can retrieve records. As we need to get all products, we will provide access to read_products API access. Similar to this we can provide multiple API access in the same app,

Shopify Admin Access for Salesforce Integration- Salesforce Shopify

1.3 Get Admin Access Key

Create an admin access key from the API credential tab of the app. Once Admin access is created, scroll down to the same tab page to see the Admin API credential.

Shopify Admin Key for Salesforce Integration

2. Setup Named and External Credentials in Salesforce

Salesforce’s Named Credentials securely store and manage authentication credentials for external services or endpoints. Let us create a Named Credential and External Credential for the Shopify API.

Create an External Credential in Salesforce

External Credentials hold authentication protocols, authentication parameters and permission set-related information for calling external systems. Let us create an external credential Shopify EC(ShopifyEC) for the Shopify System.

External Credential in Salesforce - Integrate Shopify with Salesforce

We will use admin credentials to connect Shopify API. Admin key will be stored in External Credential as an Authentication parameter. We also need to create a Principal that will be used to assign external credentials in permission sets. Refer to our other post Accessing External Credential Parameters of Named Credential in Salesforce Apex to use authentication parameters.

External Credential Parameters in Salesforce - Integrate Shopify with Salesforce

Create Named Credential

Create a named credential Shopify Sync NC (ShopifySyncNC) and assign the above-created External Credential to it. Check Generate Authorization Header and Allow Formulas in HTTP Header in Callout Options to pass external credential parameters at runtime to callout.

Named Credential in Salesforce  -Integrate Shopify with Salesforce

Create a Permission Set and Assign it to yourself

Create a permission set Shopify User PS and add the above external credentials to the External Credential Principal Access section. Once the permission set is created assign this to the required user.

3. Prepare a Custom Object for the Product Sync

Create a custom object to Sync Shopify API into Salesforce Org. You can also sync API records into any existing custom object or standard object like Product2.

For this post, I have created a custom object named Shopify Products (ShopifyProduct__c) and below custom fields to store Shopify Information. You can create custom fields based on your requirements.

Field LabelField APIType
ActiveActive__cCheckbox
Product NumberNameAuto Number
DescriptionDescription__cRich Text Area
Product NameProductName__cText
Product TypeProductType__cText
VendorVendor__cText
TagsTags__cText

4. Create an Apex Class to Integrate Shopify API

Create an apex class ShopifyProductSyncService that will integrate Shopify API in Salesforce. The complete code for this class is added below. We can also add the apex class ShopifyProductSyncController to provide an invocable method. This method can be called from Flow Action.

We can also use a generic apex class to connect any Shopify system. You can refer generic code from the post Generic Apex class for Calling External System.

I have used the ApplicationException class to log any runtime exception. You can check our post Exception Logging in Custom Object : Salesforce Apex to learn about logging exceptions in custom objects. You can use your architecture to log runtime errors to manage integration.

As product sync should be a daily activity, you can set up this class as a scheduled class and run it regularly.

Test Functionality

You can test the above-created apex class using Screen Flow or Apex execution. I have called the above class from another class and can sync product records.

Shopify Synced Records in Salesforce

References

Shopify Product API

Shopify REST API Authentication

Related Posts

Shopify integration with Salesforce using Webhook

Accessing External Credential Parameters of Named Credential in Salesforce Apex

Generic Apex class for Calling External System

Download S3 File in Salesforce using AWS Signature Version 4.0

Use Named Credential to Upload File in S3

Displaying Tabular Data with GraphQL in Lightning Web Component

 Automating data synchronization between Salesforce and Amazon Seller

Need Help?

Need some kind of help in implementing this feature, connect on my LinkedIn profile Dhanik Lal Sahni.

You may also like

Leave a Comment