shopify_python_api library what is proper query structure for Variables, PageInfo and Cursor

Highlighted
New Member
1 0 0

Hello,

I'm new to GraphQL, and this my first time working with Shopify_python_api library. What is the proper query structure?

I'm trying to run this query to get started:

client = shopify.GraphQL()
query = '''
    getFirstOrdersCursor($numOrders: Int, $numLineItems: Int)
{
    orders(first:$numOrders) {
        pageInfo {
            hasNextPage
        }
        edges {
            cursor
            node {
                id
                lineItems (first:$numLineItems) {
                    edges {
                        node {
                            id
                        }
                    }
                }
            }
        }
    }
}
'''

variables = {
    "numOrders": 10,
    "numLineItems": 5
}

client.execute(query, variables)
'{"errors":[{"message":"Parse error on \\"getFirstOrdersCursor\\" (IDENTIFIER) at [2, 5]","locations":[{"line":2,"column":5}]}]}'
Or this query:
client = shopify.GraphQL()

query0 = '''getDraftOrderByID($id: ID!) 
{
    draftOrder (id: $id) {
        totalPrice
        lineItems (first: 5) {
            edges {
                node {
                    originalUnitPrice
                    quantity
          title
                }
            }
        }
    }
}
'''
variables = {
    "id": "gid://shopify/DraftOrder/561251483788"
}

client.execute(query0, variables)
please point me into right direction.
 
0 Likes
Highlighted
Shopify Staff
Shopify Staff
491 97 88

Hi @gola 

 

What i'd suggest is getting used to GraphQL before diving into using it in your project. You can create your queries here to ensure they are working with the API - and then utilize them within your app. https://shopify.dev/tools/graphiql-admin-api

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes