Using Content Delivery API from backoffice

I wonder if anyone know an easy way to fetch data from the Content Delivery API from the backoffice, but not exposing the API secret to the backoffice at the same time.

Is building a custom backoffice endpoint that “forwards” the request the way to go, or is there something more obvious I’m missing?

Hi Karl,

Could I ask you to explain a little bit about what you are trying to achieve, please?

The Backoffice has its own API - The Management API - where you can fetch the same data, and you are already authenticated against that when logged in.
Alternatively, if you are already at a point writing your own API controller, you might as well have that fetch the data you need directly.

Sure thing - we utilize block previews.

We use Umbraco as headless, and we use React components in frontend. These are tailored to expect data coming in from the CDAPI (content delivery API).

We can use the same exact components in the backoffice block previews to give the editors a better experience. Of course then we would need to feed the components with the exact same laid out data as the CDAPI.

Instead of fetching things from the management API and spending a lot of time restructuring that data, we can get the actual CDAPI response and have things already “proofed” for this purpose.

Right, that tracks. In that case, the simplest solution is probably to create an API controller that fetches the data and uses IApiContentBuilder.Build(IPublishedContent content) to shape it into the Delivery API format. You should be able to inject it into your controller on the backend.

You can draw inspiration from the Management API and how it fetches documents from the database, so you can preview your unpublished blocks, too:

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.