Assegna argomenti o messaggi quando creati tramite 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 Mi Piace

Devo creare argomenti tramite API come utenti in staging (il mittente non deve avere un account su Discourse), quindi devo farlo tramite l’endpoint /admin/email/handle_mail. Tuttavia, questo non restituisce l’ID dell’argomento e sembra funzionare in batch.

Qual è il modo migliore per assegnare quell’argomento?

Per me sarebbe ideale se l’endpoint /admin/email/handle_mail potesse accettare un campo assign.

Perché stai invertendo l’endpoint handle_email per la creazione di argomenti?

Non puoi utilizzare l’API standard per creare argomenti con un utente in fase di staging?

1 Mi Piace

Non vedo l’opzione per creare un utente in staging tramite API: Discourse API Docs

Inoltre, qui si raccomanda di utilizzare l’endpoint handle_email: Creating a staged user with an API call - #2 by blake

Questo non lo faremo. È previsto solo per gestire le email in arrivo.

In realtà questo non funziona, riceverai un errore 403.

Potresti però chiamare questo endpoint per ottenere l’ultimo topic creato dall’utente in staging?

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

E assegnarlo poi?

2 Mi Piace

Eureka!

È possibile utilizzare “assign other regex” e poi menzionarlo nel testo di /admin/email/handle_mail.

1 Mi Piace

Ciao,

Sto usando il plugin Discourse Assign e sono riuscito a farlo, ecco il codice Python:

import requests

# Puoi ottenerlo tramite reverse engineering della richiesta di assegnazione e controllando i parametri e i valori sulla console, come menzionato in precedenza :) 

base_url = 'IL_TUO_URL'
endpoint = '/assign/assign'

 payload = {
    'username': 'NOMEUTENTE', # Il nome utente della persona a cui vuoi assegnare l'argomento
    'group_name': '',
    'target_id': NUMERO_ARGOMENTO,
    'target_type': 'Topic'
}

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

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

if response.status_code == 200:
    print("Assegnazione riuscita!")
else:
    print(f"Assegnazione fallita con codice di stato {response.status_code}: {response.text}")

Spero sia d’aiuto ^^

1 Mi Piace