Box Windows SDK V2 - how to access enterprise webhooks V2 via API?
回答済みSituation: I have a custom application that interacts with the Box API via JWT auth. Everything is working great except for one issue.
My users are able to subscribe to different folder events similarly to how you can do so on Box itself - they just look at a list of checkboxes for different folder events we support, and choose which event they wish to subscribe to. I've implemented this by creating (or updating, if already exists for the given user-folder combo) a webhook. The webhook notification payload is properly received by an endpoint on our app, and it's parsed so we can do whatever with it (generate emails using our own email system, etc). So everything seems to be set up correctly - we create/update the webhooks using the Box Windows SDK V2 (using, for example, the userClient.WebhooksManager.CreateWebhookAsync) method.
The Problem:
I realize I made a mistake, and that the notification payload has a "created_by" field that isn't the user who created the webhook, as I had assumed (oops, my bad for not looking carefully), but rather the user who triggered the event that is sending the notification (which makes sense if I'd been paying attention, since it's a created_by field in a webhook_event type object, I just got confused by the same field name being used in different places).
That's great - but now I'm not sure how my webhook receiver can get at the user information for the user who created the webhook (not the user who triggered the event - the user who created the webhook in the first place)? When I try to look up the webhook using an admin token (using adminClient.WebHooksManager.GetWebhookAsync()) I get a 404 not found. When I try to look up all webhooks using an admin token (using adminClient.WebhooksManager.GetWebhooksAsync()) it's an empty list. So I'm in kind of a chicken and egg situation where I need to look up the user who created the webhook, but I only have access to the webhook ID in the notification payload, but it seems that the only way I can access the webhook is by already knowing what user created it?
Does this mean I'm going to have to create some table in our own application to map users to webhooks? We were trying to keep as much of this stuff out of our own database as possible.
-
Actually never mind - the writing it out actually helped me think through the problem some and I went with a solution where every webhook we create actually had a distinct URL for each user (so, before our notification payload parsing URL was just static, for example /api/BoxNotifications. Now when the user creates the webhook, we assign the webhook a URL of, for example, /api/BoxNotifications/{userId}, so that we can just take it in as a parameter directly).
Hopefully some other folks learn from my mistake/misunderstanding.
サインインしてコメントを残してください。
コメント
1件のコメント