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.
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.
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
هل يعاني أي شخص آخر من هذه المشكلة في الوقت الحالي؟ لقد حاولت لمدة يومين استخدام واجهة برمجة التطبيقات (API)، لكنني أحصل على أخطاء مماثلة في كل مرة. لست متأكدًا مما إذا كنت أفتقد خطوة ما أو إذا كان هناك تغيير ما.
لقد أنشأت مفتاح واجهة برمجة تطبيقات (API) جديدًا لمستخدم system. كما جربت إنشاء مفتاح واجهة برمجة تطبيقات (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"})
بالنسبة للخطأ الذي تواجهه مع كود Ruby الخام، فإن المشكلة تكمن في أن Api-Key و Api-Username يجب تعيينهما في رؤوس الطلب (request headers). كما يجب أن تستخدم أسماء الحقول في الـ API شرطات (-) بدلاً من الشرطات السفلية (_). راجع قسم المصادقة في أعلى https://docs.discourse.org/ للحصول على تفاصيل حول كيفية مصادقة الطلب.
لست متأكدًا مما قد يسبب الخطأ عند إجراء المكالمة باستخدام مكتبة Discourse API. السبب الأكثر احتمالًا للمشكلة هو أنك لا تستخدم بيانات اعتماد API صحيحة. تأكد من استخدام مفتاح API تكون فيه مستوى المستخدم مضبوطًا على “جميع المستخدمين”: