خطأ 403 أثناء استدعاءات API المتعددة

نستخدم الواجهات البرمجية التالية لتحديث المستخدمين وتعليقهم، لكننا نحصل على أخطاء 403. هل يمكنكم إخبارنا بالسبب وراء هذا الخطأ؟ علماً بأننا نستخدم مفتاح واجهة برمجة تطبيقات (API key) خاص بمسؤول النظام.

واجهة برمجة تطبيقات التعليق

{{base_url}}/admin/users/316/suspend?api_key={{api_key}}&api_username={{api_username}}

جسم الطلب

{
    "suspend_until": "3020-04-17",
    "reason": "inactive"
}

الاستجابة - 403 ممنوع

تحديث البريد الإلكتروني

{{base_url}}/users/{username}/preferences/email?api_key={{api_key}}&api_username={{api_username}}

جسم الطلب

{
    "email": "discourse1@example.com"
}

الاستجابة - 403 ممنوع

You need to put the API key in the header, not the url.

إعجابَين (2)

Even tried it as well.Getting same 403 Forbidden with BODY-> [“BAD CSRF”]

The API credentials need to be in the request header. You also need to use a dash instead of an underscore for the header field names:

  • api_key needs to be changed to api-key (or Api-Key)
  • api_username needs to be changed to api-username (or Api-Username)

The rule is that the header field names are not case sensitive, but you need to use dashes, not underscores. (I learned this the hard way.) Have a look at the example at the top of Discourse API Documentation to see a properly formatted API request.

4 إعجابات