Skip to main content

Actions

The ballerinax/shopify.admin package exposes the following clients:

ClientPurpose
ClientShopify Admin REST API: manage customers, products, orders, fulfillments, webhooks, and more.

Client

Shopify Admin REST API: manage customers, products, orders, fulfillments, webhooks, and more.

Configuration

FieldTypeDefaultDescription
xShopifyAccessTokenstringRequiredThe Shopify Admin API access token (X-Shopify-Access-Token header).

Initializing the client

import ballerinax/shopify.admin;

configurable string accessToken = ?;
configurable string storeUrl = ?;

admin:ApiKeysConfig apiKeyConfig = {
xShopifyAccessToken: accessToken
};

admin:Client shopify = check new (apiKeyConfig, storeUrl);

Operations

Customer management

getCustomers

Retrieves a list of customers with optional filtering by IDs, date ranges, and pagination.

Parameters:

NameTypeRequiredDescription
idsstring?NoComma-separated list of customer IDs to restrict results.
sinceIdstring?NoRestrict results to those after the specified ID.
createdAtMinstring?NoShow customers created after this date (ISO 8601).
createdAtMaxstring?NoShow customers created before this date (ISO 8601).
updatedAtMinstring?NoShow customers last updated after this date (ISO 8601).
updatedAtMaxstring?NoShow customers last updated before this date (ISO 8601).
'limitint?NoMaximum number of results to show (default: 50, max: 250).
fieldsstring?NoComma-separated list of fields to include in the response.

Returns: CustomerList|error

Sample code:

admin:CustomerList customers = check shopify->getCustomers('limit = 10);

Sample response:

{
"customers": [
{
"id": 6940095127745,
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "[email protected]",
"orders_count": 0,
"state": "disabled",
"total_spent": "0.00",
"created_at": "2024-01-15T10:30:00-05:00"
}
]
}
createCustomer

Creates a new customer record.

Parameters:

NameTypeRequiredDescription
payloadCreateCustomerYesThe Customer object to be created.

Returns: CustomerObject|error

Sample code:

admin:CreateCustomer payload = {
customer: {
first_name: "Steve",
last_name: "Lastnameson",
email: "[email protected]"
}
};
admin:CustomerObject result = check shopify->createCustomer(payload);

Sample response:

{
"customer": {
"id": 6940095127745,
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "[email protected]",
"created_at": "2024-01-15T10:30:00-05:00",
"orders_count": 0,
"state": "disabled",
"total_spent": "0.00",
"verified_email": true
}
}
getCustomer

Retrieves a single customer by ID.

Parameters:

NameTypeRequiredDescription
customerIdstringYesThe customer ID.
fieldsstring?NoComma-separated list of fields to include.

Returns: CustomerObject|error

Sample code:

admin:CustomerObject customer = check shopify->getCustomer("6940095127745");

Sample response:

{
"customer": {
"id": 6940095127745,
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "[email protected]",
"orders_count": 0,
"state": "disabled"
}
}
updateCustomer

Updates an existing customer.

Parameters:

NameTypeRequiredDescription
customerIdstringYesThe customer ID.
payloadUpdateCustomerYesThe Customer object with updated fields.

Returns: CustomerObject|error

Sample code:

admin:CustomerObject updated = check shopify->updateCustomer("6940095127745", {
customer: {
first_name: "Steven",
tags: "VIP,loyal"
}
});

Sample response:

{
"customer": {
"id": 6940095127745,
"first_name": "Steven",
"last_name": "Lastnameson",
"email": "[email protected]",
"tags": "VIP,loyal"
}
}
searchCustomers

Searches for customers matching a supplied query.

Parameters:

NameTypeRequiredDescription
querystring?NoText to search for in the shop's customer data.
'orderstring?NoField and direction by which to order results (default: last_order_date DESC).
'limitint?NoMaximum number of results (default: 50, max: 250).
fieldsstring?NoComma-separated list of fields to include.

Returns: CustomerList|error

Sample code:

admin:CustomerList results = check shopify->searchCustomers(query = "steve");

Sample response:

{
"customers": [
{
"id": 6940095127745,
"first_name": "Steve",
"last_name": "Lastnameson",
"email": "[email protected]"
}
]
}

Product management

getProducts

Retrieves a list of products with optional filtering by title, vendor, status, collection, and date ranges.

Parameters:

NameTypeRequiredDescription
idsstring?NoComma-separated list of product IDs.
'limitint?NoMaximum results per page (default: 50, max: 250).
titlestring?NoFilter by product title.
vendorstring?NoFilter by product vendor.
productTypestring?NoFilter by product type.
statusstring?NoFilter by status: active, archived, or draft (default: active).
fieldsstring?NoComma-separated list of fields to include.

Returns: ProductList|error

Sample code:

admin:ProductList products = check shopify->getProducts(status = "active", 'limit = 5);

Sample response:

{
"products": [
{
"id": 7982605344961,
"title": "Classic T-Shirt",
"vendor": "Acme",
"product_type": "Apparel",
"status": "active",
"created_at": "2024-01-10T08:00:00-05:00"
}
]
}
createProduct

Creates a new product.

Parameters:

NameTypeRequiredDescription
payloadCreateProductYesThe Product object to be created.

Returns: ProductObject|error

Sample code:

admin:ProductObject product = check shopify->createProduct({
product: {
title: "Classic T-Shirt",
body_html: "<p>A comfortable cotton t-shirt.</p>",
vendor: "Acme",
product_type: "Apparel",
tags: "cotton,summer"
}
});

Sample response:

{
"product": {
"id": 7982605344961,
"title": "Classic T-Shirt",
"body_html": "<p>A comfortable cotton t-shirt.</p>",
"vendor": "Acme",
"product_type": "Apparel",
"status": "draft",
"tags": "cotton,summer"
}
}
getProduct

Retrieves a single product by ID.

Parameters:

NameTypeRequiredDescription
productIdstringYesThe product ID.
fieldsstring?NoComma-separated list of fields to include.

Returns: ProductObject|error

Sample code:

admin:ProductObject product = check shopify->getProduct("7982605344961");

Sample response:

{
"product": {
"id": 7982605344961,
"title": "Classic T-Shirt",
"vendor": "Acme",
"product_type": "Apparel",
"status": "active"
}
}
updateProduct

Updates a product and its variants and images.

Parameters:

NameTypeRequiredDescription
productIdstringYesThe product ID.
payloadUpdateProductYesThe Product object with updated fields.

Returns: ProductObject|error

Sample code:

admin:ProductObject updated = check shopify->updateProduct("7982605344961", {
product: {
title: "Premium Classic T-Shirt",
status: "active"
}
});

Sample response:

{
"product": {
"id": 7982605344961,
"title": "Premium Classic T-Shirt",
"vendor": "Acme",
"status": "active"
}
}

Product variants

getProductVariants

Retrieves a list of product variants for a given product.

Parameters:

NameTypeRequiredDescription
productIdstringYesThe product ID.
fieldsstring?NoComma-separated list of fields to include.
'limitint?NoMaximum results per page.
sinceIdstring?NoRestrict results to after the specified ID.

Returns: ProductVariantList|error

Sample code:

admin:ProductVariantList variants = check shopify->getProductVariants("7982605344961");

Sample response:

{
"variants": [
{
"id": 43503271895233,
"product_id": 7982605344961,
"title": "Small / Blue",
"price": "19.99",
"sku": "TSHIRT-S-BLUE",
"inventory_quantity": 50
}
]
}
createProductVariant

Creates a new product variant.

Parameters:

NameTypeRequiredDescription
productIdstringYesThe product ID.
payloadCreateProductVariantYesThe Product variant object to be created.

Returns: ProductVariantObject|error

Sample code:

admin:ProductVariantObject variant = check shopify->createProductVariant("7982605344961", {
variant: {
option1: "Large",
price: "24.99",
sku: "TSHIRT-L-BLUE"
}
});

Sample response:

{
"variant": {
"id": 43503271895300,
"product_id": 7982605344961,
"title": "Large",
"price": "24.99",
"sku": "TSHIRT-L-BLUE"
}
}
getProductVariant

Retrieves a single product variant by its ID.

Parameters:

NameTypeRequiredDescription
variantIdstringYesThe variant ID.
fieldsstring?NoComma-separated list of fields to include.

Returns: ProductVariantObject|error

Sample code:

admin:ProductVariantObject variant = check shopify->getProductVariant("43503271895233");

Sample response:

{
"variant": {
"id": 43503271895233,
"product_id": 7982605344961,
"title": "Small / Blue",
"price": "19.99",
"sku": "TSHIRT-S-BLUE"
}
}
updateProductVariant

Updates an existing product variant.

Parameters:

NameTypeRequiredDescription
variantIdstringYesThe variant ID.
payloadUpdateProductVariantYesThe Product variant object with updated fields.

Returns: ProductVariantObject|error

Sample code:

admin:ProductVariantObject updated = check shopify->updateProductVariant("43503271895233", {
variant: {
price: "22.99"
}
});

Sample response:

{
"variant": {
"id": 43503271895233,
"price": "22.99",
"sku": "TSHIRT-S-BLUE"
}
}

Order management

getOrders

Retrieves a list of orders with optional filtering by status, financial status, fulfillment status, and date ranges.

Parameters:

NameTypeRequiredDescription
idsstring?NoComma-separated list of order IDs.
'limitint?NoMaximum results per page (default: 50, max: 250).
statusstring?NoFilter by order status: open, closed, cancelled, or any (default: open).
financialStatusstring?NoFilter by financial status: authorized, pending, paid, partially_paid, refunded, voided, partially_refunded, any, or unpaid.
fulfillmentStatusstring?NoFilter by fulfillment status: shipped, partial, unshipped, any, or unfulfilled.
fieldsstring?NoComma-separated list of fields to include.

Returns: OrderList|error

Sample code:

admin:OrderList orders = check shopify->getOrders(status = "open", 'limit = 10);

Sample response:

{
"orders": [
{
"id": 5553109696705,
"name": "#1001",
"email": "[email protected]",
"total_price": "49.98",
"financial_status": "paid",
"fulfillment_status": null,
"created_at": "2024-01-20T14:00:00-05:00"
}
]
}
createOrder

Creates an order. By default, product inventory is not claimed.

Parameters:

NameTypeRequiredDescription
payloadCreateOrderYesThe Order object to be created.

Returns: OrderObject|error

Sample code:

admin:OrderObject newOrder = check shopify->createOrder({
'order: {
line_items: [
{
variant_id: 43503271895233,
quantity: 2
}
],
customer: {
id: 6940095127745
},
financial_status: "pending"
}
});

Sample response:

{
"order": {
"id": 5553109696705,
"name": "#1001",
"total_price": "39.98",
"financial_status": "pending",
"fulfillment_status": null,
"line_items": [
{
"id": 12345678901234,
"variant_id": 43503271895233,
"title": "Classic T-Shirt",
"quantity": 2,
"price": "19.99"
}
]
}
}
getOrder

Retrieves a specific order by ID.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
fieldsstring?NoComma-separated list of fields to include.

Returns: OrderObject|error

Sample code:

admin:OrderObject order = check shopify->getOrder("5553109696705");

Sample response:

{
"order": {
"id": 5553109696705,
"name": "#1001",
"email": "[email protected]",
"total_price": "49.98",
"financial_status": "paid",
"fulfillment_status": null
}
}
updateOrder

Updates an existing order.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
payloadUpdateOrderYesThe Order object with updated fields.

Returns: OrderObject|error

Sample code:

admin:OrderObject updated = check shopify->updateOrder("5553109696705", {
'order: {
note: "Customer requested gift wrapping",
tags: "gift,priority"
}
});

Sample response:

{
"order": {
"id": 5553109696705,
"name": "#1001",
"note": "Customer requested gift wrapping",
"tags": "gift,priority"
}
}

Fulfillments

getOrderFulfillments

Retrieves fulfillments associated with an order.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
createdAtMinstring?NoShow fulfillments created after this date (ISO 8601).
createdAtMaxstring?NoShow fulfillments created before this date (ISO 8601).
fieldsstring?NoComma-separated list of fields to include.
'limitint?NoMaximum results (default: 50, max: 250).

Returns: OrderFulfillmentsList|error

Sample code:

admin:OrderFulfillmentsList fulfillments = check shopify->getOrderFulfillments("5553109696705");

Sample response:

{
"fulfillments": [
{
"id": 4521387524289,
"order_id": 5553109696705,
"status": "success",
"tracking_company": "UPS",
"tracking_numbers": ["1Z999AA10123456784"],
"created_at": "2024-01-22T10:00:00-05:00"
}
]
}
createOrderFulfillment

Creates a fulfillment for the specified order and line items. If no line item IDs are specified, all unfulfilled and partially fulfilled line items are fulfilled.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
payloadCreateOrderFulfillmentYesThe fulfillment object to be created.

Returns: OrderFulfillmentObject|error

Sample code:

admin:OrderFulfillmentObject fulfillment = check shopify->createOrderFulfillment("5553109696705", {
fulfillment: {
tracking_company: "UPS",
tracking_numbers: ["1Z999AA10123456784"],
notify_customer: "true"
}
});

Sample response:

{
"fulfillment": {
"id": 4521387524289,
"order_id": 5553109696705,
"status": "success",
"tracking_company": "UPS",
"tracking_numbers": ["1Z999AA10123456784"]
}
}

Draft orders

createDraftOrder

Creates a draft order for deferred or manual order workflows.

Parameters:

NameTypeRequiredDescription
payloadCreateDraftOrderYesThe Draft order object to be created.
customerIdstring?NoUsed to load the customer and associate their email.
useCustomerDefaultAddressboolean?NoLoad customer shipping information if true.

Returns: DraftOrderObject|error

Sample code:

admin:DraftOrderObject draft = check shopify->createDraftOrder({
draft_order: {
line_items: [
{
title: "Custom Item",
price: "29.99",
quantity: 1
}
],
customer: {
id: 6940095127745
}
}
});

Sample response:

{
"draft_order": {
"id": 1078505537729,
"name": "#D1",
"status": "open",
"total_price": "29.99",
"subtotal_price": "29.99",
"customer": {
"id": 6940095127745,
"first_name": "Steve"
}
}
}

Transactions & refunds

createTransactionForOrder

Creates a transaction for an order (e.g., capture, sale, or external payment).

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
payloadCreateTransactionYesThe Transaction object to be created.
'sourcestring?NoSet to external for cash transactions.

Returns: TransactionObject|error

Sample code:

admin:TransactionObject txn = check shopify->createTransactionForOrder("5553109696705", {
'transaction: {
kind: "capture",
amount: "49.98"
}
});

Sample response:

{
"transaction": {
"id": 6981435809,
"order_id": 5553109696705,
"kind": "capture",
"amount": "49.98",
"status": "success",
"created_at": "2024-01-22T11:00:00-05:00"
}
}
createRefundForOrder

Creates a refund for an order.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
payloadCreateRefundYesThe Refund object to be created.

Returns: RefundObject|error

Sample code:

admin:RefundObject refund = check shopify->createRefundForOrder("5553109696705", {
refund: {
note: "Customer returned item",
shipping: {
full_refund: true
}
}
});

Sample response:

{
"refund": {
"id": 929361237,
"order_id": 5553109696705,
"note": "Customer returned item",
"created_at": "2024-01-25T09:00:00-05:00"
}
}

Order risks

getOrderRisks

Retrieves a list of all order risks for an order.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.

Returns: OrderRiskList|error

Sample code:

admin:OrderRiskList risks = check shopify->getOrderRisks("5553109696705");

Sample response:

{
"risks": [
{
"id": 8723457891,
"order_id": 5553109696705,
"message": "This order was placed from a proxy IP",
"recommendation": "investigate",
"score": "0.8",
"source": "External",
"cause_cancel": false,
"display": true
}
]
}
createOrderRisk

Creates an order risk for an order.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
payloadCreateOrderRiskYesThe order risk object to be created.

Returns: OrderRiskObject|error

Sample code:

admin:OrderRiskObject risk = check shopify->createOrderRisk("5553109696705", {
risk: {
message: "This order came from an unusual location",
recommendation: "investigate",
score: "0.7",
'source: "External",
cause_cancel: false,
display: true
}
});

Sample response:

{
"risk": {
"id": 8723457892,
"order_id": 5553109696705,
"message": "This order came from an unusual location",
"recommendation": "investigate",
"score": "0.7",
"source": "External"
}
}
getOrderRisk

Retrieves a single order risk by its ID.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
riskIdstringYesThe order risk ID.

Returns: OrderRiskObject|error

Sample code:

admin:OrderRiskObject risk = check shopify->getOrderRisk("5553109696705", "8723457891");

Sample response:

{
"risk": {
"id": 8723457891,
"order_id": 5553109696705,
"message": "This order was placed from a proxy IP",
"recommendation": "investigate",
"score": "0.8"
}
}
updateOrderRisk

Updates an order risk.

Parameters:

NameTypeRequiredDescription
orderIdstringYesThe order ID.
riskIdstringYesThe order risk ID.
payloadUpdateOrderRiskYesThe order risk object with updated fields.

Returns: OrderRiskObject|error

Sample code:

admin:OrderRiskObject updated = check shopify->updateOrderRisk("5553109696705", "8723457891", {
risk: {
recommendation: "accept",
score: "0.2"
}
});

Sample response:

{
"risk": {
"id": 8723457891,
"order_id": 5553109696705,
"recommendation": "accept",
"score": "0.2"
}
}

Webhook management

getWebhooks

Retrieves a list of webhook subscriptions with optional filtering by address, topic, and date ranges.

Parameters:

NameTypeRequiredDescription
addressstring?NoFilter by the URI that receives the POST request.
topicstring?NoFilter by webhook topic (e.g., orders/create).
'limitint?NoMaximum results (default: 50, max: 250).
fieldsstring?NoComma-separated list of fields to include.

Returns: WebhookList|error

Sample code:

admin:WebhookList webhooks = check shopify->getWebhooks(topic = "orders/create");

Sample response:

{
"webhooks": [
{
"id": 1071340091,
"address": "https://example.com/webhooks/orders",
"topic": "orders/create",
"format": "json",
"created_at": "2024-01-10T08:00:00-05:00"
}
]
}
createWebhook

Creates a new webhook subscription by specifying both an address and a topic.

Parameters:

NameTypeRequiredDescription
payloadCreateWebhookYesThe webhook subscription object to be created.

Returns: WebhookObject|error

Sample code:

admin:WebhookObject webhook = check shopify->createWebhook({
webhook: {
topic: "orders/create",
address: "https://example.com/webhooks/orders",
format: "json"
}
});

Sample response:

{
"webhook": {
"id": 1071340092,
"address": "https://example.com/webhooks/orders",
"topic": "orders/create",
"format": "json",
"created_at": "2024-01-28T12:00:00-05:00"
}
}
getWebhook

Retrieves a single webhook subscription by its ID.

Parameters:

NameTypeRequiredDescription
webhookIdstringYesThe webhook ID.
fieldsstring?NoComma-separated list of fields to include.

Returns: WebhookObject|error

Sample code:

admin:WebhookObject webhook = check shopify->getWebhook("1071340091");

Sample response:

{
"webhook": {
"id": 1071340091,
"address": "https://example.com/webhooks/orders",
"topic": "orders/create",
"format": "json"
}
}
updateWebhook

Updates a webhook subscription's topic or address URI.

Parameters:

NameTypeRequiredDescription
webhookIdstringYesThe webhook ID.
payloadUpdateWebhookYesThe webhook object with updated fields.

Returns: WebhookObject|error

Sample code:

admin:WebhookObject updated = check shopify->updateWebhook("1071340091", {
webhook: {
address: "https://new-endpoint.example.com/webhooks/orders"
}
});

Sample response:

{
"webhook": {
"id": 1071340091,
"address": "https://new-endpoint.example.com/webhooks/orders",
"topic": "orders/create"
}
}
getWebhookCount

Retrieves a count of existing webhook subscriptions, optionally filtered by address or topic.

Parameters:

NameTypeRequiredDescription
addressstring?NoFilter by the URI that receives the POST request.
topicstring?NoFilter by webhook topic.

Returns: WebhookCountObject|error

Sample code:

admin:WebhookCountObject count = check shopify->getWebhookCount();

Sample response:

{
"count": 4
}