Skip to main content

Hello,

I’m working on a Python script to determine coupon usage by my WooCommerce customers and issue new ones based on previously used coupons. Part of my logic requires me to obtain a list of WooCommerce order data for specific order IDs to extract coupon usage.

 

I read about using HTTP requests via Python (Code by Zapier) and have been stuck trying to figure out how to actually use the API correctly to make a GET request to my WooCommerce store.

 

I’ve tried searching through Google, Zapier forums, and read through the technical docs to find similar examples and instance, and tried many different kinds payload configurations but I can’t figure it out. It’s the last thing I need to sort out before I can deploy the pipeline.

References: 

  1. https://docs.tectalic.com/woocommerce-zapier/developer-documentation/#rest-api-endpoints
  2. https://github.com/kennethreitz/requests/blob/v2.8.1/docs/user/quickstart.rst#make-a-request

Below is a shortened version of test code I have, what am I missing?

How can I go about updating my request for multiple order IDs? Loop and store into a variable?

import requests

payload = {
'Authorization': Basic CONSUMERKEY|CONSUMERPASSWORD,
'content-type': 'application/json'
}

# 25303 is an Order Id
response = requests.get('https://mywebsite.com/wp-json/wc-zapier/v1/orders/25303',headers=payload)

 

I tried something else but I keep getting a 406. Im following what I think is correct syntax. Any thoughts?

 

Im using a known good CONSUMERKEY and CONSUMERSECRET that I know works from a Zapier Webhook in a different Zap.

 

import requests
from requests.auth import HTTPBasicAuth

# Order ID is 25303
response = requests.get('https://mywebsite.com/wp-json/wc-zapier/v1/orders/25303', auth=HTTPBasicAuth('CONSUMERKEY', 'CONSUMERSECRET'))

 


Hi ​@nadiyascupcakes 

TIP: Try asking ChatGPT for help with the Code and API requests.

 

For us to have full context, post screenshots showing how your Zap Code step is configured in EDIT mode with the inputs visible.

 

✅ Step-by-step: Making HTTP calls in Code by Zapier

  1. Trigger
    Start with a trigger—could be a scheduled Zap, webhook, or WooCommerce trigger—that provides the input you need (e.g., coupon_id, customer_email, etc.).

  2. Python Code step Setup

    • Choose “Code by Zapier” → “Run Python”.

    • Provide any necessary input under Input Data (e.g., api_url, consumer_key, consumer_secret).

  3. Example Python structure:

    import requests

    # Access your inputs
    url = input_datab'api_url']
    ck = input_data<'consumer_key']
    cs = input_data<'consumer_secret']

    # Perform HTTP GET
    response = requests.get(url, auth=(ck, cs))
    response.raise_for_status() # checks for errors

    data = response.json()
    # Do anything with data; e.g., extract coupon usage:
    usage = data.get('usage_count')

    # Return values via dictionary
    return {'usage_count': usage, 'raw': data}
    You can also do POST, PUT, DELETE with requests.post(), etc.—just swap in JSON payloads and appropriate headers.

Hello,

Thanks for your response.

Just to clarify, I just need help with the HTTP request and not how to write the script. I have everything else covered. Right now I am hardcoding all the CONSUMERKEY and CONSUMERSECRET values just to make sure I can get request to work so what I provided should be enough. 

Please advise on the actual requests syntax and usage.


@nadiyascupcakes 

Did you try asking ChatGPT for help by sharing your code and the app API endpoint docs, and prompt for help configuring the Python Code for the Zap Code step?

 

WooCommerce API: https://woocommerce.github.io/woocommerce-rest-api-docs/#introduction

 

Help links for using Code Zap app: https://zapier.com/apps/code/integrations#help

 


Incredible! Yes the AI was able to provide me a syntactically corrected response.

Thanks a ton for your help; I’ll make note of this for future reference.

 

For those wondering, this is what worked

import requests
from requests.auth import HTTPBasicAuth

header = {
'User-Agent': 'Zapier',
'Content-Type': 'application/json'
}

#Order ID is 25303
response = requests.get('https://yourwebsite.com/wp-json/wc-zapier/v1/orders/25303', headers=header, auth=HTTPBasicAuth('CONSUMERKEY', 'CONSUMERSECRET'))

 


Wow! Thank you for confirming that Troy’s suggestion got the Zap running. This will significantly help our Community members to have as a reference for the same issue.