The XenForo 2 API provides powerful tools for integrating and extending the functionality of your forum. Using the API, you can retrieve data, manage users, posts, and perform many other tasks from outside of XenForo. This guide will help you get familiar with how to use the XenForo 2 API to maximize the platform’s potential.

XenForo 2 API User Guide
The XenForo 2 API allows for extending and integrating the forum with external applications.
Table of Contents

    Enable API In XenForo 2

    Before using the API, you need to enable it in XenForo 2. Log in to the admin dashboard, select Optionsand go to the item API. Here, enable the option Enable API.

    Once activated, you will see the API’s base URL, which is usually in the form of “//yourdomain.com/api/”. This URL is the starting point for all API requests.

    Create API Key

    The API Key is required to authenticate requests to XenForo’s API. To generate an API Key, go to API Keys in the admin dashboard. Click Create API Keyenter a name and select the access rights that suit your needs.

    Each API Key can be configured to have different access rights, from reading, writing, to managing forum resources. Save the API Key carefully as it will be used in all API requests.

    Using the API With HTTP Requests

    The XenForo 2 API uses HTTP requests like GET, POST, PUT, DELETE to interact with data. You can send these requests using tools like Postman, or through programming code in languages ​​like Python, PHP, or JavaScript.

    For example, to get a list of posts, you can send a GET request to “//yourdomain.com/api/threads” with the API Key in the request header:

    See also  How to Create Custom Modules for XenForo 2

    GET /api/threads
    Authorization: Bearer YOUR_API_KEY

    User Data Access

    The XenForo API allows you to retrieve user data, including profile information, status, and permissions. Use a GET request to “//yourdomain.com/api/users” to get a list of users, or “//yourdomain.com/api/users/{user_id}” to get details for a specific user.

    These requests are useful when you need to synchronize user data between XenForo and external applications.

    Managing Posts and Topics

    You can use the API to create, edit, or delete posts and topics in the forum. Use a POST request to create a new post, with the data sent in the body of the request. For example:

    POST /api/threads
    Content-Type: application/json
    Authorization: Bearer YOUR_API_KEY
    
    {
      "node_id": 1,
      "title": "Tiêu đề bài viết mới",
      "message": "Nội dung bài viết mới."
    }

    This helps you automate content posting or integrate your forum with other content management systems.

    Access Control

    The XenForo API allows you to control access to different resources. You can set individual permissions for each API Key, ensuring that only authorized applications and users can perform specific actions.

    Correct permission configuration helps protect your data from unauthorized access and ensures that only valid actions are performed.

    Advanced

    The XenForo 2 API is a powerful tool that allows you to integrate and extend the functionality of your forum. Using the API, you can access and manage data flexibly, and integrate your forum with external applications and services. Hopefully, this guide will help you get started using the XenForo 2 API effectively.

    Good luck in developing and optimizing your XenForo 2 forum!

    Leave a Reply

    Your email address will not be published. Required fields are marked *