Assign topics or messages when created via API

Hi,

I’m ussing the Discourse Assign plugin and managed to do it, here’s the python code:

import requests

# You can get this from by reverse engineering the assign request and checking the parameters and values on the console as someone mentioned before :) 

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

 payload = {
    'username': 'USERNAME', #The username of the person you want to assign the topic to
    '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}")

I hope it helps ^^

1 Like