> ## Documentation Index
> Fetch the complete documentation index at: https://developer.lulacommerce.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Upsert Store Menu

> Update or insert (upsert) a store menu with new configuration, operating hours, and settings.

This endpoint allows you to update an existing menu or create a new one if it doesn't exist, providing flexibility for menu management operations.

<Info>
  Upsert operations are ideal for menu synchronization and bulk updates, allowing you to maintain consistent menu configurations across multiple stores or update existing menus with new operating hours.
</Info>

### Path Parameters

<ParamField path="store_id" type="string" required>
  The unique identifier of the store for which to upsert the menu
</ParamField>

### Query Parameters

<ParamField query="menu_id" type="string" required>
  The unique identifier of the menu to update, or leave empty to create a new menu
</ParamField>

### Request Body

<ParamField body="menu_name" type="string" required>
  Display name for the menu
</ParamField>

<ParamField body="is_default" type="boolean" required>
  Whether this menu should be the default menu for the store
</ParamField>

<ParamField body="status" type="string" required>
  Menu status: "active" or "inactive"
</ParamField>

<ParamField body="menu_hours" type="array" required>
  Array of operating hours for each day of the week, including existing IDs for updates

  <Expandable title="Menu Hours Object">
    <ParamField body="day_of_week" type="integer" required>
      Day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
    </ParamField>

    <ParamField body="open_time" type="string" required>
      Opening time in HH:MM format (24-hour)
    </ParamField>

    <ParamField body="close_time" type="string" required>
      Closing time in HH:MM format (24-hour)
    </ParamField>

    <ParamField body="is_closed" type="boolean" required>
      Whether the store is closed on this day
    </ParamField>

    <ParamField body="id" type="string" optional>
      Existing menu hour ID (for updates)
    </ParamField>

    <ParamField body="menu_id" type="string" optional>
      Parent menu ID (for existing menu hours)
    </ParamField>
  </Expandable>
</ParamField>

### Request Example

```json theme={null}
{
  "menu_name": "Lula item schoping test menu",
  "is_default": false,
  "status": "active",
  "menu_hours": [
    {
      "day_of_week": 0,
      "open_time": "00:00",
      "close_time": "01:00",
      "is_closed": false,
      "id": "6445fd02-ba77-49c9-9147-914520c46cfb",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 0,
      "open_time": "10:00",
      "close_time": "12:00",
      "is_closed": false,
      "id": "ca60d563-098a-4353-bac5-76c92b01d85c",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 1,
      "open_time": "01:00",
      "close_time": "03:59",
      "is_closed": false,
      "id": "3c699321-aa44-4e6a-9a30-e801d61b511a",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 1,
      "open_time": "10:00",
      "close_time": "17:00",
      "is_closed": false,
      "id": "9cc1f27d-0b60-41ae-8a7c-88e163af9d74",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 2,
      "open_time": "00:00",
      "close_time": "03:59",
      "is_closed": false,
      "id": "e334adad-c4ea-47c9-8b89-70f3d382b44f",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 2,
      "open_time": "10:00",
      "close_time": "17:00",
      "is_closed": false,
      "id": "d5de2e83-f6a8-4a3b-969b-8f021fcb7b8c",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 3,
      "open_time": "00:00",
      "close_time": "03:59",
      "is_closed": false,
      "id": "b7d7470a-20bf-447f-8fb3-166d605d8817",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 3,
      "open_time": "10:00",
      "close_time": "17:00",
      "is_closed": false,
      "id": "4ca9ce73-7c51-4529-8ed3-1d968d24d6a9",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 4,
      "open_time": "10:00",
      "close_time": "17:00",
      "is_closed": false,
      "id": "94bc7141-f44f-44e4-bfe4-062d6cb9b6e5",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 5,
      "open_time": "10:00",
      "close_time": "17:00",
      "is_closed": false,
      "id": "fb1b46d6-3c81-46fc-b45b-6ec9f1a4ad87",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    },
    {
      "day_of_week": 6,
      "open_time": "10:00",
      "close_time": "17:00",
      "is_closed": false,
      "id": "bc421e4a-5b9f-49c3-867e-56114a0912c2",
      "menu_id": "17137644-0017-4284-b15d-4605b092f063"
    }
  ]
}
```

<Accordion title="Upsert Operation Behavior">
  **Create Mode (New Menu)**

  * When menu\_id is not provided or doesn't exist
  * Creates a new menu with all provided configuration
  * Generates new IDs for menu and menu hours
  * Sets creation timestamps and user information

  **Update Mode (Existing Menu)**

  * When menu\_id matches an existing menu
  * Updates menu configuration and operating hours
  * Preserves existing IDs where provided
  * Updates modification timestamps

  **Hybrid Operations**

  * Can add new menu hours while updating existing ones
  * Removes menu hours not included in the request
  * Supports partial updates of operating schedules
  * Maintains data integrity during complex changes
</Accordion>

<Note>
  **Multiple Time Slots**: This endpoint supports multiple opening/closing periods for the same day, allowing for complex scheduling like lunch breaks or split shifts.
</Note>

<Tip>
  **Efficient Updates**: Include existing IDs in menu\_hours objects to update existing entries rather than recreating them, which preserves audit trails and related data.
</Tip>

### Use Cases

<Accordion title="Common Upsert Scenarios">
  **Menu Synchronization**

  * Sync menu configurations across multiple store locations
  * Maintain consistent operating hours across franchise locations
  * Update multiple menus with new corporate policies

  **Schedule Adjustments**

  * Modify operating hours for seasonal changes
  * Add special hours for holidays or events
  * Implement temporary schedule modifications

  **Complex Operating Hours**

  * Configure multiple opening periods per day
  * Set up lunch break closures or split shifts
  * Handle 24-hour operations with midnight transitions

  **Menu Template Application**

  * Apply standardized menu templates to new stores
  * Update existing menus to match new corporate standards
  * Implement brand-wide menu changes efficiently
</Accordion>

### Split-Day Operations

<Accordion title="Managing Complex Schedules">
  **Multiple Time Periods per Day**

  * Early morning hours (00:00-01:00)
  * Regular business hours (10:00-17:00)
  * Late evening service (22:00-23:59)

  **Lunch Break Management**

  * Morning hours (09:00-12:00)
  * Afternoon hours (13:00-17:00)
  * Closed period for lunch (12:00-13:00)

  **24-Hour Operations**

  * Continuous service across midnight
  * Day 0: 22:00-23:59
  * Day 1: 00:00-06:00

  **Special Event Scheduling**

  * Extended hours for promotions
  * Limited hours for maintenance
  * Holiday-specific operating schedules
</Accordion>

### Data Validation

<Accordion title="Validation Rules and Constraints">
  **Time Format Validation**

  * Times must be in HH:MM format (24-hour)
  * Opening time must be before closing time (within the same day)
  * Times must be valid (00:00 to 23:59)

  **Day of Week Validation**

  * Must be integers between 0 and 6
  * 0 = Sunday, 6 = Saturday
  * Each day can have multiple time periods

  **Menu Configuration Validation**

  * Menu name must be non-empty and unique within the store
  * Status must be "active" or "inactive"
  * is\_default must be boolean

  **ID Validation**

  * Existing IDs must reference valid menu hours
  * menu\_id in query parameter must match existing menu for updates
  * Invalid IDs will be ignored and new entries created
</Accordion>

### Error Handling

<Accordion title="Common Error Scenarios">
  **Invalid Menu ID**

  ```json theme={null}
  {
    "error": "Menu not found",
    "message": "The specified menu_id does not exist for this store"
  }
  ```

  **Time Validation Errors**

  ```json theme={null}
  {
    "error": "Invalid time range",
    "message": "Opening time must be before closing time",
    "field": "menu_hours[0]"
  }
  ```

  **Conflicting Default Menus**

  ```json theme={null}
  {
    "error": "Multiple default menus",
    "message": "Cannot set multiple menus as default for the same store"
  }
  ```

  **Missing Required Fields**

  ```json theme={null}
  {
    "error": "Validation failed",
    "message": "menu_name is required",
    "field": "menu_name"
  }
  ```
</Accordion>

<Warning>
  **Data Overwrite**: Upsert operations can overwrite existing menu configurations. Ensure you include all desired menu hours in the request, as missing entries may be removed.
</Warning>

### Best Practices

<Accordion title="Upsert Implementation Best Practices">
  **Data Preparation**

  * Always retrieve current menu configuration before updating
  * Include existing IDs to preserve data relationships
  * Validate time ranges before submitting requests
  * Test complex schedules in staging environment

  **Error Prevention**

  * Check for time conflicts before submitting
  * Validate day\_of\_week values are within range
  * Ensure only one menu per store is set as default
  * Handle timezone considerations for multi-location businesses

  **Performance Optimization**

  * Batch multiple menu updates when possible
  * Use existing IDs to minimize database operations
  * Consider the impact of frequent menu changes on customer experience
  * Implement proper error handling and retry logic

  **Audit and Compliance**

  * Track who makes menu changes and when
  * Maintain history of menu modifications
  * Document business justification for schedule changes
  * Review menu performance after updates
</Accordion>
