Cookie Consent by Free Privacy Policy Generator

Xenforo API - Bulk Post Threads (Python)

This is for fans of programmatic SEO. Below is a Python script to bulk upload new threads to the Xenforo forum script. The script works by reading a CSV file that is stored in a dataframe and then posted to Xenforo using the tqdm library.

Xenforo has an excellent Rest API with endpoints that are perfect for programmatic SEO.

Code:
# Import modules
import pandas as pd
import requests
import csv
import json
import base64
from tqdm.notebook import tqdm

# send the API via header requests
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/'

# Paste your uploaded csv file name here - example: sample-data.csv or paste remote weblink
df = pd.read_csv("https://airwolf.dev/xen/xenforo-test2.csv")
df

# Xenforo_Post_Insert Function to build the JSON array

# (add or remove post schemas to suit your requirements)
def xenforo_post_insert(title, content):
    data = {'node_id': '23',
            'title': title,
            'message': content
            }
    xenforo_post_insert = requests.post(url, headers=headers, data=data)

# Executes the script and runs the TQDM progress bar
for index, row in tqdm(df.iterrows()):
# Add or remove Xenforo schemas varibles below
    xenforo_post_insert(row["title"], row["content"])
 
Back
Top