Sample Javascript Content API Client Library Call Not Working

Hello everyone,

I attempted to make a content api call from the browser using the content api docs.

the call to http://localhost:2368’ and https://demo.ghost.io both resulted in the same error displayed below.

here is the snippet:

{{#contentFor "scripts"}}
<script src="https://unpkg.com/@tryghost/content-api@1.0.0/umd/content-api.min.js"></script>
<script>
        const api = new GhostContentAPI({
  url: 'https://demo.ghost.io',
  key: '22444f78447824223cefc48062',
  version: 'v2'
});

// fetch 5 posts, including related tags and authors
api.posts
    .browse({limit: 5, include: 'tags,authors'})
    .then((posts) => {
        posts.forEach((post) => {
            console.log(post.title);
        });
    })
    .catch((err) => {
        console.error(err);
    });
</script>
{{/contentFor}}

Any feedback is appreciated.

Thank you

Could you update to the latest version of the content-api and try then? :slight_smile: The latest is 1.2.4

1 Like

That did work. Thank you @egg.
Also noticed a typo in the header of the docs page link above.
libarary should be library I think. not sure where to report that.

Awesome - good to hear! :tada:

There should be an edit button at the top of the page, or on almost all of our docs pages you can add /edit to the url and submit a PR on github - would be really appreciated :relaxed:

1 Like

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