API Error: You are not permitted to view the requested resource

AI-generated summary

A user, erik_chan, is experiencing an error (“You are not permitted to view the requested resource”) when trying to access a private category using the Ruby API. They have tried authenticating with different users, including the system user, but still encounter the issue.

erik_chan mentions that they expect users with admin rights to be able to access private categories via the API.

Other users, such as chenny408 and j127, report similar issues.

simon suggests that the problem might be due to incorrect API credentials or authentication method. They point out that the Api-Key and Api-Username need to be set in the request headers, and the API field names should use dashes (-) instead of underscores (_).

j127 confirms that setting the Api-Key and Api-Username in the request headers resolves the issue. They also mention that the Discourse API documentation might need to be updated to reflect this.

simon updates the relevant documentation and deletes outdated posts.

I am receiving the following error:

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

when I make the ruby API call ‘category_latest_topics’

response = client.category_latest_topics("<some_category>") 

This is due to the category permissions (the category is not public). I tried to authenticate by using

client.api_username = "system"  

and making sure “system” is a member of the group that has permissions to the category but still no luck! Any suggestions or workarounds?

No response so far. Am I posting this in the right forum?

Try using a different user, other than System. Issue an API key for a different user. You will need to experiment.

No luck. Tried issuing API key for different users who have permission to the category but still no access.

Would be awesome if anyone else has suggestions for this?

How can I access a private category via the API. This should not be an issue for users/system with admin rights to the forum.

I’m having the same issue, can someone take a look into this?

Have you attempted to generate a key from your account? You are the admin who created the forum, yes? You say “users/system” so I am wondering if you tried your own account.

Yes i am the admin of my forum.

I have tried both my username and system with no luck. I can’t call client.category_latest_topics(<category_name>) even though the user has permissions to the category

I feel some other variable exists and is causing this error; one that cannot be seen due to the limited info provided.

Be sure to check these topics in regards to setting up and using the Discourse API, if you have not yet done so.

Appreciate your help. If you read my original post i am using the ruby api. I have also looked through the documentation before posting this topic.

If you could show me what variable i am missing or where to exactly to find out more i would appreciate it.

지금 이 문제를 겪고 있는 사람이 더 있나요? 2일 동안 API를 사용하려고 시도하고 있지만, 매번 비슷한 오류가 발생합니다. 제가 단계를 놓치고 있는지, 아니면 무언가 변경되었는지 확실하지 않습니다.

system 사용자를 위한 새로운 API 키를 생성했습니다. 또한 모든 사용자를 위한 API 키를 생성한 후 관리자 계정을 사용해 보기도 했습니다.

discourse_api Ruby 제보를 사용했습니다:

DiscourseApi::UnauthenticatedError ({"errors"=>["You are not permitted to view the requested resource. The API username or key is invalid."], "error_type"=>"invalid_access"})

다른 게시물에서 가져온 이 코드로도 시도해 보았습니다:

require 'net/http'
require 'uri'

INSTANCE_URL = 'https://forum.example.com/admin/users/list/all.json?email=user@example.com'
API_USERNAME = 'system'
API_KEY = 'a_new_api_key_here'

def send_request
  url = URI.parse(INSTANCE_URL)
  request = Net::HTTP::Get.new(url.path)
  request.set_form_data({'api_username' => API_USERNAME, 'api_key' => API_KEY})
  http = Net::HTTP.new(url.host, url.port)
  response = http.request(request)

  if response.code == '200'
    puts "Success!"
  else
    puts "Error"
    puts response.code
  end
end

send_request # 400

api_username과 api_key를 폼 데이터에 포함시켜 원시 요청으로 API를 사용하려고 시도해 보았지만, 404 오류가 발생합니다.

이메일 주소 목록을 읽어들이고, 사용자 이름을 가져온 다음, 모든 Discourse 이메일에서 구독을 취소하는 스크립트를 작성하려고 하고 있습니다.

원시 Ruby 코드에서 발생하는 오류에 대해 말씀드리자면, 문제는 Api-Key와 Api-Username을 요청 헤더에 설정해야 한다는 점입니다. 또한 API 필드 이름은 밑줄(_)이 아닌 대시(-)를 사용해야 합니다. 요청 인증 방법에 대한 자세한 내용은 https://docs.discourse.org/ 상단의 Authentication 섹션을 참고해 주세요.

Discourse API gem을 사용하여 호출할 때 발생하는 오류의 원인은 정확히 알 수 없습니다. 가장 가능성 높은 원인은 올바른 API 자격 증명을 사용하지 않고 있기 때문일 것입니다. User Level이 All Users로 설정된 API 키를 사용하고 있는지 확인해 주세요:

위 방법으로 문제가 해결되지 않는다면, 시도 중인 요청을 여기에 게시해 주시면 확인해 드리겠습니다.

감사합니다, 잘 작동합니다. 여기의 첫 몇몇 게시글을 참고했는데, 업데이트가 필요할 수 있습니다:

알려주셔서 감사합니다. OP를 업데이트하고 해당 토픽에서 가장 오래된 게시글을 삭제했습니다.