Webhooks - Not receiving request of verification in Python
I am using this function
logging.basicConfig(filename='automation.log', level=logging.INFO)
smartsheet_client = smartsheet.Smartsheet(SMARTSHEET_API_KEY)
def create_webhook(sheet_id: int, callback_url: str):
"""Create a webhook for the specified sheet and verify it."""
# Create the webhook
webhook = smartsheet_client.Webhooks.create_webhook(
smartsheet.models.Webhook({
'name': 'name',
'scope': 'sheet',
'scopeObjectId': sheet_id,
'callbackUrl': callback_url,
'events': ['*.*'],
'version': 1
})
)
logging.info(f"Webhook created successfully: {webhook}")
# Enable the webhook to initiate the verification process
update_webhook(webhook.result.id)
# Wait for verification to complete
while True:
time.sleep(5) # Wait for 5 seconds before checking again
updated_webhook = get_webhook(webhook.result.id)
if updated_webhook.status == 'ENABLED':
logging.info("Webhook verification completed successfully.")
break
elif updated_webhook.status == 'DISABLED_VERIFICATION_FAILED':
logging.error("Webhook verification failed.")
break
def update_webhook(webhook_id: int):
"""Update the enabled status of the webhook."""
smartsheet_client.Webhooks.update_webhook(
webhook_id,
smartsheet.models.Webhook({
'enabled': enabled
})
)
def get_webhook(webhook_id: int):
"""Retrieve the details of the specified webhook."""
return smartsheet_client.Webhooks.get_webhook(webhook_id)
And i have a fastapi endpoint
@app.post("/webhook")
async def handle_webhook(challenge: str, webhookId: int, smartsheet_hook_challenge: str = Header(None)):
# Verify that the received challenge matches the value in the header
if challenge != smartsheet_hook_challenge:
raise HTTPException(status_code=400, detail="Invalid challenge")
# Construct the response containing the same challenge value
response_body = {"smartsheetHookResponse": challenge}
But i am not receiving any request for verification . Please help!
Answers
-
Looks like you accidentally posted this twice. I replied here: https://community.smartsheet.com/discussion/comment/422304/#Comment_422304
Categories
- All Categories
- 14 Welcome to the Community
- Smartsheet Customer Resources
- 64.2K Get Help
- 419 Global Discussions
- 221 Industry Talk
- 461 Announcements
- 4.8K Ideas & Feature Requests
- 143 Brandfolder
- 141 Just for fun
- 58 Community Job Board
- 462 Show & Tell
- 32 Member Spotlight
- 1 SmartStories
- 299 Events
- 38 Webinars
- 7.3K Forum Archives