تعيين الموضوعات أو الرسائل عند إنشائها عبر API

I’d like to be able to create messages that are assigned to specific users. Is this something that is possible already and I am missing something, or that you would consider adding?

I am not seeing reference to the assign plugin in the API docs. Seems to me an e.g. assigned_to=usernname should be an option.

https://docs.discourse.org/#tag/Posts%2Fpaths%2F~1posts.json%2Fpost

The background to this is that I am using discourse as a ticket system, using @angus’s Tickets Plugin 🎟. The easiest way for me to allow members to create tickets is to create a gravity form in wordpress that creates the message in discourse. I know this can work and I have the rest of it lined up, just not the ability to assign tickets to specific users upon creation.

To assign a topic you issue an API request after creating the topic. For the request format, please read How to reverse engineer the Discourse API

4 إعجابات

أحتاج إلى إنشاء مواضيع عبر واجهة برمجة التطبيقات (API) باستخدام مستخدمين مرحليين (لا يحتاج المرسل إلى حساب في Discourse)، لذا يجب أن أقوم بذلك عبر نقطة النهاية /admin/email/handle_mail. لكن هذه النقطة لا تُرجع معرف الموضوع (Topic ID) ويبدو أنها تعمل بشكل دفعات.

ما أفضل طريقة لتعيين ذلك الموضوع؟

الأفضل بالنسبة لي لو كانت نقطة النهاية /admin/email/handle_mail تقبل حقل “assign” (تعيين).

لماذا تعكس نقطة نهاية handle_email لإنشاء المواضيع؟

هل لا يمكنك استخدام واجهة برمجة التطبيقات القياسية لإنشاء مواضيع مع مستخدم في مرحلة التجهيز؟

إعجاب واحد (1)

لا أرى خيارًا لإنشاء مستخدم مرحلي عبر واجهة برمجة التطبيقات: Discourse API Docs

كما يُوصى هنا باستخدام نقطة نهاية handle_email: Creating a staged user with an API call - #2 by blake

لن نفعل ذلك. فهي مخصصة فقط لمعالجة البريد الوارد.

هذا لا يعمل في الواقع، ستحصل على خطأ 403.

لكن هل يمكنك استدعاء نقطة النهاية هذه للحصول على أحدث موضوع من قبل المستخدم المرحلي؟

http://localhost:3000/topics/created-by/staged-username.json

ثم تقوم بتعيينه؟

إعجابَين (2)

هureka!

من الممكن استخدام “تعيين تعبير نمطي آخر” ثم ذكر ذلك في نص /admin/email/handle_mail.

إعجاب واحد (1)

مرحباً،

أنا أستخدم إضافة Discourse Assign وتمكنت من فعل ذلك، إليك كود بايثون:

import requests

# يمكنك الحصول على هذا عن طريق هندسة عكسية لطلب التعيين والتحقق من المعلمات والقيم في وحدة التحكم كما ذكر أحدهم من قبل :) 

base_url = 'YOUR_URL'
endpoint = '/assign/assign'

payload = {
    'username': 'USERNAME', # اسم المستخدم للشخص الذي تريد تعيين الموضوع له
    'group_name': '',
    'target_id': TOPIC_NUMBER,
    'target_type': 'Topic'
}

headers = {
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Referer': 'URL_OF_THE_TOPIC', 
    'Accept': '*/*',
    'Api-Key': 'YOUR_API_KEY',
    'Api-Username': 'YOUR_USERNAME'
}

response = requests.put(f"{base_url}{endpoint}", data=payload, headers=headers)

if response.status_code == 200:
    print("Assignment successful!")
else:
    print(f"Assignment failed with status code {response.status_code}: {response.text}")

آمل أن يكون هذا مفيدًا ^^

إعجاب واحد (1)