Managing Plugins With Rocket.net API

Rocket.net WordPress Plugin Management API Guide

🚀 Rocket.net WordPress Plugin Management

Complete API Guide for Managing WordPress Plugins at Scale

⚠️ CRITICAL: Always use the /v1/sites/{id}/plugins endpoint for WordPress plugin management. Never use file system APIs or WP-CLI for checking plugin status.

Why This Guide Exists

Managing WordPress plugins across hundreds of sites requires the correct API endpoints. Using the wrong endpoints (file system or WP-CLI) will give you incomplete or incorrect information. This guide shows you the correct way to manage plugins via the Rocket.net API.

✅ Correct Endpoint: GET/POST/PATCH/DELETE /v1/sites/{id}/plugins
This queries WordPress directly and shows plugin status, version, and activation state.
❌ Wrong Endpoints (Don’t Use):
  • /v1/sites/{id}/files – File system API (doesn’t show WordPress status)
  • /v1/sites/{id}/wpcli – WP-CLI (unreliable, returns null on many sites)
  • /v1/sites/{id}/file_manager/files – File manager (for files, not plugins)

Step-by-Step Guide

1 Authentication

Always authenticate first to get a JWT token. The token expires in 7 days.

$creds = @{
    username = 'your-email@example.com'
    password = 'your-password'
}

$login = Invoke-RestMethod -Uri 'https://api.rocket.net/v1/login' `
    -Method Post `
    -Body ($creds | ConvertTo-Json) `
    -ContentType 'application/json'

$token = $login.token
$headers = @{
    Authorization = "Bearer $token"
    'Content-Type' = 'application/json'
}

Important: If you get 401 errors, re-authenticate to get a fresh token.

2 List All Sites (with Pagination)

Rocket.net accounts can have 100+ sites. Always paginate to get all sites.

$allSites = @()
$page = 1

do {
    $response = Invoke-RestMethod `
        -Uri "https://api.rocket.net/v1/sites?page=$page&page_size=100" `
        -Method Get `
        -Headers $headers
    
    $allSites += $response.result
    $page++
} while ($response.result.Count -eq 100)

Write-Host "Total sites: $($allSites.Count)"
⚠️ Warning: The default API call returns only 10 sites. Using page_size=100 gets 100 sites per page. Always loop until result.Count < 100.

3 Check Plugins on a Site

Use the Plugins API endpoint to see what WordPress knows about.

# Find site by domain
$site = $allSites | Where-Object {
    $_.domain -match 'example.com'
}

# List all plugins
$plugins = Invoke-RestMethod `
    -Uri "https://api.rocket.net/v1/sites/$($site.id)/plugins" `
    -Method Get `
    -Headers $headers

# Check for specific plugin
$mlPlugins = $plugins.result | Where-Object {
    $_.name -like '*ml-plugin-manager*'
}

if ($mlPlugins) {
    $mlPlugins | ForEach-Object {
        Write-Host "Found: $($_.name)"
        Write-Host "  Status: $($_.status)"
        Write-Host "  Version: $($_.version)"
    }
}

Plugin Object Properties:

  • name - Plugin display name (e.g., "ml-plugin-manager-3.0.19")
  • status - "active" or "inactive"
  • version - Version number
  • slug - Plugin slug (may be empty)

4 Delete a Plugin

Use DELETE with the exact plugin name from the list.

$deleteBody = @{
    plugins = "ml-plugin-manager-3.0.19"
} | ConvertTo-Json

Invoke-RestMethod `
    -Uri "https://api.rocket.net/v1/sites/$($site.id)/plugins" `
    -Method Delete `
    -Headers $headers `
    -Body $deleteBody

Write-Host "Deleted: ml-plugin-manager-3.0.19"

Notes:

  • Use the exact name from the plugin list (not slug)
  • For multiple plugins: "plugins": "plugin1,plugin2,plugin3" (comma-separated)

5 Install a Plugin

Method A: Install from URL (Recommended for custom plugins)

$installBody = @{
    custom_url = "https://example.com/plugin.zip"
    activate = $true
} | ConvertTo-Json

Invoke-RestMethod `
    -Uri "https://api.rocket.net/v1/sites/$($site.id)/plugins" `
    -Method Post `
    -Headers $headers `
    -Body $installBody

Method B: Install from WordPress.org

$installBody = @{
    plugins = "plugin-slug"
    activate = $true
} | ConvertTo-Json

Invoke-RestMethod `
    -Uri "https://api.rocket.net/v1/sites/$($site.id)/plugins" `
    -Method Post `
    -Headers $headers `
    -Body $installBody

6 Activate/Deactivate a Plugin

# Activate
$activateBody = @{
    plugin = "ml-plugin-manager/ml-plugin-manager.php"
    status = "activate"
} | ConvertTo-Json

Invoke-RestMethod `
    -Uri "https://api.rocket.net/v1/sites/$($site.id)/plugins" `
    -Method Patch `
    -Headers $headers `
    -Body $activateBody

# Deactivate
$deactivateBody = @{
    plugin = "ml-plugin-manager/ml-plugin-manager.php"
    status = "deactivate"
} | ConvertTo-Json

Invoke-RestMethod `
    -Uri "https://api.rocket.net/v1/sites/$($site.id)/plugins" `
    -Method Patch `
    -Headers $headers `
    -Body $deactivateBody
⚠️ Critical: Use plugin (singular), not plugins. Use the plugin path: folder-name/main-file.php

Complete Example: Mass Plugin Update

This example shows how to replace an old plugin version across all sites.

# 1. Authenticate
$login = Invoke-RestMethod -Uri 'https://api.rocket.net/v1/login' `
    -Method Post `
    -Body (@{username='email@example.com'; password='password'} | ConvertTo-Json) `
    -ContentType 'application/json'
$token = $login.token
$h = @{Authorization="Bearer $token"; 'Content-Type'='application/json'}

# 2. Get all sites
$allSites = @(); $page = 1
do {
    $r = Invoke-RestMethod -Uri "https://api.rocket.net/v1/sites?page=$page&page_size=100" -Headers $h
    $allSites += $r.result
    $page++
} while ($r.result.Count -eq 100)

# 3. Find sites with old version
$sitesWithOld = @()
foreach ($site in $allSites) {
    try {
        $plugins = Invoke-RestMethod -Uri "https://api.rocket.net/v1/sites/$($site.id)/plugins" -Headers $h
        $old = $plugins.result | Where-Object {$_.name -eq 'ml-plugin-manager-3.0.19'}
        if ($old) {
            $sitesWithOld += [PSCustomObject]@{
                Domain = $site.domain
                ID = $site.id
            }
        }
    } catch { }
}

Write-Host "Found $($sitesWithOld.Count) sites with old version"

# 4. Update each site
foreach ($site in $sitesWithOld) {
    Write-Host "`nUpdating: $($site.Domain)"
    
    # Delete old version
    $delBody = @{plugins="ml-plugin-manager-3.0.19"} | ConvertTo-Json
    Invoke-RestMethod -Uri "https://api.rocket.net/v1/sites/$($site.ID)/plugins" `
        -Method Delete -Headers $h -Body $delBody
    
    # Install new version
    $installBody = @{
        custom_url="https://example.com/plugin.zip"
        activate=$true
    } | ConvertTo-Json
    Invoke-RestMethod -Uri "https://api.rocket.net/v1/sites/$($site.ID)/plugins" `
        -Method Post -Headers $h -Body $installBody
    
    Write-Host "  ✓ Updated successfully"
}

Quick Reference Table

Task Method Endpoint Body Example
List plugins GET /v1/sites/{id}/plugins None
Install from URL POST /v1/sites/{id}/plugins {"custom_url": "...", "activate": true}
Install from WP.org POST /v1/sites/{id}/plugins {"plugins": "slug", "activate": true}
Delete DELETE /v1/sites/{id}/plugins {"plugins": "name"}
Activate PATCH /v1/sites/{id}/plugins {"plugin": "path", "status": "activate"}
Deactivate PATCH /v1/sites/{id}/plugins {"plugin": "path", "status": "deactivate"}

✨ Best Practices

  1. Always authenticate first - Get fresh token for each session
  2. Always paginate - Don't assume first 10 sites are all sites
  3. Use Plugins API - Not files API or WP-CLI
  4. Verify after changes - List plugins again to confirm
  5. Handle errors gracefully - Sites might be down or inaccessible
  6. Test on one site first - Before mass deployment
  7. Use exact plugin names - From the API response, not guessed
  8. Wait between requests - Don't hammer the API

Common Errors & Solutions

Error Cause Solution
401 Unauthorized Token expired (7 days) Re-authenticate to get new token
404 Not Found Wrong site ID or plugin doesn't exist Verify site ID and plugin name
400 Bad Request Wrong parameter format Check JSON structure and parameter names
500 Internal Server Error Site might be down Try again in a few minutes

Why the Plugins API is Correct

WordPress tracks plugins in its database, not just by folder names. The Plugins API queries WordPress directly and returns:

  • ✅ Plugin display name (as WordPress sees it)
  • ✅ Activation status (active/inactive)
  • ✅ Version number
  • ✅ Plugin slug

File system APIs only show folders and files, which doesn't tell you:

  • ❌ If the plugin is active or inactive
  • ❌ What version WordPress thinks it is
  • ❌ If WordPress even recognizes it as a plugin