Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from graphqlclient import GraphQLClient
- # Replace these with your actual Shopify credentials
- SHOPIFY_API_VERSION = "2023-07"
- SHOPIFY_ACCESS_TOKEN = "your_shopify_access_token"
- SHOPIFY_SHOP_URL = "your-shop-url.myshopify.com"
- # Create a GraphQL client
- client = GraphQLClient(f"https://{SHOPIFY_SHOP_URL}/admin/api/{SHOPIFY_API_VERSION}/graphql.json")
- client.inject_token(f"Bearer {SHOPIFY_ACCESS_TOKEN}")
- # Define the GraphQL mutation for creating a webhook
- mutation = """
- mutation webhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $callbackUrl: URL!) {
- webhookSubscriptionCreate(topic: $topic, webhookSubscription: {callbackUrl: $callbackUrl, format: JSON}) {
- userErrors {
- field
- message
- }
- webhookSubscription {
- id
- topic
- callbackUrl
- }
- }
- }
- """
- # Variables for the mutation
- variables = {
- "topic": "ORDERS_CREATE", # Change this to the event you want to subscribe to
- "callbackUrl": "https://your-callback-url.com/webhook" # Replace with your webhook URL
- }
- # Execute the mutation
- result = client.execute(mutation, variables)
- print("Result:", result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement