And you should be able to construct a custom query to filter your products by different type or properties...
/umbraco/delivery/api/v2/content
Accepts filter options
But in terms of having this content returned via a custom route, then I don't think the delivery API is setup to allow the Url to be changed...
... but if it is important to return the content via a custom route then you could create your own UmbracoApiController, route it how you need, but you'd need to implement the getting of the content from the Umbraco published cache and returning the response.
Ok. Thanks for your input. I got you about the routing part. But how can I implement the getting of the content from the Umbraco published cache and returning the response, for content delievry content api specifically ?
And 'Creating a custom API endpoint' here has nothing to do with the Content Delivery Api, so you can use this approach to create your own endpoint at any Url, once you have mapped your custom route to an Api Controller, inside that controller you can inject IPublishedContentQuery to make requests to the Umbraco published cache and build your custom models to return on the API.
Here is an example of injecting IPublishedContentQuery into a controller:
So you probably need to decide if you want to have a specific Url or happy to use the Content Deliver Api Url format to pull back your content from Umbraco, and this will decide which approach you go for.
Headless Content ApI Custom Route
Hello there, hope you are doing great.
I am using Umbraco Headless Content Api in a project with nextjs.
Let's say I have different kinds of Products in Umbraco backoffice. I want to return these products using Content Api from a custom route ?
Is even it possible ? How can I do it ? Can anyone suggest a tutorial for it ?
Hi M. Umar
There is a pretty good introduction to the content delivery API here:
https://docs.umbraco.com/umbraco-cms/reference/content-delivery-api
And you should be able to construct a custom query to filter your products by different type or properties...
/umbraco/delivery/api/v2/content
Accepts filter options
But in terms of having this content returned via a custom route, then I don't think the delivery API is setup to allow the Url to be changed...
... but if it is important to return the content via a custom route then you could create your own UmbracoApiController, route it how you need, but you'd need to implement the getting of the content from the Umbraco published cache and returning the response.
https://docs.umbraco.com/umbraco-cms/v/12.latest/reference/routing/umbraco-api-controllers/routing#routing
https://docs.umbraco.com/umbraco-cms/reference/routing/umbraco-api-controllers#using-mvc-attribute-routing-in-umbraco-web-api-controllers
Regards
Marc
Ok. Thanks for your input. I got you about the routing part. But how can I implement the getting of the content from the Umbraco published cache and returning the response, for content delievry content api specifically ?
is there any tutorial for this ?
Hi M. Umar
If I understand your question correctly, they are two different things
Content Delivery API - a new thing added to Umbraco that allows you to request things from the Umbraco Published Cache via fixed routing endpoints:
https://docs.umbraco.com/umbraco-cms/reference/content-delivery-api
And 'Creating a custom API endpoint' here has nothing to do with the Content Delivery Api, so you can use this approach to create your own endpoint at any Url, once you have mapped your custom route to an Api Controller, inside that controller you can inject IPublishedContentQuery to make requests to the Umbraco published cache and build your custom models to return on the API.
Here is an example of injecting IPublishedContentQuery into a controller:
https://docs.umbraco.com/umbraco-cms/implementation/services#accessing-core-services-and-helpers-in-a-controller
So you probably need to decide if you want to have a specific Url or happy to use the Content Deliver Api Url format to pull back your content from Umbraco, and this will decide which approach you go for.
regards
Marc
is working on a reply...