What I’m trying to do:
Host a webhook listener in order to capture a webhook’s JSON, wrangle it, and then push it somwhere else. For some reason though, the email trigger is being hit multiple times when it should just happen once.
What I’ve tried and what’s not working:
I have a server function that recieves a webhook and wrangles the data into a JSON to be used as the body for a PUSH
request to another API. It sends 1 PUSH
request per 1 POST
webhook that it receives.
Then based on the PUSH
response, I send an email to the target user notifying them of whether it failed or succeeded. However, it seems to be sending 2 to 3 emails per webhook event so I’m not sure why that’s happening.
Code Sample:
cd = {
"name": substance, #int
"locationid": int(locationID), #string
"substanceid": int(substanceID), #int
"supplier": vendor, #string
"containersize": containerSize, #int
"units": unitCode #int
"dateacquired": ciDate #string
}
# the endpoint returns array listing IDs of newly created items PUSHed to cheminventory
addsubstance = requests.post(
"https://app.cheminventory.net/api/container/add",
json = {
"authtoken": "blahblahblah",
"data": [cd] #required by API to be inside a list
}
)
# return object = [1, 2, 3, ...]
if addsubstance:
anvil.email.send(#email to me saying "Succeeded in adding blah to blah")
else:
anvil.email.send(#email to me saying "Failed in adding blah to blah")
So in essence, I’m receiving multiple success emails when addsubstance
is both a single-item array and multi-item array. I’m not sure why that’s happening because everything is supposed to just be done once.