Cookie Consent by Free Privacy Policy Generator

Xenforo API - Python: Create new Thread

If you are using the Xenforo community forum script and starting to learn the Xenforo Rest API. This post is to show you how you can programmatically create a new thread with this simple Python script.

Code:
# Xenforo Forum - Programmatic Create new Thread
import requests

# Send API header request
headers = {
          'Content-type' : 'application/x-www-form-urlencoded',
           'XF-Api-User': '1',
          'XF-Api-Key' : 'api-key-goes-here'
          }

# Connect with the API Endpoint
url = 'https://example.com/api/threads/

# Post new thread title & message
data = {
    'node_id': 23, # node ID is the forum ID
    'title': 'This is the thread title',
    'message': 'This is the thread message body contents This is the thread message body contents.'
}

r = requests.post(url, headers=headers, data=data)

# Print the response (200 is success)
print(r)
 
Back
Top