Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Biagio Paruolo 1619 posts 1911 karma points c-trib
    Feb 25, 2024 @ 10:18
    Biagio Paruolo
    0

    DeliveryApi: Simple code to return publishContent as Delivery Api Content JSON format

    Hi,

    I wish to write a simple code that I searched and tested to return the JSON like Delivery API and not overloaded like to return direct Content Type. Do you have some suggestions? How to query the data with DeliveryApi SDK?

    using Umbraco.Cms.Core.DeliveryApi;
    
    .... inject interface: 
            private readonly IApiContentQueryService _apiContentQueryService;
            private readonly IApiContentRouteBuilder _apiContentRouteBuilder;
            private readonly IApiContentBuilder _apiContentBuilder;
    
     public DemoController(
          .... IApiContentRouteBuilder apiContentRouteBuilder,
                IApiContentBuilder apiContentBuilder
                )
            {
             ....
                _apiContentQueryService = apiContentQueryService;
                _apiContentRouteBuilder = apiContentRouteBuilder;
                _apiContentBuilder = apiContentBuilder;
    
            }
    
     public async Task<IActionResult> Content(int id)
            {
              var content =  _contentService.GetById(id);
    
    
                if (content == null)
                    return NotFound();
    
    
               var flag = await IsAuthorizedToSeeData(id, email);
    
                if (flag)
                {
                      var iii = _apiContentRouteBuilder.Build(_publishedContentQuery.Content(id));
                    var cc = _apiContentBuilder.Build(_publishedContentQuery.Content(id));
    
                    return Ok(cc);
                }
                else
                    return Unauthorized();
            }
    
Please Sign in or register to post replies

Write your reply to:

Draft