Skip to content

Shopify

ShopifyToolSpec #

Bases: BaseToolSpec

Shopify tool spec.

Source code in llama-index-integrations/tools/llama-index-tools-shopify/llama_index/tools/shopify/base.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class ShopifyToolSpec(BaseToolSpec):
    """Shopify tool spec."""

    spec_functions = ["run_graphql_query"]

    def __init__(self, shop_url: str, api_version: str, admin_api_key: str):
        # Currently only supports Admin API auth
        # https://shopify.dev/docs/apps/auth/admin-app-access-tokens
        from shopify import Session, ShopifyResource

        session = Session(shop_url, api_version, admin_api_key)
        ShopifyResource.activate_session(session)

    def run_graphql_query(self, graphql_query: str):
        """
        Run a GraphQL query against the Shopify Admin API.

        Example graphql_query: {
              products (first: 3) {
                edges {
                  node {
                    id
                    title
                    handle
                  }
                }
              }
            }

        providing this query would return the id, title and handle of the first 3 products
        """
        from shopify import GraphQL

        return GraphQL().execute(graphql_query)

run_graphql_query #

run_graphql_query(graphql_query: str)

Run a GraphQL query against the Shopify Admin API.

{

products (first: 3) { edges { node { id title handle } } }

}

providing this query would return the id, title and handle of the first 3 products

Source code in llama-index-integrations/tools/llama-index-tools-shopify/llama_index/tools/shopify/base.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def run_graphql_query(self, graphql_query: str):
    """
    Run a GraphQL query against the Shopify Admin API.

    Example graphql_query: {
          products (first: 3) {
            edges {
              node {
                id
                title
                handle
              }
            }
          }
        }

    providing this query would return the id, title and handle of the first 3 products
    """
    from shopify import GraphQL

    return GraphQL().execute(graphql_query)