2

I can't guess how to get menu items from a specific menu via API.

I use:

https://github.com/alexandreelise/j4x-api-collection

https://documenter.getpostman.com/view/9617873/Szzj9yJy#6ac385da-724b-4b5b-b020-21c4d9fc9411

I get for example specific menu

{{base_url}}/{{base_path}}/menus/{{app}}/{{menu_id}}

But how to view menu items for this menu?

2 Answers 2

0

I don't see a way to do this at the moment. You can only list all menu items per application:

{{base_url}}/{{base_path}}/menus/{{app}}/items
0

In addition to what Sharky said, basically you need to add in Postman what is called a Api Test which is nothing more than javascript and the Chai JS library.

enter image description here

You see the tests tab

You need to add this code in the test tab to filter out just the menu items of a given menutype. On my example site I have mainmenu and then I created using the API another site menu with menutype "menu", then added a menu item to it again via the Api.

Now I had:

mainmenu:

  • menutitem1
  • menuitem2

and

menu:

  • menuitem3

With the following js code you can fetch only what you want using the tests tab of a request.


pm.test("My custom site menu only items", () => {
   const allMenuItems = pm.response.json();
   
   const menuTypeToFilterBy = 'menu';

   let onlySpecificMenuItems = allMenuItems['data'].filter((item) => {
       return item['attributes']['menutype'] === menuTypeToFilterBy;
   });

   console.log(onlySpecificMenuItems);
   
   //TODO: Do whatever you want with this filtered result

});


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.