# Menu

> Ajax API endpoints that return the store's navigation menus and the nested items of one menu, so a theme can render navigation from JavaScript.

The Menu API returns the store's navigation menus and the nested items inside one menu. Both endpoints are open to anonymous visitors.

All Ajax API requests should use [locale-aware URLs](/docs/theme/references/ajax-api/#locale-aware-urls) to give visitors a consistent experience.

## List the navigation menus of the store

```text
GET /{locale}/api/front/menus
```

List the navigation menus of the store, each with its nested items. Takes no parameters.

### Example request

**Example request**

```javascript
fetch(window.SHOPLAZZA.routes.root + '/api/front/menus')
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### Response

**Schema | Example**

- `data` object[]

  The response payload.

  *   Array [

  - `id` string

    ID of the navigation menu.
  - `title` string

    Name of the navigation menu.
  - `category` number
  - `children` object[]

    Sub-items of this navigation item.

    *   Array [

    - `id` number

      ID of the navigation item.
    - `title` string

      Label shown for the navigation item.
    - `origin_type` number
    - `type` string

      Type of resource the navigation item links to, for example `home`, `page` or `collection`.
    - `source_id` string

      ID of the resource the navigation item links to.
    - `url` string

      Relative URL the navigation item links to.
    - `pid` number

      ID of the parent navigation item; `0` for a top-level item.
    - `status` number
    - `disabled` number
    - `target` string

      Link target of the navigation item, for example `_blank` to open a new tab.
    - `url_obj` object

      Structured link information of the navigation item.

      - `type` string

        Type of resource the navigation item links to, for example `home`, `page` or `collection`.
      - `source_id` string

        ID of the resource the navigation item links to.
      - `url` string

        Relative URL the navigation item links to.
      - `title` string

        Label shown for the navigation item.
    - `expanded` boolean
    *   ]
  *   ]
- `msg` string

  Result message returned with the response.
- `state` number

  Request result flag; `success` or `0` means the request succeeded.

```json
{
  "data": [
    {
      "id": "header",
      "title": "Main menu",
      "category": 1,
      "children": [
        {
          "id": 83850217,
          "title": "Home",
          "origin_type": 15,
          "type": "home",
          "source_id": "0",
          "url": "/",
          "pid": 0,
          "status": 0,
          "disabled": 0,
          "target": "",
          "url_obj": {
            "type": "home",
            "source_id": "0",
            "url": "/",
            "title": ""
          },
          "expanded": true
        },
        {
          "id": 83850219,
          "title": "New Arrivals",
          "origin_type": 3,
          "type": "page",
          "source_id": "0",
          "url": "",
          "pid": 0,
          "status": 0,
          "disabled": 0,
          "target": "",
          "url_obj": {
            "type": "page",
            "source_id": "0",
            "url": "",
            "title": ""
          },
          "expanded": true,
          "children": [
            {
              "id": 83850221,
              "title": "Collection",
              "origin_type": 2,
              "type": "collection",
              "source_id": "0",
              "url": "",
              "pid": 83850219,
              "status": 0,
              "disabled": 0,
              "target": "",
              "url_obj": {
                "type": "collection",
                "source_id": "0",
                "url": "",
                "title": ""
              },
              "expanded": true
            }
          ]
        }
      ]
    }
  ],
  "msg": "请求成功",
  "state": 0
}
```

## Get a navigation menu

```text
GET /{locale}/api/front/menus/{menu_id}
```

Get one navigation menu with its nested items. `menu_id` is the handle of the menu, such as `header` or `footer`.

### Example request

**Example request**

```javascript
fetch(window.SHOPLAZZA.routes.root + '/api/front/menus/header')
  .then((response) => response.json())
  .then((data) => {
    // do something...
  });
```

### Request parameters

- `menu_id` string

  The handle of the menu, such as `header`.

### Response

**Schema | Example**

- `data` object

  The response payload.

  - `id` string

    ID of the navigation menu.
  - `title` string

    Name of the navigation menu.
  - `category` number
  - `children` object[]

    Sub-items of this navigation item.

    *   Array [

    - `id` number

      ID of the navigation item.
    - `title` string

      Label shown for the navigation item.
    - `origin_type` number
    - `type` string

      Type of resource the navigation item links to, for example `home`, `page` or `collection`.
    - `source_id` string

      ID of the resource the navigation item links to.
    - `url` string

      Relative URL the navigation item links to.
    - `pid` number

      ID of the parent navigation item; `0` for a top-level item.
    - `status` number
    - `disabled` number
    - `target` string

      Link target of the navigation item, for example `_blank` to open a new tab.
    - `url_obj` object

      Structured link information of the navigation item.

      - `type` string

        Type of resource the navigation item links to, for example `home`, `page` or `collection`.
      - `source_id` string

        ID of the resource the navigation item links to.
      - `url` string

        Relative URL the navigation item links to.
      - `title` string

        Label shown for the navigation item.
    - `expanded` boolean
    *   ]
- `msg` string

  Result message returned with the response.
- `state` number

  Request result flag; `success` or `0` means the request succeeded.

```json
{
  "data": {
    "id": "header",
    "title": "Main menu",
    "category": 1,
    "children": [
      {
        "id": 83850217,
        "title": "Home",
        "origin_type": 15,
        "type": "home",
        "source_id": "0",
        "url": "/",
        "pid": 0,
        "status": 0,
        "disabled": 0,
        "target": "",
        "url_obj": {
          "type": "home",
          "source_id": "0",
          "url": "/",
          "title": ""
        },
        "expanded": true
      },
      {
        "id": 83850219,
        "title": "New Arrivals",
        "origin_type": 3,
        "type": "page",
        "source_id": "0",
        "url": "",
        "pid": 0,
        "status": 0,
        "disabled": 0,
        "target": "",
        "url_obj": {
          "type": "page",
          "source_id": "0",
          "url": "",
          "title": ""
        },
        "expanded": true,
        "children": [
          {
            "id": 83850221,
            "title": "Collection",
            "origin_type": 2,
            "type": "collection",
            "source_id": "0",
            "url": "",
            "pid": 83850219,
            "status": 0,
            "disabled": 0,
            "target": "",
            "url_obj": {
              "type": "collection",
              "source_id": "0",
              "url": "",
              "title": ""
            },
            "expanded": true
          }
        ]
      }
    ]
  },
  "msg": "请求成功",
  "state": 0
}
```
