Militant API wiki

First API Call

Supporting pages, examples and technical details in a cleaner layout.

Guide to make your first call to the Militant API.

1. Check that the API works

curl https://your-instance.com/api/v1/

You should see the list of endpoints in JSON.

2. Authenticate

curl -X POST https://your-instance.com/api/v1/auth.php \
  -H "Content-Type: application/json" \
  -d '{
    "username": "your_username",
    "password": "your_password"
  }'

Response:

{
  "success": true,
  "token": "abc123def456...",
  "expires_at": "2026-03-04 12:00:00",
  "user_id": 1
}

Copy the token, you'll need it for all following calls.

3. Make an authenticated call

Get the news feed

curl https://your-instance.com/api/v1/posts.php \
  -H "Authorization: Bearer YOUR_TOKEN"

Create a post

curl -X POST https://your-instance.com/api/v1/posts.php \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "My first post via the API!"
  }'

Get your profile

curl https://your-instance.com/api/v1/users.php?username=your_username \
  -H "Authorization: Bearer YOUR_TOKEN"

4. Handle errors

Invalid token (401)

{
  "success": false,
  "error": "Invalid or expired token"
}

Solution: Login again to get a new token.

Rate limit exceeded (429)

{
  "success": false,
  "error": "Rate limit exceeded"
}

Solution: Wait 1 hour or reduce the number of requests.

Next steps