Discourse API - Unable to query certain endpoints

AI-generated summary

Unable to Query Certain Endpoints with Discourse API

Ryan_NR is experiencing issues with the Discourse API, receiving errors such as “You need to be logged in to do that” and “You are not permitted to view the requested resource.” Despite using an admin user account and confirming the API key and username, the problem persists.

codinghorror suggests that the issue may be related to incorrect credential sending, while blake recommends passing API credentials in the request header instead of query parameters.

Ryan_NR is using a Postman collection downloaded from the Discourse API documentation, but blake notes that some of these collections may be outdated.

After trying blake’s suggestion, Ryan_NR still encounters the same error. blake shares a working curl command for the group members API request, suggesting that Ryan_NR compare it with their Postman setup.

Hi folks - I’m an admin user of our Discourse instance - but I’m unable to query certain endpoints.

Sometimes I get this:

Other times I am prompted with You need to be logged in to do that

I have confirmed the API key I’m using is attached to my Admin user, and that the API_Username is my own username - do you have any advice on this?

My guess is the call is not sending the credentials correctly?

You could try passing the api credentials in the header of the request instead of the query params. There should be an example in the api documentation topic.

Could be - I’m not sure - The set up I have is just the Postman collection downloaded from here:

I just changed out the API Key, Username, and Base URL.

Is this collection no longer valid?

Thanks @blake I’ll give it a try

Yea some of them are probably outdated.

@blake - Passing creds as a request header is returning the same:

{
    "errors": [
        "You are not permitted to view the requested resource."
    ],
    "error_type": "invalid_access"
}

I was able to get the group members api request to work on meta with this curl command:

curl -i -sS -X GET "https://meta.discourse.org/groups/my-private-group/members.json" \
-H "Content-Type: multipart/form-data;" \
-H "Api-Key: key" \
-H "Api-Username: username"

Maybe you can use the copy as curl command in Postman and compare.