创建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 端点。但该端点不返回话题 ID,且似乎是以批量方式工作的。

分配该话题的最佳方法是什么?

对我而言,最理想的情况是 /admin/email/handle_mail 端点能够接受一个 assign 字段。

你为什么在创建主题时反转 handle_email 端点?

你无法对暂存用户使用标准的创建主题 API 吗?

1 个赞

我在 API 中未找到通过 API 创建预注册用户的选项:Discourse API Docs

此外,这里推荐使用 handle_email 端点:Creating a staged user with an API call - #2 by blake

这个我们不会做。该端点仅用于处理 incoming 邮件。

这实际上无法工作,您会收到 403 错误。

不过,您可以调用以下端点来获取暂存用户创建的最新话题吗?

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

然后再进行分配?

2 个赞

太棒了!

可以在 /admin/email/handle_mail 的文本中提及“分配其他正则表达式”功能。

1 个赞

您好,

我正在使用 Discourse Assign 插件,并且已经成功实现了,这是 Python 代码:

import requests

# 您可以从反向工程 assign 请求并检查控制台中的参数和值来获取此信息,正如之前有人提到的 :) 

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("分配成功!")
else:
    print(f"分配失败,状态码 {response.status_code}: {response.text}")

希望它有帮助 ^^

1 个赞