Redirects API

Complete API reference for managing redirects programmatically. All endpoints require authentication.

Authentication

All API requests must include authentication. RedirectFlow uses session-based authentication for web requests.

Request Headers

Content-Type: application/json
Cookie: next-auth.session-token=your-session-token

Note: API tokens are available on Pro and Business plans. Contact support for details.

Base URL

https://your-domain.com/api

Replace with your actual RedirectFlow instance URL

Endpoints

GET/api/redirects

Retrieve all redirects for authenticated user

Query Parameters

NameTypeDescription
website_idintegerFilter by website ID
groupstringFilter by redirect group

Response

200Success
{
  "redirects": [
    {
      "id": 1,
      "old_path": "/old-blog",
      "new_path": "/blog", 
      "status_code": 301,
      "is_regex": false,
      "group_id": "blog",
      "website_id": 1,
      "target_environments": "production,staging",
      "deployed_to_prod": "2024-01-15T10:30:00Z",
      "deployed_to_staging": "2024-01-15T10:29:00Z",
      "deployed_to_dev": null,
      "created_at": "2024-01-15T09:00:00Z",
      "updated_at": "2024-01-15T10:30:00Z"
    }
  ]
}
POST/api/redirects

Create a new redirect

Request Body

{
  "old_path": "/old-page",
  "new_path": "/new-page",
  "status_code": 301,
  "is_regex": false,
  "group_id": "migration",
  "website_id": 1,
  "target_environments": "production",
  "notes": "Migration redirect for old page"
}

Response

201Success
{
  "redirect": {
    "id": 2,
    "old_path": "/old-page",
    "new_path": "/new-page",
    "status_code": 301,
    "is_regex": false,
    "group_id": "migration",
    "website_id": 1,
    "target_environments": "production",
    "notes": "Migration redirect for old page",
    "created_at": "2024-01-15T11:00:00Z",
    "updated_at": "2024-01-15T11:00:00Z"
  }
}
PUT/api/redirects/{id}

Update an existing redirect

Request Body

{
  "old_path": "/updated-old-path",
  "new_path": "/updated-new-path",
  "status_code": 302,
  "target_environments": "production,staging"
}

Response

200Success
{
  "redirect": {
    "id": 2,
    "old_path": "/updated-old-path",
    "new_path": "/updated-new-path",
    "status_code": 302,
    "target_environments": "production,staging",
    "updated_at": "2024-01-15T12:00:00Z"
  }
}
DELETE/api/redirects/{id}

Delete a redirect

Response

200Success
{
  "message": "Redirect deleted successfully"
}
POST/api/redirects/bulk-update

Update multiple redirects at once

Request Body

{
  "redirectIds": [1, 2, 3],
  "updates": {
    "target_environments": "production,staging,development",
    "group_id": "updated-group"
  }
}

Response

200Success
{
  "updated": 3,
  "message": "Redirects updated successfully"
}
DELETE/api/redirects/bulk-delete

Delete multiple redirects at once

Request Body

{
  "redirectIds": [1, 2, 3]
}

Response

200Success
{
  "deleted": 3,
  "message": "Redirects deleted successfully"
}
POST/api/redirects/import

Import redirects from CSV file

Request Body

FormData with CSV file

Response

200Success
{
  "imported": 25,
  "skipped": 2,
  "errors": [],
  "message": "Import completed successfully"
}

Error Codes

The API uses conventional HTTP response codes to indicate success or failure.

CodeMessageDescription
400Bad RequestInvalid request parameters or body
401UnauthorizedAuthentication required
403ForbiddenInsufficient permissions or usage limits exceeded
404Not FoundRedirect not found
409ConflictRedirect with same path already exists
422Unprocessable EntityValidation errors
429Too Many RequestsRate limit exceeded
500Internal Server ErrorServer error occurred

Example Usage

JavaScript/Fetch

// Create a new redirect
const response = await fetch('/api/redirects', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  credentials: 'include', // Include cookies for session auth
  body: JSON.stringify({
    old_path: '/old-page',
    new_path: '/new-page',
    status_code: 301,
    website_id: 1,
    target_environments: 'production'
  })
});

const result = await response.json();
console.log('Created redirect:', result.redirect);

cURL

curl -X POST https://your-domain.com/api/redirects \
  -H "Content-Type: application/json" \
  -H "Cookie: next-auth.session-token=your-session-token" \
  -d '{
    "old_path": "/old-page",
    "new_path": "/new-page", 
    "status_code": 301,
    "website_id": 1,
    "target_environments": "production"
  }'

Rate Limits

100
requests per minute
Free Plan
1,000
requests per minute
Pro Plan
5,000
requests per minute
Business Plan