ABSYZ ABSYZ

  • Home

    Home

  • About us

    Who We Are

  • Our Expertise

    What we Do

  • Our Approach

    How We Do It

  • Products

    What We Made

  • Industries

    Who We Do It For

  • Clients

    Whom We Did It For.

  • Article & Blogs

    What Experts Think

  • Careers

    Join The Team

  • Get In Touch

    Let’s Get Started

ABSYZ

Integration of Salesforce with Shopify Application

Home / Article & Blogs / Salesforce / Integration / Integration of Salesforce with Shopify Application
By Team ABSYZ inIntegration, Salesforce

Hi All,

This Blog gives a small demonstration  on how the process happens in integration of Shopify app with Salesforce. We can use SOAP API or REST API based on your requirement.

Here I am using REST API for integration.

For integration with Shopify app we cannot use Oauth authentication. As shopify does not allow Oath as an authentication mechanism hence we can not use Oauth here.

Shopify app is mainly used for selling the products it is similar like Amazon. To sell the products in shopify we need to have a store in shopify. Integration between salesforce and shopify will be possible if we have a store in shopify.

What is a store? Store is a place where we can sell our products exclusively. To create store in shopify visit this link https://www.shopify.in/online-store Here there are mainly two versions one is a free version which you can use for testing this functionality and the second one is a paid one.

Shopify store image is displayed below.

Shopify store page

To fetch data from shopify app we need to have an Access token and Password. To Generate an Access Token and Password we need to create a private app in shopify to access our store data.

Creating Private App:

Click on the tab “Apps”

Apps Page

Click on Private Apps button on the top right corner then private app page will be seen.

Private app

Click on ‘Create Private App’ button and the private app creation page will be opened.

Private App creation Page

Fill the Title field with any name the title will be your app name and email is an optional field on filling the details click on Save app. Then private app detail page is opened.

Private App detail Page

On the above image you can see API Key and Password. Example URL in the above image is used in HTTP requests to fetch the data from the shopify app.

The Example URL format: https://apikey:password@hostname/admin/data.json

Place your shopify store URL in “Remote site settings” in Salesforce.

Go to salesforce and click on setup-> Security Controls -> Remote Site Settings. Click on New Remote Site and give any name and paste the shopify store URL and click on Save.

To fetch the data from shopify app we need to create a certificate in salesforce org.

Why to create a salesforce certificate? Shopify will connect with the trusted sites and to make salesforce as trusted site we need to create a certificate.Certificate is added with a HTTP header and sent as a request. Then shopify accepts the certified requests and send us the data.

How to Create a Certificate:

Go to salesforce and click on setup-> Administrative setup section-> security Controls-> Certificate & Key Management->create self signed certificate. Fill the label and save it.

Here for integration with shopify app i used a VF page and controller. On clicking the button in VF page, the whole shopify data is fetched into the salesforce org by using HTTP requests. Here we are hitting shopify with the Example URL , API key and password. The method used in HTTP Requests is GET method. So it will fetch the data from the shopify and the certificate we created on the top is used as “req.setClientCertificateName(‘Shopify’)” .

Shopify in the above line is the certificate name which i created and you need to give the certificate name that you created.

The data that is fetched from HTTP requests are in JSON format. To convert JSON format to normal format we use json.deserialize() method. Once you receive the data from deserialize method we can map it to the salesforce objects. So once you complete the whole process, data from shopify will be fetched and you can use this data in salesforce.

The functionality may change a bit if we are integrating with other apps but the HTTP Callouts and the deserializing functionality will be same for integration with any third party application.

To know more about HTTP request visit this link: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_httprequest.htm%23apex_System_HttpRequest_methods

This is the Visualforce page and Controller code:

[sourcecode language=”java”]

// Visualforce Page code

<apex:page controller=”shopifycontroller”>
<apex:form>
<apex:commandButton value=”getShopifyData” action=”{!retrieveGoogleAccessToken}”/>
</apex:form>
</apex:page>

//Controller Code

public class shopifycontroller {
public void retrieveGoogleAccessToken() {
//Local Variables
string ResponseBody;
//Making Callouts using HTTP Requests
Http h = new Http();
HttpRequest req = new HttpRequest();
//Provide URL of the Shopify store to HTTP requests
String url = ‘https://xxxxxx.myshopify.com’;
string endPointValue = url + ‘/admin/orders.json’;
req.setEndpoint(endPointValue);
//Adding certificate to HTTP Requests
req.setClientCertificateName(‘Shopify’);
//Providing Username and Password
String username = ‘xxxxxxxxxxxxxxxxxxxxxx’;
String password = ‘xxxxxxxxxxxxxxxxx’;
Blob headerValue = Blob.valueOf(username + ‘:’ + password);
String authorizationHeader = ‘Basic ‘ +
EncodingUtil.base64Encode(headerValue);
req.setHeader(‘Authorization’, authorizationHeader);
req.setHeader(‘content-type’, ‘application/json’);
//Use get Method as we are retrieving data from shopify
req.setMethod(‘GET’);
try {
HttpResponse res = h.send(req);
ResponseBody = res.getBody();
} catch (exception e) {
System.debug(‘exception’ + e);
}

// Parse entire JSON response.

JSONParser parser = JSON.createParser(ResponseBody);
while (parser.nextToken() != null) {
// Start at the array of Orders.
if (parser.getCurrentToken() == JSONToken.START_ARRAY) {
while (parser.nextToken() != null) {
// Advance to the start object marker to
// find next Order statement object.
if (parser.getCurrentToken() == JSONToken.START_OBJECT) {
Orders ord = (Orders) parser.readValueAs(Orders.class);
// For debugging purposes, serialize again to verify what was parsed.
String serializeData = JSON.serialize(ord);

// Skip the child start array and start object markers.
parser.skipChildren();
}
}
}
}
}
// Inner classes used for serialization by readValuesAs().

public class Orders {
public Double total_price;
public DateTime created_at;
public string email;
public Orders(Double price, DateTime dt, string em) {
total_price = price;
created_at = dt;
email = em;
}
}
}

[/sourcecode]

Please post your comments or inputs if you feel this blog is helpful.

APPOAUTHRESTShopifySOAP
108
Like this post
127 Posts
Team ABSYZ

Search Posts

Archives

Categories

Recent posts

All About The OmniStudio FlexCards

All About The OmniStudio FlexCards

Boost Customer Experience With Repeater Widget in CRM Analytics

Boost Customer Experience With Repeater Widget in CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics

Net zero as a Service In CPG Industry

Net zero as a Service In CPG Industry

How Do We Import an External Library into Salesforce Lightning?

How Do We Import an External Library into Salesforce Lightning?

  • Previous PostCombining RESTful Web Services and Site.com for creating publicly asccessible URL
  • Next PostWave Analytics

Related Posts

All About The OmniStudio FlexCards
OmniStudio Salesforce

All About The OmniStudio FlexCards

Boost Customer Experience With Repeater Widget in CRM Analytics
CRM Analytics Salesforce

Boost Customer Experience With Repeater Widget in CRM Analytics

Enhance Insights Using Custom Tooltips In CRM Analytics
CRM Analytics Salesforce

Enhance Insights Using Custom Tooltips In CRM Analytics

How Do We Import an External Library into Salesforce Lightning?
Lightning Salesforce

How Do We Import an External Library into Salesforce Lightning?

14 Comments

  1. bharathkumar
    Reply
    4 January 2017

    I have tried it and it does not work. It is giving an unauthorised & 401 error.
    JSONParser parser = JSON.createParser(s); –> should be responsebody instead of ‘s’

    Reply
    • Raviteja Vaddi
      Reply
      4 January 2017

      Thanks for your input

      Reply
  2. cropredy
    Reply
    25 January 2017

    I’m a bit confused by the use case. How does this apply to an order in the Shopify store passing into Salesforce as an Order object?

    Reply
  3. Raviteja Vaddi
    Reply
    3 February 2017

    No we need to parse using json parser and insert order with the details

    Reply
  4. Raviteja Vaddi
    Reply
    3 April 2017

    Sorry i don’t know much about marketing cloud.

    Reply
  5. Md Riaz
    Reply
    4 June 2017

    I am geting an Error
    “errors”:”[API] Invalid API key or access token (unrecognized login or wrong password)
    Even though it is working with Browser

    Reply
  6. Andrew
    Reply
    23 August 2017

    Is the connection to Salesforce in real time? Or will they need to manually request the data from Shopify?

    Reply
    • Raviteja Vaddi
      Reply
      28 August 2017

      Yes it is in real time. Shopify is having a feature called WebHooks. So on different events in Shopify they will call the webhooks related to that event. So they can get the data from salesforce or they can transfer the data to salesforce.

      Reply
  7. YK
    Reply
    16 March 2018

    I am getting “Invalid API key or access token [unrecognized login or wrong password]” with this approach. The URL works fine in the browser with given credentials. Ever faced this issue?

    Reply
  8. techpower4
    Reply
    20 March 2018

    Hi, Raviteja. I just followed your post it worked every well. Now I have to implement to get data from shopify using batch apex and scheduled it for every one hour.

    Reply
  9. Dheeraj
    Reply
    27 March 2018

    I followed the steps provided by you by creating trial account in shopify. I’m getting response as below
    HttpResponse[Status=Unauthorized, StatusCode=401].
    Could you please help me on this.

    Reply
    • Dheeraj
      Reply
      27 March 2018

      For username and password i given site username and password.That’s the reason for getting response as unauthorized.
      Now i provided api key and password, it’s working. Thank you.

      Reply
  10. Langlais
    Reply
    12 June 2018

    Hi, I don’t have the refresh button on the Salesforce shopify site with trial version, it’s normal?
    Thank you

    Reply
  11. Jeys
    Reply
    27 March 2019

    Hi i followed th step that you mentioned and i got this error

    System.NullPointerException: null input to JSON parser
    Error is in expression ‘{!retrieveGoogleAccessToken}’ in component in page shopifydemo: Class.System.JSONParser.: line 5, column 1
    Class.System.JSON.createParser: line 23, column 1
    Class.shopifycontroller.retrieveGoogleAccessToken: line 33, column 1

    An unexpected error has occurred. Your solution provider has been notified. (System)

    Reply

Leave a Reply (Cancel reply)

Your email address will not be published. Required fields are marked *

*
*

ABSYZ Logo

INDIA | USA | UAE

  • About us
  • Article & Blogs
  • Careers
  • Get In Touch
  • Our Expertise
  • Our Approach
  • Products
  • Industries
  • Clients
  • White Papers

Copyright ©2022 Absyz Inc. All Rights Reserved.

youngsoft
Copy
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “ACCEPT ALL”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent. Privacy Policy
Cookie SettingsREJECT ALLACCEPT ALL
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled

Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.

CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.

Functional

Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.

Performance

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

Analytics

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.

Advertisement

Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.

Others

Other uncategorized cookies are those that are being analyzed and have not been classified into a category as yet.

SAVE & ACCEPT