I need to build Umbraco Web API that will return JSON containing values of created document types, but I can't find any clear explanation on how to do so. I'm relatively new to APIs and I don't know if I need to provide anything else (if I do, please say so and I will). Thanks in advance!
You basically write a regular/standard .Net Web Api but inherit from UmbracoApiController instead of ApiController and the routing/url to the Api will be ~/Umbraco/Api/[YourControllerName].
Thank you for answering. Problem was that I was using VS Code. When I switched to VS everything went smoothly, but now I don't know how to get Document Types for CRUD methods. If you know how to do that, please help me.
What I haven't found is how you get the properties of the document type as JSON. I can easily create an API end point in Umbraco that returns a static string. Other than looking at some of Matt's code, there appears to be no documentation beyond the creation of a simple end point.
With Umbraco Headless not out yet, needing to wait until the x.1 version is out and stable, and the downside of it not working on prem, we need better documentation to create our own headless that can compete with the other open source solutions.
The only part that I know of that is different is the routing, otherwise I write my .Net Web Apis using Umbraco the same I would when not using Umbraco.
Creating Web API that returns JSON
Hello
I need to build Umbraco Web API that will return JSON containing values of created document types, but I can't find any clear explanation on how to do so. I'm relatively new to APIs and I don't know if I need to provide anything else (if I do, please say so and I will). Thanks in advance!
You basically write a regular/standard .Net Web Api but inherit from UmbracoApiController instead of ApiController and the routing/url to the Api will be ~/Umbraco/Api/[YourControllerName].
See more info here: https://our.umbraco.com/documentation/reference/routing/webapi/
Regards, Magnus
Thank you for answering. Problem was that I was using VS Code. When I switched to VS everything went smoothly, but now I don't know how to get Document Types for CRUD methods. If you know how to do that, please help me.
Talking in general terms you would for reading Umbraco data use the Umbraco helper since it's cached. See https://our.umbraco.com/documentation/Reference/Querying/UmbracoHelper/. Typically:
For create, update, delete you would have to look at the different services available: https://our.umbraco.com/documentation/Reference/Management/Services/
Regards, Magnus
What I haven't found is how you get the properties of the document type as JSON. I can easily create an API end point in Umbraco that returns a static string. Other than looking at some of Matt's code, there appears to be no documentation beyond the creation of a simple end point.
With Umbraco Headless not out yet, needing to wait until the x.1 version is out and stable, and the downside of it not working on prem, we need better documentation to create our own headless that can compete with the other open source solutions.
My experience is that to return json from a Web Api using Umbraco is no different from a standard .Net Web Api, i.e.: https://stackoverflow.com/questions/9847564/how-do-i-get-asp-net-web-api-to-return-json-instead-of-xml-using-chrome
The only part that I know of that is different is the routing, otherwise I write my .Net Web Apis using Umbraco the same I would when not using Umbraco.
Regards, Magnus
You can serialize the content model.
is working on a reply...