This guide will cover connecting to the with using API Keys in conjunction with the HTTP Basic scheme and some request examples. Shopify Admin API Linx authentication Linx is a low code developer tool for IT professionals. It works on any stack making use of your existing (databases, files, APIs etc). You can use it to ABOUT LINX Build and host APIs and Microservices (E.g. a large bank runs their Business Banking Customer API on Linx) Create endpoints for webhooks (E.g. this site is integrated with our marketing systems and Slack using webhooks and Linx) Integrate systems ( E.g. a mining and manufacturing supplier integrates their online shop, Salesforce and Sage X3 with Linx) Automate processes (E.g. a large investment company automates their client correspondence with Linx) Creating a Linx application and connecting it to Shopify involves the following steps: Creating a private app and generating an API Key Configuring Linx to authenticate Customizing requests RESOURCES : Developer documentation related to the Shopify Admin API. Shopify REST API reference documentation (22.5 KB) : Template Linx application. Open it in the to follow this guide. ShopifyTemplate.lsoz Linx Designer Step 1: Create a Private App To access and modify your Shopify resources using Linx, you first need to . This will then which must be used when making requests from Linx. register a private app with Shopify generate the relevant API Key To register a private app, log in to your Shopify dashboard, navigate to the Apps dashboard (Left menu > ). Click on the link which will open your private app dashboard. If you haven’t already, . Apps Manage private apps enable private app development Once enabled, click on the "Create New Private App" button. Give your app a name such as “LinxApp” and complete the contact details. In the section, show the inactive permissions of the app (by default none are selected). Admin API Select the relevant permissions, these will be the access scope of the linked application. In this guide we will be reading and writing data to the and resources, you can modify the access permissions at a later stage. Customers Products Scroll to the bottom of the page and click then . Save Create App Your app authentication details will be displayed: : Key used as the username in the HTTP Basic authentication of the request as well as the request URL. API Key : Used as the password in the HTTP Basic authentication of the request. Password : Example of the base URL to use when requesting to your instance. Base URL Step 2: Connect to Shopify To connect to the Shopify API, drag a onto a user-defined function and configure the relevant properties described below. CallRESTEndpointFNC A best practice is creating values for all the needed constants in our application that may change at a later stage. By making these $.Settings values, we can reference them throughout our Linx application and update them in a single place to have application-wide effects. $.Settings Create new values like below and add your authentication details. $.Settings Creating the Base URL When making requests to the Shopify API, you need to build up the base URL of each request like below: https: //{apikey}:{password}@{hostname}/admin/api/{version}/{resource}.json In Linx, this can be done via the use of expressions or using dynamic settings. In the provided template application the URL is built up via a dynamic setting expression. The has the structure of the URL and placeholder references which reference other values. At runtime, the values referenced in the other settings will be concatenated into a base URL. $.Settings.shopify _ baseUrl $.Settings https: //{shopify_apiKey}:{shopify_password}@{shopify_shopName}.myshopify.com/admin/api/{shopify_api_version} At runtime, the value of will be: $.Settings.shopify_baseUrl When a request is made, the base URL can just be based on this value. The particular resource path can then be added in each request using an expression like below: $.Setting = $.Settings.shopify_baseURI + + "/products" ".json" Authentication Private applications authenticate with Shopify through basic HTTP authentication. This can be accomplished by completing the Authentication properties like below: CallRESTEndpointFNC Step 3: Querying And Modifying Data The below examples are demonstrations of interacting with the Shopify API and Linx. Querying Customers The below example deals with the object. The function makes a request to the endpoint which returns a JSON string response containing a list of all the customers. The response is then imported by Linx into a custom type object which is then used to structure the response body. Customer GET /customers First, create a new and give it the name of . Drag a onto the canvas. Function GetCustomers CallRESTEndpointFNC GetCustomers Complete the Basic authentication details by referencing the API Key and password from earlier. Then configure the URL to be like the below (using the expression editor): = $.Settings.shopify_baseURI + + "/customers" ".json" Right-click on the and and , this will expose the runtime values of the objects in scope. Next, debug the function and take note of the response body returned in the Debug Values panel. The response body is a JSON string like below: CallRESTEndpointFNC Add breakpoint Enable logging GetCustomers { : [ { : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : [ { : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : } ], : , : , : [], : , : { : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : , : } } ] } "customers" "id" 207119551 "email" "bob.norman@hostmail.com" "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 contains a parent object containing a “customers” child object which contains a list of objects which contain the fields related to the product we are creating. Next we need to create a custom data type so Linx will know what to parse the response body into, this will allow us to work with individual field values in subsequent operations. Copy the value of from the Debug values panel or from the . Import the copied JSON string as a new . This will create a data object or type for you to structure the response data into. Configure the to have an of the newly imported user-defined type. You can then return the details as an output of the custom function. CallRESTEndpoint.ResponseBody API documentation Type CallRESTEndpointFNC Output type Adding Products In the below example, a will be added to Shopify. This will involve making a request to the A JSON structure containing details of a will be submitted as the request body. Product POST /products endpoint. Product Example request: POST /admin/api/ /products.json { : { : , : , : , : , : [ , , ] } } 2021 -01 "product" "title" "Burton Custom Freestyle 151" "body_html" "<strong>Good snowboard!</strong>" "vendor" "Burton" "product_type" "Snowboard" "tags" "Barnes & Noble" "John's Fav" "Big Air" In the below example we are going to create a user-defined function that will take in the details of the product as the input parameters. These details will then be assigned to the user-defined type and submitted in a request. First, In order to submit a valid JSON data structured like the above, you need to create a user-defined that matches the fields in the product object, either manually or by importing the provide JSON example as a new Type with the name of “newProduct”. This will create two types, a parent newProduct that holds a child newProduct_product. Type This user-defined type is then available to reference across your Linx application to structure data. Next, we are going to create a user-defined function that will take in data in this format and then submit this data to the Shopify API. To do this, create a new user-defined function with the name of “CreateProduct”, with an input parameter with the name of the product and the Type of product. When this CreateProduct user-defined function is called from somewhere else in the application, the structure of the child object will be able to be used to pass data through. The parent product is not needed as an input parameter as it just creates another level, we can assign it later inside the function. For the request body, we are going to submit a newProduct type from earlier in a JSON format. Currently, the CreateProduct function takes in an input parameter of the type newProduct_product. However, for the request to succeed, we need to submit the entire structure of newProduct. To do this, we need to assign the input parameter productDetails details as the child newProduct_product of newProduct. To do this, drag an instance of the newProduct type from the Solution Explorer onto the CreateProduct canvas. Expand its field values properties and in the product field, reference the input parameter productDetails. Now to make the request using the newProduct type. Inside the CreateProduct function, drag a onto the canvas. Configure the authentication credentials and the request URL. CallRESTEndpointFNC Now we need to submit the local instance of newProduct as the request body. Change the of the request to POST and set the as JSON. For the property, reference the local newProduct. Method Body format Body Now we can make a request to test it out. A new product should be visible on the Shopify products dashboard: You can then import the response as a new user-defined type and set it as the of the CallRESTEndpointFNC. When a new product is now created, the newly added details and some metadata including the new id are then available in subsequent functions such as logging them to a database with an or writing to a file using a . Output type ExecuteSQLFNC TextFileWriteFNC Previously published at https://community.linx.software/community/t/shopify-integration/506