Recent searches


No recent searches

Zendesk Sell Python API - Sequences



Posted Dec 07, 2023

Hi,

There's not much documentation out there on the Zendesk Sell API in Python.  This post aims to be a quick jumpstart,  to enable an update of a Zendesk Sell Sequence.

The problem, if you're doing Sequences is that after you've reached a limit, say about 200 people in a day that have completed a sequence,  any more users selected will stay in "On-Going" and be blocked.

Without the API,  after about 24 hours, you need to go into Zedesk Sell, and manually unblock and resend.  This is a real pain.  

With the API,  you can just run the Python script below, and it will detect those with blocked sequences,  and set them to active again.  If you haven't reach your daily limit they will send out,  and now you can add more users to your sequence.

import requests
import json
import sys

url = "https://api.getbase.com/v2/sequence_enrollments"

headers = {
  'Accept': 'application/json',
  'Content-Type': 'application/json',
  'Authorization': 'Bearer abcdef0123456abcdef' # Replace with your key Sell->Settings->Integrations->OAuth
}

payload = json.dumps({
})


response = requests.request("GET", url, headers=headers, data=payload)

#print(response.text)

data = response.json()


num_items = (len(data["items"]))

print ("GOT {} ITEMS".format(num_items))

for i in range(0, num_items):

    item_id = (data["items"][i]["data"]["id"])
    item_state = (data["items"][i]["data"]["state"])

    if (item_state != 'blocked'):
        print ("========= RECORD [{}/{}], ITEM_ID {} ========".format(i, num_items, item_id))
    else:
        print ("[BLOCKED] RECORD [{}/{}], ITEM_ID {} ========".format(i, num_items, item_id))
        
        print (data["items"][i]["data"])
     
        print (">>>>>> DO AN UPDATE OF THE STATE")
        item_url = "https://api.getbase.com/v2/sequence_enrollments/{}".format(item_id)

        
        item_payload = json.dumps({
            "data": {
                "state": "active"
            }
        })

        item_response = requests.request("PUT", item_url, headers=headers, data=item_payload)

        item_data = item_response.json()

        print ("RESPONSE AFTER UPDATE")
        print (item_data)

        #break

Hope that helps!

Bill

Woodruff Engineering - where you can get your Magnets and Power Supplies.

 

 


0

0

0 comments

Sign in to leave a comment.

Didn't find what you're looking for?

New post