Integrate third Party Rest API

Hi,

I am currently evaluating ghost and have a simple question to which I haven’t found any information.
How can I embedded a third Party REST API on a ghost page.

Thanks

You need to provide more context to what you’re trying to do - if you’re trying to fetch data from a third party API and add it to a page, from a Ghost perspective, you need to use code injection

Thanks for your reply. All I want is to call a products Rest API which of course returns json and show those products in the theme layout on a ghost page, in the footer or the sidebar. I would also need the context, I need to know on which page I am on.
Code injection does not look perfect for that since I can call the API but I don’t see how to display it.

I posted a similar question, but haven’t found an answer yet.

I have a subscription with an API that provides stock data, and I’d like to pull those APIs into the body text of a blog post. So I may have a sentence along the lines of “Apple achieve a return-on-equity of 29%” in my blog post, where the 29% I’d like to pull through as an API so the blog post updates itself and stays relevant.

Unsure how to do that.

The typical approach is to do it with client-side JS. There’s nothing particularly Ghost-specific about doing it that way - you have some JS that fetches data from an API, generates some HTML, then injects it where you want on the page. From Ghost’s side of things you can use a HTML card or code injection to get the JS onto your site, and you can put placeholder elements into your template files or in HTML cards to give you somewhere to inject the generated HTML.

Alternatively you can have a small service that’s separate to Ghost that fetches your API periodically and modifies posts via Ghost’s Admin API. That’s a more complex setup and would require more maintenance.

3 Likes

Thanks Kevin! Sound good I give it a try

As mentioned javascript code injection or code in theme gets the job done. Just to add where I have a requirement like this will use JQuery with Ghost to organise content. Note that when you start down this track you may need to consider caching API request. Let me know if you need help, or have any questions with strategy for this.