Modules@robinpath/shopify
shopify

@robinpath/shopify

0.1.1Node.jsPublic

Shopify module for RobinPath.

Shopify

Shopify module for RobinPath.

Package: @robinpath/shopify | Category: Ecommerce | Type: Integration

Authentication

shopify.setCredentials "my-store" "shpat_xxx"

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the shopify module when you need to:

  • List products in the store. -- Use shopify.listProducts to perform this operation
  • Get a product by ID. -- Use shopify.getProduct to perform this operation
  • Create a new product. -- Use shopify.createProduct to perform this operation
  • Update an existing product. -- Use shopify.updateProduct to perform this operation
  • List orders with optional filters. -- Use shopify.listOrders to perform this operation

Quick Reference

FunctionDescriptionReturns
setCredentialsSet Shopify store credentials.Confirmation message.
listProductsList products in the store.Array of product objects.
getProductGet a product by ID.Product object.
createProductCreate a new product.Created product object.
updateProductUpdate an existing product.Updated product object.
listOrdersList orders with optional filters.Array of order objects.
getOrderGet an order by ID.Order object.
listCustomersList customers.Array of customer objects.
getCustomerGet a customer by ID.Customer object.
getInventoryGet inventory levels for an item.Array of inventory level objects.
countProductsGet total product count.Number of products.
countOrdersGet total order count with optional status filter.Number of orders.

Functions

setCredentials

Set Shopify store credentials.

Module: shopify | Returns: string -- Confirmation message.

shopify.setCredentials "my-store" "shpat_xxx"
ParameterTypeRequiredDescription
shopstringYesShopify store name (e.g. 'my-store' from my-store.myshopify.com)
accessTokenstringYesAdmin API access token

listProducts

List products in the store.

Module: shopify | Returns: array -- Array of product objects.

shopify.listProducts {"limit":10}
ParameterTypeRequiredDescription
optionsobjectNoOptions: limit, page_info, collection_id, status

getProduct

Get a product by ID.

Module: shopify | Returns: object -- Product object.

shopify.getProduct "123456789"
ParameterTypeRequiredDescription
productIdstringYesProduct ID

createProduct

Create a new product.

Module: shopify | Returns: object -- Created product object.

shopify.createProduct {"title":"New Product","body_html":"<p>Description</p>","vendor":"My Brand"}
ParameterTypeRequiredDescription
productobjectYesProduct object (title, body_html, vendor, product_type, variants, etc.)

updateProduct

Update an existing product.

Module: shopify | Returns: object -- Updated product object.

shopify.updateProduct "123456789" {"title":"Updated Title"}
ParameterTypeRequiredDescription
productIdstringYesProduct ID
productobjectYesFields to update

listOrders

List orders with optional filters.

Module: shopify | Returns: array -- Array of order objects.

shopify.listOrders {"status":"open","limit":25}
ParameterTypeRequiredDescription
optionsobjectNoOptions: limit, status, financial_status, fulfillment_status, since_id

getOrder

Get an order by ID.

Module: shopify | Returns: object -- Order object.

shopify.getOrder "987654321"
ParameterTypeRequiredDescription
orderIdstringYesOrder ID

listCustomers

List customers.

Module: shopify | Returns: array -- Array of customer objects.

shopify.listCustomers {"limit":10}
ParameterTypeRequiredDescription
optionsobjectNoOptions: limit, since_id

getCustomer

Get a customer by ID.

Module: shopify | Returns: object -- Customer object.

shopify.getCustomer "111222333"
ParameterTypeRequiredDescription
customerIdstringYesCustomer ID

getInventory

Get inventory levels for an item.

Module: shopify | Returns: array -- Array of inventory level objects.

shopify.getInventory "444555666"
ParameterTypeRequiredDescription
inventoryItemIdstringYesInventory item ID

countProducts

Get total product count.

Module: shopify | Returns: number -- Number of products.

shopify.countProducts
ParameterTypeRequiredDescription
(none)NoCall with no arguments

countOrders

Get total order count with optional status filter.

Module: shopify | Returns: number -- Number of orders.

shopify.countOrders {"status":"open"}
ParameterTypeRequiredDescription
optionsobjectNoOptions: status (open, closed, any)

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Shopify API error (${res.status}): ${text}Check the error message for details
shopify.setCredentials requires shop name and access token.Check the error message for details
shopify.getProduct requires a productId.Check the error message for details
shopify.createProduct requires a product object.Check the error message for details
shopify.updateProduct requires productId and product object.Check the error message for details
shopify.getOrder requires an orderId.Check the error message for details
shopify.getCustomer requires a customerId.Check the error message for details
shopify.getInventory requires an inventoryItemId.Check the error message for details
@desc "List products and validate result"
do
  set $result as shopify.listProducts {"limit":10}
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Products

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  shopify.setCredentials $token
enddo

@desc "List products and iterate results"
do
  set $result as shopify.listProducts {"limit":10}
  each $item in $result
    print $item
  end
enddo

2. Create a new item with createProduct

Create a new resource and capture the result.

@desc "Setup authentication"
do
  shopify.setCredentials $token
enddo

@desc "Create product"
do
  set $result as shopify.createProduct {"title":"New Product","body_html":"<p>Description</p>","vendor":"My Brand"}
  print "Created: " + $result
enddo

3. Create and update workflow

Create an item and then update it.

@desc "Setup authentication"
do
  shopify.setCredentials $token
enddo

@desc "Create product and update product"
do
  set $created as shopify.createProduct {"title":"New Product","body_html":"<p>Description</p>","vendor":"My Brand"}
  # Update the created item
  shopify.updateProduct "123456789" {"title":"Updated Title"}
enddo

4. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  shopify.setCredentials $token
enddo

@desc "List products and create product"
do
  set $existing as shopify.listProducts {"limit":10}
  if $existing == null
    shopify.createProduct {"title":"New Product","body_html":"<p>Description</p>","vendor":"My Brand"}
    print "Item created"
  else
    print "Item already exists"
  end
enddo

5. Multi-step Shopify workflow

Chain multiple shopify operations together.

@desc "Setup authentication"
do
  shopify.setCredentials $token
enddo

@desc "List products, get product, and more"
do
  set $r_listProducts as shopify.listProducts {"limit":10}
  set $r_getProduct as shopify.getProduct "123456789"
  set $r_createProduct as shopify.createProduct {"title":"New Product","body_html":"<p>Description</p>","vendor":"My Brand"}
  print "All operations complete"
enddo

6. Safe listProducts with validation

Check results before proceeding.

@desc "Setup authentication"
do
  shopify.setCredentials $token
enddo

@desc "List products and validate result"
do
  set $result as shopify.listProducts {"limit":10}
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • woocommerce -- WooCommerce module for complementary functionality
  • bigcommerce -- BigCommerce module for complementary functionality
  • square -- Square module for complementary functionality
  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/shopify

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.5 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

sales