How to Build a Shopify Integration
Author profile picture

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

ABOUT LINX
Linx is a low code developer software for IT professionals. It works on any stack making use of your current (databases, information, APIs and so on). You can use it to

  • Build and host APIs and Microservices (E.g. a giant financial institution runs their Business Banking Customer API on Linx)
  • Create endpoints for webhooks (E.g. this website is built-in with our advertising and marketing programs and Slack utilizing webhooks and Linx)
  • Integrate programs (E.g. a mining and manufacturing provider integrates their on-line store, Salesforce and Sage X3 with Linx)
  • Automate processes (E.g. a giant funding firm automates their shopper correspondence with Linx)

Creating a Linx software and connecting it to Shopify includes the next steps:

  • Creating a personal app and producing an API Key
  • Configuring Linx to authenticate
  • Customizing requests

RESOURCES

  1. Shopify REST API reference documentation: Developer documentation associated to the Shopify Admin API.
  2. ShopifyTemplate.lsoz (22.5 KB) : Template Linx software. Open it within the Linx Designer to comply with this information.

Step 1: Create a Private App

To entry and modify your Shopify sources utilizing Linx, you first want to register a personal app with Shopify. This will then generate the related API Key which have to be used when making requests from Linx.

To register a personal app, log in to your Shopify dashboard, navigate to the Apps dashboard (Left menu > Apps). Click on the Manage personal apps hyperlink which is able to open your personal app dashboard. If you haven’t already, allow personal app growth.

Once enabled, click on on the “Create New Private App” button. Give your app a title equivalent to “LinxApp” and full the contact particulars. In the Admin API part, present the inactive permissions of the app (by default none are chosen).

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Select the related permissions, these would be the entry scope of the linked software. In this information we might be studying and writing information to the Customers and Products sources, you may modify the entry permissions at a later stage.

Scroll to the underside of the web page and click on Save then Create App.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Your app authentication particulars might be displayed:

  • API Key: Key used because the username within the HTTP Basic authentication of the request in addition to the request URL.
  • Password: Used because the password within the HTTP Basic authentication of the request.
  • Base URL: Example of the bottom URL to use when requesting to your occasion.

Step 2: Connect to Shopify

To join to the Shopify API, drag a CallRESTEndpointFNC onto a user-defined operate and configure the related properties described under.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

A finest observe is creating $.Settings values for all of the wanted constants in our software which will change at a later stage. By making these $.Settings values, we will reference them all through our Linx software and replace them in a single place to have application-wide results.

Create new $.Settings values like under and add your authentication particulars.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Creating the Base URL

When making requests to the Shopify API, you want to construct up the bottom URL of every request like under:

https://{apikey}:{password}@{hostname}/admin/api/{model}/{useful resource}.json

In Linx, this may be accomplished by way of using expressions or utilizing dynamic settings.

In the offered template software the URL is constructed up by way of a dynamic setting expression. The $.Settings.shopify_baseUrl has the construction of the URL and placeholder references which reference different $.Settings values. At runtime, the values referenced within the different settings might be concatenated into a base URL.

https://{shopify_apiKey}:{shopify_password}@{shopify_shopName}.myshopify.com/admin/api/{shopify_api_version}

At runtime, the worth of $.Settings.shopify_baseUrl might be:

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

When a request is made, the bottom URL can simply be based mostly on this $.Setting worth. The specific useful resource path can then be added in every request utilizing an expression like under:

= $.Settings.shopify_baseURI + "/products" + ".json"
This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Authentication

Private functions authenticate with Shopify via primary HTTP authentication. This will be completed by finishing the CallRESTEndpointFNC Authentication properties like under:

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Step 3: Querying And Modifying Data

The under examples are demonstrations of interacting with the Shopify API and Linx.

Querying Customers

The under instance offers with the Customer object. The operate makes a GET request to the /prospects endpoint which returns a JSON string response containing a checklist of all the shoppers. The response is then imported by Linx into a customized kind object which is then used to construction the response physique.

First, create a new Function and provides it the title of GetCustomers. Drag a CallRESTEndpointFNC onto the GetCustomers canvas.

Complete the Basic authentication particulars by referencing the API Key and password from earlier. Then configure the URL to be just like the under (utilizing the expression editor):

= $.Settings.shopify_baseURI + "/customers" + ".json"
This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Right-click on the CallRESTEndpointFNC and Add breakpoint and Enable logging, it will expose the runtime values of the objects in scope. Next, debug the GetCustomers operate and be aware of the response physique returned within the Debug Values panel. The response physique is a JSON string like under:

{
  "customers": [
    {
      "id": 207119551,
      "email": "[email protected]",
      "accepts_marketing": false,
      "created_at": "2021-01-01T14:46:48-05:00",
      "updated_at": "2021-01-01T14:46:48-05:00",
      "first_name": "Bob",
      "last_name": "Norman",
      "orders_count": 1,
      "state": "disabled",
      "total_spent": "199.65",
      "last_order_id": 450789469,
      "note": null,
      "verified_email": true,
      "multipass_identifier": null,
      "tax_exempt": false,
      "phone": "+16136120707",
      "tags": "",
      "last_order_name": "#1001",
      "currency": "USD",
      "addresses": [
        {
          "id": 207119551,
          "customer_id": 207119551,
          "first_name": null,
          "last_name": null,
          "company": null,
          "address1": "Chestnut Street 92",
          "address2": "",
          "city": "Louisville",
          "province": "Kentucky",
          "country": "United States",
          "zip": "40202",
          "phone": "555-625-1199",
          "name": "",
          "province_code": "KY",
          "country_code": "US",
          "country_name": "United States",
          "default": true
        }
      ],
      "accepts_marketing_updated_at": "2005-06-12T11:57:11-04:00",
      "marketing_opt_in_level": null,
      "tax_exemptions": [],
      "admin_graphql_api_id": "gid://shopify/Customer/207119551",
      "default_address": {
        "id": 207119551,
        "customer_id": 207119551,
        "first_name": null,
        "last_name": null,
        "company": null,
        "address1": "Chestnut Street 92",
        "address2": "",
        "city": "Louisville",
        "province": "Kentucky",
        "country": "United States",
        "zip": "40202",
        "phone": "555-625-1199",
        "name": "",
        "province_code": "KY",
        "country_code": "US",
        "country_name": "United States",
        "default": true
      }
    }
  ]
}

This object comprises a father or mother object containing a “customers” little one object which comprises a checklist of objects which include the fields associated to the product we’re creating.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Next we want to create a customized information kind so Linx will know what to parse the response physique into, it will enable us to work with particular person area values in subsequent operations.

Copy the worth of CallRESTEndpoint.ResponseBody from the Debug values panel or from the API documentation. Import the copied JSON string as a new Type. This will create a information object or kind for you to construction the response information into. Configure the CallRESTEndpointFNC to have an Output kind of the newly imported user-defined kind. You can then return the small print as an output of the customized operate.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Adding Products

In the under instance, a Product might be added to Shopify. This will contain making a POST request to the /merchandise endpoint. A JSON construction containing particulars of a Product might be submitted because the request physique.

Example request:

POST /admin/api/2021-01/merchandise.json
{
  "product": {
    "title": "Burton Custom Freestyle 151",
    "body_html": "Good snowboard!",
    "vendor": "Burton",
    "product_type": "Snowboard",
    "tags": [
      "Barnes & Noble",
      "John's Fav",
      "Big Air"
    ]
  }
}

In the under instance we’re going to create a user-defined operate that can take within the particulars of the product because the enter parameters. These particulars will then be assigned to the user-defined kind and submitted in a request.

First, In order to submit a legitimate JSON information structured just like the above, you want to create a user-defined Type that matches the fields within the product object, both manually or by importing the present JSON instance as a new Type with the title of “newProduct”. This will create two varieties, a father or mother newProduct that holds a little one newProduct_product.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

This user-defined kind is then accessible to reference throughout your Linx software to construction information.

Next, we’re going to create a user-defined operate that can absorb information on this format after which submit this information to the Shopify API.

To do that, create a new user-defined operate with the title of “CreateProduct”, with an enter parameter with the title of the product and the Type of product. When this CreateProduct user-defined operate known as from elsewhere within the software, the construction of the kid object might be in a position to be used to move information via. The father or mother product isn’t wanted as an enter parameter because it simply creates one other degree, we will assign it later contained in the operate.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

For the request physique, we’re going to submit a newProduct kind from earlier in a JSON format. Currently, the CreateProduct operate takes in an enter parameter of the sort newProduct_product. However, for the request to succeed, we want to submit your entire construction of newProduct. To do that, we want to assign the enter parameter productDetails particulars because the little one newProduct_product of newProduct. To do that, drag an occasion of the newProduct kind from the Solution Explorer onto the CreateProduct canvas. Expand its area values properties and within the product area, reference the enter parameter productDetails.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Now to make the request utilizing the newProduct kind. Inside the CreateProduct operate, drag a CallRESTEndpointFNC onto the canvas. Configure the authentication credentials and the request URL.

Now we want to submit the native occasion of newProduct because the request physique. Change the Method of the request to POST and set the Body format as JSON. For the Body property, reference the native newProduct.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Now we will make a request to check it out. A brand new product ought to be seen on the Shopify merchandise dashboard:

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

You can then import the response as a new user-defined kind and set it because the Output kind of the CallRESTEndpointFNC. When a new product is now created, the newly added particulars and a few metadata together with the brand new id are then accessible in subsequent capabilities equivalent to logging them to a database with an ExecuteSQLFNC or writing to a file utilizing a TextFileWriteFNC.

This information will cowl connecting to the Shopify Admin API with Linx utilizing API Keys along with the HTTP Basic scheme authentication and a few request examples.

Previously revealed at https://community.linx.software/community/t/shopify-integration/506

Tags

Join Hacker Noon

Create your free account to unlock your customized studying expertise.