Assign topics or messages when created via 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.

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 Reverse engineer the Discourse API

4개의 좋아요

I need to create topics by API as staged users (sender does not need to have account in Discourse), so I have to do it by the /admin/email/handle_mail endpoint. But it does not return topic ID and seems to work in a batch.

What is the best way how to assign that topic?

The best for me would be if /admin/email/handle_mail endpoint could accept an assign field.

Why are you reversing the handle_email endpoint for creating topics?

You can’t use the standard create topic API with a staged user?

1개의 좋아요

I do not see option to create staged user by API: Discourse API Docs

Also here is is recommanded to use handle_email endpoint: Creating a staged user with an API call - #2 by blake

This we won’t do. It is only meant to handle incoming email.

This doesn’t work actually, you will get a 403 error.

Could you call this endpoint though to get the latest topic by the staged user?

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

And then assign it?

2개의 좋아요

Heureka!

It is possible to use "assign other regex“ and then mention in text of /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개의 좋아요