Welke scope is nodig om toegang te krijgen tot {{localhost}}/posts.json?

AI-generated summary

The discussion revolves around the necessary API scope for accessing {{localhost}}/posts.json. Hugo_Tadashi reports that an admin API key with read, write, and read lists scopes fails to access the endpoint, while a global key works. simon explains that the read scope only applies to /t routes, not /posts.json, and suggests that adding access to /posts.json to the read scope would be a logical improvement. Hugo_Tadashi seeks a workaround for read-only access without using a global key, and simon notes that unauthenticated access might work for public posts, but a global key is required for private or protected content. riking supports the idea of adding this functionality, calling it a #pr-welcome.

Hi,

I generated an admin-issued API key with write, read and read lists scopes. However, when I try to consume the key (adding the key on the header Api-Key) to access the {{localhost}}/posts.json endpoint, I get the following error:

    "errors": [
        "You are not permitted to view the requested resource. The API username or key is invalid."
    ],
    "error_type": "invalid_access"
}

On the other hand, generating a global key give me access to the endpoint. What is the correct (minimum) scope for reading {{localhost}}/posts.json?

I haven’t tested this yet, but I think that what you are seeing is the expected behaviour. You can click on the anchor button that is displayed next to each of the API key scopes to see which paths the scope allows you to access. You’ll see that the read scope is only applied to routes beginning with /t. The read lists scope gives you access to the Discourse topic lists. There isn’t a scope that specifically allows you to access /posts.json, so it looks like you’ll have to use a global key for that.

I’m wondering if it would make sense to add /posts.json to the read scope.

Hi Simon! Thanks for the reply and the explanation. For my use case I’ll need reading the posts from /posts.json, but at the same time I would like to be as less intrusive as possible and only ask for read-only access. Is there any workaround?

If you are only querying for public posts, you might be able to make an unauthenticated API request to /posts.json. If your site is private, or the posts are in protected categories, I think the only way you can currently retrieve the posts is with a global API key.

pr-welcome for either a new scope or adding this to read, I think.