Shopify Connector

Shopify Connector

Shopify is an ecommerce platform that allows users to set up an online store to sell their goods. With the Shopify connector for Zoho CRM you can sync data from the Orders and Customers modules of your Shopify store to Zoho CRM by writing custom functions and schedules in Zoho CRM.

Install Shopify Connector

You can either go to the Zoho Marketplace and install the Shopify Connector or log in to your Zoho CRM account and install.

  1. Click Setting > Setup > Marketplace All.
    All the installed extensions are listed. Under All Marketplace you can view all the extensions supported in CRM.
  2. Click All Extensions, browse through for Shopify Connector and click it.
    The details about the extension will be available.
  3. Click InstallNow.
  4. In the following screen, agree to the terms of service and click Install Now.
  5. Click Authorize.
    If you skip in this step, you can authorize the extension later from theShopify Connector Extension Details page.
  6. Specify the Shop Sub Domain of your Shopify account and click Save and Authorize.
    Your shop sub domain is the name you provided for your online store while creating your Shopify account.)
  7. Click Install APP.

Sync Shopify Data with Zoho CRM

After installing and authorizing the Shopify connector, you can create a custom schedule to integrate your shopify data with Zoho CRM every day, as needed. To learn more about creating schedules in Zoho CRM, read more.

Below is an example of a custom function used to add all of the newly created Customers in your shopify account as Contacts in Zoho CRM using the shopifyconnector.customer_after_a_certain_date API.,

domainmap=map();
currentDate=(zoho.currentdate.subDay(1)).toString("yyyy-MM-dd");
currentTime=zoho.currenttime.toString("HH:mm:ss");
requiredFormat=currentDate + "T" + currentTime + "-04:30";
domainmap.put(("updated_at_min"),requiredFormat);
respmap = zoho.crm.invokeConnector("shopifyconnectorextension.sophifyconnector.customer_after_a_certain_date",domainmap);
resp=(respmap.get("response")).toMap();
resp2=resp.get("customers").toJSONList();
info resp2;
for each index a in resp2
{
requiredMap=(resp2.get(a)).toMap();
firstName=requiredMap.get("first_name");
lastName=requiredMap.get("last_name");
if(!isNull(firstName)  &&  !isNull(lastName))
{
createMap=map();
accountMap=map();
createMap.put("First Name",firstName);
createMap.put("Last Name",lastName);
accountMap.put(("Account Name"),lastName + "_" + requiredMap.get("id"));
createMap.put("Email",requiredMap.get("email"));
createMap.put("Description",(("Your Shopify Customer Id is " + requiredMap.get("id")) + " and he accepts_marketing value is ") + requiredMap.get("accepts_marketing"));
default_addMap=map();
default_addMap=(requiredMap.get("default_address")).toMap();
if(default_addMap.size()  >  0)
{
city=default_addMap.get("city");
country=default_addMap.get(("country"));
country=default_addMap.get(("country"));
zip=default_addMap.get("zip");
province=default_addMap.get("province");
phone=default_addMap.get("phone");
accountMap.put("Billing City",city + "");
accountMap.put("Billing Country",(country) + "");
accountMap.put("Billing Code",zip + "");
accountMap.put("Phone",phone + "");
accountMap.put("Billing State",province + "");
createMap.put("Mailing City",city + "");
createMap.put("Mailing Country",(country) + "");
createMap.put("Mailing Zip",zip + "");
createMap.put("Phone",phone + "");
createMap.put("Mailing State",province + "");
}
createAccountResp=map();
createAccountResp = zoho.crm.create(("Accounts"),accountMap);
info createAccountResp;
createMap.put("ACCOUNTID",(createAccountResp).get("Id"));
crmCreateResp = zoho.crm.create("Contacts",createMap);
}
}

You can also add all new orders placed in Shopify store to the Invoice module of Zoho CRM using the following function:

domainmap=map();
currentDate=(zoho.currentdate.subDay(1)).toString("yyyy-MM-dd");
currentTime=zoho.currenttime.toString("HH:mm:ss");
requiredFormat=currentDate + "T" + currentTime + "-04:30";
domainmap.put(("updated_at_min"),requiredFormat);
resultMap = zoho.crm.invokeConnector("shopifyconnectorextension.sophifyconnector.order_after_a_certain_date",domainmap);
resp=(resultMap.get("response")).toMap();
requiredMap=map();
requiredList=resp.get("orders").toJSONList();
info requiredList.size();
for each index ordernumber in requiredList
{
    requiredMap=(requiredList.get(ordernumber)).toMap();
    subject=requiredMap.get("name");
    line_items=requiredMap.get("line_items").toJSONList();
    if(!isNull(subject))
    {
        line_items=requiredMap.get("line_items").toJSONList();
        prodList=List:Map();
        gtotal=0.0;
        //iterate listitems
        for each index a in line_items
        {
            invoiceMap=map();
            productMap=map();
            productRecordMap=map();
            linemap=(line_items.get(a)).toMap();
            quantity=(linemap.get("quantity")).toDecimal();
            price=(linemap.get("price")).toDecimal();
            unit_price=0.0;
            unit_price=price;
            prductid=linemap.get("product_id");
            if(isNull(prductid)  ||  prductid.equalsIgnoreCase("null"))
            {
                prductid="";
            }
            else
            {
                prductid="_" + prductid;
            }
            productMap.put("Product Name",(linemap.get("title")) + prductid);
            productMap.put("Unit Price",unit_price + "");
            //create product
            productRecordMap = zoho.crm.create("Products",productMap,2);
            line_productMap=map();
            line_productMap.put("Product Id",productRecordMap.get("Id"));
            line_productMap.put("Quantity",quantity);
            line_productMap.put("List Price",unit_price);
            line_productMap.put("Net Total",(quantity  *  price));
            prodList.add(line_productMap);
            gtotal=(gtotal  +  quantity  *  price);
        }
        //list item end
        invoiceMap.put("Subject",subject);
        invoiceMap.put("Products",prodList);
        invoiceMap.put("Sub Total",gtotal);
        invoiceMap.put("Grand Total",gtotal);
        customer=requiredMap.get("customer");
        customerrecordmap=customer.toMap();
        lastname=customerrecordmap.get("last_name");
        firstname=customerrecordmap.get("first_name");
        //search accountid of the customer
        customer_id=customerrecordmap.get("id");
        email=customerrecordmap.get("email");
        criteriafield="(Email|=|" + email + ")";
        criteriaMap=List:Map();
        if(!isNull(email))
        {
            criteriaMap = zoho.crm.searchRecords("Contacts",criteriafield);
        }
        contactmap=map();
        accmap=map();
        coMap=(customerrecordmap.get("default_address")).toMap();
        company=coMap.get("company");
        accmap.put(("Account Name"),company);
        acccriteriafield=(("(Account Name|=|") + company) + ")";
        info "company" + company + "sub" + subject;
        acc_criteriaMap=List:Map();
        if(!isNull(company))
        {
            acc_criteriaMap = zoho.crm.searchRecords(("Accounts"),acccriteriafield);
        }
        //create or update contact
        if(criteriaMap.size()  ==  0)
        {
            mymap=map();
            mymap.put("First Name",firstname);
            mymap.put("Last Name",lastname);
            mymap.put("Email",email);
            //create or update account
            if(acc_criteriaMap.size()  ==  0)
            {
                accountsmap = zoho.crm.create(("Accounts"),accmap,2);
                mymap.put("ACCOUNTID",(accountsmap).get("Id"));
            }
            else
            {
                accjson=acc_criteriaMap.toString().toJSONList();
                accjsonmap=(accjson.get(0)).toMap();
                mymap.put("ACCOUNTID",accjsonmap.get("ACCOUNTID"));
            }
            contactmap = zoho.crm.create("Contacts",mymap,2);
            invoiceMap.put("CONTACTID",contactmap.get("Id"));
            invoiceMap.put("ACCOUNTID",mymap.get("ACCOUNTID"));
        }
        else
        {
            json=criteriaMap.toString().toJSONList();
            contactmap=(json.get(0)).toMap();
            if(isNull(contactmap.get("ACCOUNTID")))
            {
                accountsmap=map();
                if(acc_criteriaMap.size()  ==  0)
                {
                    accountsmap = zoho.crm.create(("Accounts"),accmap,2);
                    contactmap.put("ACCOUNTID",(accountsmap).get("Id"));
                }
                else
                {
                    accountsjson=acc_criteriaMap.toString().toJSONList();
                    accountsmap=(accountsjson.get(0)).toMap();
                  contactmap.put("ACCOUNTID",accountsmap.get("ACCOUNTID"));
                }
                updateContact = zoho.crm.updateRecord("Contacts",contactmap.get("CONTACTID"),contactmap);
            }
            invoiceMap.put("CONTACTID",contactmap.get("CONTACTID"));
            invoiceMap.put("ACCOUNTID",contactmap.get("ACCOUNTID"));
        }
        info "invoiceMap==" + invoiceMap;
        //create or update invoice
        criteriafield="(Subject|=|" + subject + ")";
        criteriaMap = zoho.crm.searchRecords("Invoices",criteriafield);
        invoiceDate=requiredMap.get("updated_at");
        datestr=invoiceDate.getPrefix("T");
        invoiceMap.put("Invoice Date",datestr);
        if(criteriaMap.size()  ==  0)
        {
            criteriaMap2 = zoho.crm.create("Invoices",invoiceMap,2);
        }
        else
        {
            json=criteriaMap.toString().toJSONList();
            jsonmap=(json.get(0)).toMap();
            criteriaMap2 = zoho.crm.updateRecord("Invoices",jsonmap.get("INVOICEID"),invoiceMap);
        }
    }
}

This custom function works as follows:

  • The function fetches all the newly created Orders from Shopify and creates a record in the Invoice module of Zoho CRM. Before creating the new Invoice it checks for the whether the Contact, Account and Product associated with the Invoice are already present in Zoho CRM. If not, it creates a new Contact, Account and Product and map it to the new Invoice. If the record already exists in Zoho CRM, the record will be updated.
  • This verification is done based on the following fields for each module:
    • Contact - Email address
    • Account - Company name
    • Product - Product ID.

In these functions, the line currentDate=(zoho.currentdate.subDay(1)).toString("yyyy-MM-dd"); is used to fetch all data created one day prior to the date of execution. You can modify this time limit according to your requirements. For instance, if you are running the schedule on a weekly basis, change the subDay() value to 7.

When you are running the custom function for the first time after installation, you might want to fetch all the existing data from Shopify. In that case, set this value accordingly and execute the custom function once, then create a daily or weekly schedule. For example, if your Shopify account has data from up to 6 months prior, then set this value as 180and execute the custom function once. Then, create a custom schedule to fetch the data on a daily or weekly basis.

Note

  • The custom functions provided here are samples only. You will be able to write custom functions based on your requirements.
  • This connector supports only Shopify's Orders and Customers modules APIs.

Uninstall Shopify Connector

You can uninstall the Shopify connector extension whenever you wish to. Remember that deleting this extension will delete all its associated data.

To uninstall Shopify Connector

  1. Click Setting > Setup > Marketplace > All.
    All the installed extensions are listed. Under All Marketplace you can view all the extensions supported in CRM.
  2. Browse for Shopify Connector and click the corresponding Uninstall link.
  3. Click OK to confirm.
    The extension will be uninstalled.

Share this post :

FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohocrm.com