Menu Management and Resync
Managing a menu often means more than simply creating, updating, and deleting individual menu items. Sometimes you have to perform actions on a multitude of items. This is where menu management comes in.
Fetching All Menu Items
Not sure what menu items are in a menu? You can fetch a paginated list of menu items using the API, with a default page size of 100. This will return a list of menu items currently available for the provided listing. If you have more than 100 items in your menu or have specified a smaller limit, you can fetch the next page by incrementing the page[offset]
query parameter.
curl \
--request GET \
--url 'https://api-g.weedmaps.com/wm/v1/listings/12345678/menu_items' \
--header 'accept: application/json' \
--header 'authorization: Bearer [ACCESS TOKEN HERE]'
Resyncing a Menu
We allow listing owners to mutate menu items after they've been sent over. This allows them to fill in any data that your API might not support yet, like imagery. As such, it's quite possible that they can make changes that you'll have a hard time reverting.
In these situations, it's best to have some type of resync functionality built on your side. There are a couple of different ways we have seen this done:
Diffing
One option is to fetch all the menu items for a listing, diff them from what you have in your system, and send the proper creates, updates, and deletes to get things back to how you have them. The advantage of this option is that it doesn't impact the additive information — like an image — a listing owner may have painstakingly added one by one. The obvious disadvantage is the complexity of building out a diffing algorithm for an external API.
Delete and Repush
The other option is to delete everything from the menu and start over again. This is the much simpler approach, but does have its drawbacks. The main downside of this option is that any information added by the listing owner is effectively removed. You also remove any items that might be in someone's cart that they're ready to order.
Step 1: Fetch All Menu Items
Don't forget the menu items endpoint is paginated, so it may take more than one request to get everything you need.
curl \
--url 'https://api-g.weedmaps.com/wm/v1/listings/{wmid}/menu_items?page[limit]=100&page[offset]=0' \
--header 'accept: application/json' \
--header 'authorization: Bearer [ACCESS TOKEN HERE]'
Step 2: Delete Each Menu Item
Repeat this step for every menu item that was returned in step 1.
curl \
--request DELETE \
--url 'https://api-g.weedmaps.com/wm/v1/menu_items/{menu_item_id}' \
--header 'accept: application/json' \
--header 'authorization: Bearer [ACCESS TOKEN HERE]'
Step 3: Ensure Menu Items Are Cleared
You should see an empty response returned if you've removed everything from the menu. If you still see items, repeat the above.
curl \
--url 'https://api-g.weedmaps.com/wm/v1/listings/{wmid}/menu_items?page[limit]=100&page[offset]=0' \
--header 'accept: application/json' \
--header 'authorization: Bearer [ACCESS TOKEN HERE]'
Updated almost 2 years ago