-
-
Notifications
You must be signed in to change notification settings - Fork 723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webhook triggered on Order Cycle Open #9616
Comments
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Reading through this I was just wondering if the 'API' tab should only be visible if the 'API view' is activated for this user (in admin/users/ ID /edit)? Just like the display of the API key in the user account? @lin-d-hop |
Hi @lin-d-hop , Maikel has raised a good question about which enterprises for an order cycle should be notified? Perhaps we could make the event type name more specific to support each possibility in the future. Eg:
I'm still getting familiar with how things work so I might be over-thinking it. Let me know what you think. Also can you please answer Konrad's question above? |
My feeling is probably that it doesn't need to be that complicated - perhaps any coordinator, distributor or supplier in the OC can subscribe? and it's the same information for all of them? But then I wonder why only them . . this is information that we will likely want to use on other sites like discovery sites . . so perhaps we do
|
Re @drummer83's questions - as this is API v1 I would like this to be visible for all shopfronts. The API is pubic and having this visible in the UI to everyone will enable people to understand they can use the API. In the case that the 'API key view' is not enabled for the user, can we display a message 'Please contact your instance manager to enable API access.' Ping @kirstenalarsen @RachL are you happy with this? Re who should receive: |
Hey @lin-d-hop - updates above look all good except that i think we agreed that the webhook would be for all enterprises that the User manages and would trigger when those enterprises were either Coordinator or Distributor on the order cycle But we are not including when User is manager of enterprises that are Suppliers on the Order Cycle We also discussed including the Supplier Enterprise IDs in the payload, so that the Coordinator could easily set up an integration to send notifications to them if they wanted? Should all this go into amended scope above or you are seeing as separate issues? |
I thought that's what I wrote.... will reword to clarify. Re supplier ids - I saw this as a potential additional issue. Another solution would be an OC endpoint that could be called after the webhook with full OC details. Might be preferable. |
Payload formatI've set up the proof of concept with a slightly different format to the above. Any issues?
|
User interfaceAs discussed, this is a per-user setting. With the expectation that there will be other types of webhook, I've set up a table format (preview here). The table format won't be as conducive to showing an example of the full data structure, so I wonder if we can omit this? Maybe we can have a more general description at the bottom of the table, and link to full documentation.. DocumentationHmm, this would require a similar type of documentation to the OpenAPI (swagger) documentation that we generate for the API. I need to learn more about how these can work together... |
This is all looking brilliant! Thanks @dacook! Thanks for you corrections to the spec 👌 |
Note to notify this forum thread once complete: https://community.openfoodnetwork.org/t/collaborative-logistics-tool-call-for-help-to-develop-api/2667/12 |
📚 Regarding documentation: But it requires the latest version of OpenAPI (3.1), which Rswag doesn't support yet (looks like they're low on maintainers). We might also need to update the existing spec. So I think we leave this to consider in the future. |
📚 Draft documentation |
Description
As an API user I want to be notified when an OC opens.
As an API user I want to be able to turn notifications on and off
Acceptance Criteria & Tests
EDIT
We need to be able to turn webhook posting on and off via the UI. This should be done via and additional tab in 'Enterprise Settings' called 'API'. This tab should only be visible for enterprises with shopfronts enabled.In product call 26/10 we made the decision to have all API settings at the User level in Developer Settings. The intention is to create the framework for another user type - API user.
The UI will exist in https://openfoodnetwork.org.uk/account#/developer_settings
This UI is visible when super-admin enables 'API Key View' for the user.
This setting will be called 'Post webhook on Order Cycle Open'. In line with other settings two radio buttons will denote enabled/disabled:
When 'enabled' a url is shown where the payload will be sent to.
The webhook payload will be triggered when an OC opens for any enterprises this user manages and owns. It is applicable for all distributor and coordinator enterprises (and not for one's for which the user supplies only).
A tooltip should be included saying 'This will trigger a webhook to post the following payload to the given URL when an order cycle opens:
"id": STRING,
"at": DATETIME,
"type": "order_cycle_open",
"data": {
"id": INTEGER,
"name": STRING,
"open_at": DATETIME,
"close_at": DATETIME,
"enterprise_id": INTEGER,
"enterprise_name": STRING
"tags": [STRING]
}"
The payload delivered should be:
"id": STRING (ID of the webhook)
"at": DATETIME (when payload sent)
"type": "order_cycle_open",
"data": {
"id": INTEGER (ID of the OC)
"name": STRING (name of the OC)
"open_at": DATETIME (OC opening time)
"close_at": DATETIME (OC closing time)
"enterprise_id": INTEGER (enterprise ID in DB)
"enterprise_name": STRING (enterprise name)
"tags": [STRING] (tags on the OC)
}
For example:
{
"id": "EV09374580",
"at": "2022-06-15T04:18:00-04:00",
"type": "order_cycle_open",
"data": {
"id": 79234596,
"name": "Aug 3rd"
"open_at": "2022-06-15T04:18:00-04:00",
"close_at": "2022-07-15T04:18:00-04:00",
"enterprise_id": 2093846
"enterprise_name": "Fictional Hub"
}
}
Other useful Bits
This tutorial looks good:
https://keygen.sh/blog/how-to-build-a-webhook-system-in-rails-using-sidekiq/
The text was updated successfully, but these errors were encountered: