Asignar temas o mensajes al crearse mediante 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 Me gusta

Necesito crear temas mediante la API como usuarios en etapa (el remitente no necesita tener una cuenta en Discourse), por lo que debo hacerlo a través del endpoint /admin/email/handle_mail. Sin embargo, este no devuelve el ID del tema y parece funcionar en lotes.

¿Cuál es la mejor manera de asignar ese tema?

Lo ideal para mí sería que el endpoint /admin/email/handle_mail pudiera aceptar un campo de asignación.

¿Por qué estás invirtiendo el endpoint handle_email para crear temas?

¿No se puede usar la API estándar de creación de temas con un usuario en etapa de prueba?

1 me gusta

No veo la opción para crear un usuario en etapa mediante la API: Discourse API Docs

Además, aquí se recomienda usar el endpoint handle_email: Creating a staged user with an API call - #2 by blake

Esto no lo haremos. Solo está diseñado para gestionar correos entrantes.

En realidad, esto no funciona; obtendrás un error 403.

¿Podrías llamar a este endpoint para obtener el último tema creado por el usuario en etapa?

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

¿Y luego asignarlo?

2 Me gusta

¡Eureka!

Es posible usar “asignar otra expresión regular” y luego mencionarlo en el texto de /admin/email/handle_mail.

1 me gusta

Hola,

Estoy usando el plugin Discourse Assign y logré hacerlo, aquí está el código de Python:

import requests

# Puedes obtener esto invirtiendo la ingeniería de la solicitud de asignación y verificando los parámetros y valores en la consola como alguien mencionó antes :) 

base_url = 'TU_URL'
endpoint = '/assign/assign'

payload = {
   'username': 'NOMBRE_DE_USUARIO', # El nombre de usuario de la persona a la que quieres asignar el tema
   'group_name': '',
   'target_id': NUMERO_DEL_TEMA,
   'target_type': 'Topic'
}

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

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

if response.status_code == 200:
   print("¡Asignación exitosa!")
else:
   print(f"La asignación falló con el código de estado {response.status_code}: {response.text}")

Espero que ayude ^^

1 me gusta