Advertisement
bagsari

Untitled

Aug 13th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. import requests
  2. from graphqlclient import GraphQLClient
  3.  
  4. # Replace these with your actual Shopify credentials
  5. SHOPIFY_API_VERSION = "2023-07"
  6. SHOPIFY_ACCESS_TOKEN = "your_shopify_access_token"
  7. SHOPIFY_SHOP_URL = "your-shop-url.myshopify.com"
  8.  
  9. # Create a GraphQL client
  10. client = GraphQLClient(f"https://{SHOPIFY_SHOP_URL}/admin/api/{SHOPIFY_API_VERSION}/graphql.json")
  11. client.inject_token(f"Bearer {SHOPIFY_ACCESS_TOKEN}")
  12.  
  13. # Define the GraphQL mutation for creating a webhook
  14. mutation = """
  15. mutation webhookSubscriptionCreate($topic: WebhookSubscriptionTopic!, $callbackUrl: URL!) {
  16.  webhookSubscriptionCreate(topic: $topic, webhookSubscription: {callbackUrl: $callbackUrl, format: JSON}) {
  17.    userErrors {
  18.      field
  19.      message
  20.    }
  21.    webhookSubscription {
  22.      id
  23.      topic
  24.      callbackUrl
  25.    }
  26.  }
  27. }
  28. """
  29.  
  30. # Variables for the mutation
  31. variables = {
  32.     "topic": "ORDERS_CREATE",  # Change this to the event you want to subscribe to
  33.     "callbackUrl": "https://your-callback-url.com/webhook"  # Replace with your webhook URL
  34. }
  35.  
  36. # Execute the mutation
  37. result = client.execute(mutation, variables)
  38. print("Result:", result)
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement