JavaScript client 422 Unprocessable Entity error

Hi all,

I’ve encountered an error fetching custom post with JavaScript API client. My function to browse all posts works well, but with api.posts.read({slug: 'welcome'}); appears to be an issue.
Console givers: GET 422 (Unprocessable Entity)

This is how the call looks like:

export async function fetchArticle(slug) {

        const promise = api.posts.read(
            {
                slug: slug
            },
            {
                formats: ['html', 'plaintext']
            }
        )
        return await promise
};

And loading the page with slug “welcome” this is what I get in the console GET / XHR error:
http://localhost:2368/ghost/api/v3/content/posts/?key=b78272c3dcdc852b126455c4b7&fields=id%2C%20title%2Ccustom_excerpt%2Cfeatured%2Cfeature_image%2Cslug%2Curl%2Cpublished_at&include=tags&page=welcome

I tried to use id instead of slug, but the key each time goes to the page=

Ghost v. 4.2.1 (dev/local)
Node v. 14.16.1

The URL that you’ve posted doesn’t match up with the shared code. Have you reduced the code provided to remove the fields and include param?

Nope, that’s exactly what I’m using to get the post data. The URL with query really looks weird.

Omg, sorry for bringing it up. I’ve messed with the external module. Just moved this function to a separate file and the call worked! It appears to be the call to fetch all posts above with export default affected the import.

Lack of experience with JS. Thanks for the hint @Kevin !