Firstly, you must have Python installed on your OS. Search online for how to install Python on Windows, Mac, Linux, etc. Once Python is installed:
Go to
XenForo Admin >
Setup >
API Keys
Title: Enter whatever here, e.g. Test API
Key type: User key (enter the forum username you want to post as)
Allowed scopes: Check thread:write (Covers creating, updating and soft-deleting threads and posts.)
Click
Save.
"The API key "Test API" has been created or updated. The key to use with the API is as follows:"
Copy the API Key.
Use this API key for your Python script.
Python:
import requests
api_key = 'your_api_key'
api_url = 'https://your_xenforo_site.com/api/threads'
headers = {'XF-Api-Key': api_key}
data = {
'node_id': 1, # The ID of the forum where you want to create the thread
'title': 'Thread Title',
'message': 'This is the content of the first post in the thread.'
}
response = requests.post(api_url, headers=headers, data=data)
if response.status_code == 200:
print("Thread created successfully!")
else:
print("Failed to create thread.")
Replace
'your_api_key' and
'https://your_xenforo_site.com' with the appropriate API key and your XenForo site URL. Adjust the
node_id,
title, and
message parameters as needed.