visit
ABOUT LINX
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
RESOURCES
To register a private app, log in to your Shopify dashboard, navigate to the Apps dashboard (Left menu > Apps). Click on the Manage private apps link which will open your private app dashboard. If you haven’t already, 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 Admin API section, show the inactive permissions of the app (by default none are selected).
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 Customers and Products resources, you can modify the access permissions at a later stage.
Scroll to the bottom of the page and click Save then Create App.
A best practice is creating $.Settings 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.
Create new $.Settings values like below and add your authentication details.
Creating the Base URL
When making requests to the Shopify API, you need to build up the base URL of each request like below://{apikey}:{password}@{hostname}/admin/api/{version}/{resource}.json
In the provided template application the URL is built up via a dynamic setting expression. The $.Settings.shopify_baseUrl has the structure of the URL and placeholder references which reference other $.Settings values. At runtime, the values referenced in the other settings will be concatenated into a base URL.
//{shopify_apiKey}:{shopify_password}@{shopify_shopName}.myshopify.com/admin/api/{shopify_api_version}
At runtime, the value of $.Settings.shopify_baseUrl will be:
When a request is made, the base URL can just be based on this $.Setting value. The particular resource path can then be added in each request using an expression like below:
= $.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:Querying Customers
The below example deals with the object. The function makes a GET request to the /customers 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.
First, create a new Function and give it the name of GetCustomers. Drag a onto the GetCustomers canvas.
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 Add breakpoint and Enable logging, this will expose the runtime values of the objects in scope. Next, debug the GetCustomers function and take note of the response body returned in the Debug Values panel. The response body is a JSON string like below:
{
"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": "+",
"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
}
}
]
}
Copy the value of CallRESTEndpoint.ResponseBody from the Debug values panel or from the . Import the copied JSON string as a new Type. This will create a data object or type for you to structure the response data into. Configure the CallRESTEndpointFNC to have an Output type of the newly imported user-defined type. You can then return the details as an output of the custom function.
In the below example, a will be added to Shopify. This will involve making a POST request to the /products endpoint. A JSON structure containing details of a Product will be submitted as the request body.
Example request:POST /admin/api/2021-01/products.json
{
"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"
]
}
}
First, In order to submit a valid JSON data structured like the above, you need to create a user-defined Type 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.
Now to make the request using the newProduct type. Inside the CreateProduct function, drag a CallRESTEndpointFNC onto the canvas. Configure the authentication credentials and the request URL.
Now we need to submit the local instance of newProduct as the request body. Change the Method of the request to POST and set the Body format as JSON. For the Body property, reference the local newProduct.
You can then import the response as a new user-defined type and set it as the Output type 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 .
Previously published at