Tool

Query Shopify Store Data via GraphQL

Run GraphQL queries against a Shopify store from a LlamaIndex agent.

Works with shopify

73
Spark score
out of 100
Updated 2 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Automate access to your Shopify store's data. This tool enables agents to execute GraphQL queries for retrieving information or performing actions directly within your Shopify admin.

Outcomes

What it gets done

01

Execute GraphQL queries against Shopify.

02

Retrieve product, order, and customer data.

03

Perform data mutations within the Shopify store.

04

Integrate with AI agents for automated data management.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-tool-tools-shopify | bash

Overview

Shopify Tool

A LlamaIndex tool that lets an agent run GraphQL queries and mutations against a Shopify store's Admin API. Use when an agent needs to fetch or change Shopify store data by writing GraphQL, ideally paired with schema lookup.

What it does

The Shopify Tool acts as a custom app for a Shopify store, giving a LlamaIndex agent the ability to execute GraphQL queries and mutations against the store's Admin API. The ShopifyToolSpec is initialized with the store domain, an API version, and an API key, and exposes a single tool the agent can call to run GraphQL directly against the store.

The source shows the tool paired with an OnDemandLoaderTool built from an UnstructuredReader, pointed at a local file containing the Shopify GraphQL schema. This second tool lets the agent look up the schema and get help writing correct GraphQL queries before executing them - so the agent is not just running queries blind, it can consult the schema documentation on demand for questions like what fields are available on an object or how to write a query for a specific task.

When to use - and when NOT to

Use it when you want an agent to answer questions about a Shopify store's data or perform actions against it - fetching products, checking orders, or running store-management mutations - by generating and executing GraphQL rather than calling fixed REST endpoints. Pairing it with the schema-lookup tool is recommended so the agent can correct its own query mistakes by consulting the schema instead of guessing. Because the tool can execute mutations as well as queries, be deliberate about what operations the store's API key is scoped to allow, since a mutation can change live store data.

Capabilities

run_graphql_query executes a GraphQL query or mutation against the Shopify Admin API for the configured store, returning the result for the agent to interpret.

How to install

pip install llama-index llama-index-readers-file llama-index-tools-shopify unstructured

Requires a Shopify store domain, an Admin API version string, and an API key with the appropriate access scopes.

Who it's for

Developers building LlamaIndex agents for Shopify store owners - chat-style assistants that can query or update store data on request by writing and running GraphQL against the Admin API.

Source README

Shopify Tool

This tool acts as a custom app for Shopify stores, allowing the Agent to execute GraphQL queries to gather information or perform mutations against the Shopify store.

Usage

This tool has more extensive example usage documented in a Jupyter notebook here

In particular, the tool is very effective when combined with a method of retrieving data from the GraphQL schema definition.

pip install llama-index llama-index-readers-file llama-index-tools-shopify unstructured
from llama_index.tools.shopify import ShopifyToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI

from llama_index.readers.file import UnstructuredReader
from llama_index.core.tools.ondemand_loader_tool import OnDemandLoaderTool

documentation_tool = OnDemandLoaderTool.from_defaults(
    UnstructuredReader(),
    name="graphql_writer",
    description="""
        The GraphQL schema file is located at './data/shopify_graphql.txt', this is always the file argument.
        A tool for processing the Shopify GraphQL spec, and writing queries from the documentation.

        You should pass a query_str to this tool in the form of a request to write a GraphQL query.

        Examples:
            file: './data/shopify_graphql.txt', query_str='Write a graphql query to find unshipped orders'
            file: './data/shopify_graphql.txt', query_str='Write a graphql query to retrieve the stores products'
            file: './data/shopify_graphql.txt', query_str='What fields can you retrieve from the orders object'
        """,
)


shopify_tool = ShopifyToolSpec(
    "your-store.myshopify.com", "2023-04", "your-api-key"
)

agent = FunctionAgent(
    tools=[*shopify_tool.to_tool_list(), documentation_tool],
    llm=OpenAI(model="gpt-4.1"),
    system_prompt=f"""
    You are a specialized Agent with access to the Shopify Admin GraphQL API for this Users online store.
    Your job is to chat with store owners and help them run GraphQL queries, interpreting the results for the user

    You can use graphql_writer to query the schema and assist in writing queries.

    If the GraphQL you execute returns an error, either directly fix the query, or directly ask the graphql_writer questions about the schema instead of writing graphql queries.
    Then use that information to write the correct graphql query
    """,
)

print(await agent.run("What products are in my store?"))

run_graphql_query: Executes a GraphQL query against the Shopify store

This loader is designed to be used as a way to load data as a Tool in a Agent.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.