Can't retrieve posts with API

I am trying to use the Discourse API to create a list of all posts (first posts only) with a specific tag. So far, I’ve only been able to get the latest posts, which retrieves around 40 posts, including comments. When I tried retrieving a specific post id, some of them have worked, but for some I got the response
{'errors': ['You are not permitted to view the requested resource.'],'error_type': 'invalid_access'}
even though the API key I’m using has admin access to all posts on our Discourse. Has anyone encountered this issue before?

Can you post your code snippet? (Without including the API key)
Do you see any pattern here in which work and which do not?

1 Like

Hi @RGJ, I noticed I’m able to retrieve individual posts if they have been in the list originally retrieved by posts.json. I used the code snippet below

url = "https://forum.algovera.ai/posts.json"

username = "algovera"

params = {'Api-Key': api_key, "Api-Username": username}

r = requests.get(url = url, params = params)

data = r.json()

Then I tried changing this call to https://forum.algovera.ai/posts/{id}.json", where the ID was taken from the URL of the particular post I was looking at.

The number in the URL is not the ID, that’s the post number, which is relative to the topic ID.
If you want to get the post ID you can retrieve it from the topic json as post_stream.posts[].id

So the posts in this topic have

topic ID post_number ID
255455 1 1241013
255455 2 1241026
255455 3 1241056

and your most recent post in this topic is https://meta.discourse.org/posts/1241056.json

1 Like

Oh right, thank you. That worked, so what would I need to call if I want to retrieve the latest topics and then the raw text for the first post in each topic? I saw the List Topics call in the docs but I’m not sure what the slug should be.