Manipulate JSON site data
# help-with-umbraco
t
Hi I'm not sure if this is right way to do this. I activated delivery API and can get data from my nodes I want showing in a browser (or postman). I need this data for a third party company to query from. So I have some questions, How can I call the endpoints inside my C# project? It's it the normal httpclient or does the delivery API have methods I can call? I don't need most of the fields that are returned back, how could I pass the data into my own object with properties I need? Thank you
m
do you need the whole content delivery api, or can you just create your own api endpoints with you controlling the shape of the data you expose? https://docs.umbraco.com/umbraco-cms/reference/routing/umbraco-api-controllers
re consuming the data from another c# project, I'd say use something like [restSharp](https://restsharp.dev/) or [flurl](https://flurl.dev/)? (which I believe are just abstractions over httpClient but do the CRUD for you)
t
I could give that a try. I don't need everything from the delivery API but just certain certain areas. I liked the ease of delivery API being locked down so no public access. Could I still do that with the Umbraco link you posted above? After having a quick read, the link doesn't allow me to retrieve data from Umbraco, so this would mean I have to find a way to get the data, is that correct?
m
you just fetch the data out of umbraco as required..
Copy code
csharp
using Code.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Web.Common;
using Umbraco.Extensions;

namespace Code.Controllers
{
    [Route("api/plotinfo")]
    public class PlotInfoController : Controller
    {
        private readonly ILogger _logger;
        private readonly UmbracoHelper _umbracoHelper;

        public PlotInfoController(ILogger<PlotInfoController> logger, UmbracoHelper umbracoHelper)
        {
            _logger = logger;
            _umbracoHelper = umbracoHelper;
        }

        [HttpGet]
        [Route("getplotbox/{development:guid}/{plotname}")]
        public IActionResult? GetPlotBox(string plotname, Guid development)
        {
            if (_umbracoHelper.Content(development)?.Descendants<PlotPage>().FirstOrDefault(x => x.UrlSegment == plotname) is PlotPage node)
            {
                return new JsonResult(new MyNode() { Key = node.Key, Name = node.Name});
            }
            else
            {
                _logger.LogWarning("Error - Could not find plot : {_Plotname} {_Development}", plotname, development);
                //return BadRequest($"Error - Could not find plot : {plotname} {development}");
                return new EmptyResult();
            }
        }

    }

    public class MyNode
    {
        public Guid Key { get; set; }
        public string Name { get; set; } = string.Empty;

    }
}
securing it for 3rd party access.. I think I've seen something elsewhere on discord for a jwt bearer token approach.. but no not as easy as the contentdeliveryapi.. it's mean to be internal auth like the docs with the decorators..
[UmbracoMemberAuthorize("", "VIP", "")]
wonder if you could reuse the contentdelivery.. though only a header check by the looks of it.. https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Cms.Api.Delivery/Services/ApiAccessService.cs#L31-L32
2 Views