REST API Reference

Keyboard shortcuts
  • JNext lesson
  • KPrevious lesson
  • /Search lessons
  • EscClear search

Overview

GT Link Manager exposes a REST API under the namespace gt-link-manager/v1. All endpoints are available at yoursite.com/wp-json/gt-link-manager/v1/.

All endpoints require authentication. Requests must include a valid WordPress nonce or use an authenticated session. The capability required is edit_posts for most link and category operations, and manage_options for anything involving settings. Unauthenticated requests receive a 401 Unauthorized response.

Links endpoints

List links

GET /wp-json/gt-link-manager/v1/links

Returns a paginated list of links matching the given filters.

Query parameters:

search — a string to search across name, slug, and URL. Optional.

page — integer, default 1. The page of results to return.

per_page — integer, default 20, minimum 1, maximum 200. Pass -1 to return all matching links without pagination. Use -1 with caution on large datasets.

category_id — integer, default 0. Filter by category. 0 returns links from all categories.

link_mode — string. Filter by link mode. Allowed values: standard, direct, regex. Optional — omit to return links of all modes.

orderby — the column to sort by. Allowed values: id, name, slug, url, redirect_type, rel, category_id, link_mode, priority, created_at, updated_at. Default: id.

orderASC or DESC. Default: DESC.

Response headers:

X-WP-Total — the total number of links matching the filters across all pages.

X-WP-TotalPages — the total number of pages at the current per_page setting.

Response body:

An array of link objects. Each link object has the following fields:

id — integer. The link’s database ID.

name — string. The display name.

slug — string. The URL slug (or path for direct, or pattern for regex).

url — string. The destination URL.

redirect_type — integer. 301, 302, or 307.

rel — string. Comma-separated rel values (e.g., nofollow,sponsored).

noindex — integer. 0 or 1.

is_active — integer. 0 or 1. Whether the link actively resolves redirects.

category_id — integer. The assigned category ID, or 0 if uncategorized.

tags — string. Comma-separated tag values.

notes — string. Private notes text.

link_mode — string. One of standard, direct, or regex.

regex_replacement — string. The preg_replace replacement pattern (regex mode only). Empty string for other modes.

priority — integer. Regex rule evaluation priority (lower = first). Default 10.

branded_url — string. The full branded URL for this link. For standard links, this is yoursite.com/prefix/slug. For direct links, this is yoursite.com/slug. For regex links, this field is empty (patterns don’t have a fixed URL).

created_at — string. ISO 8601 datetime.

updated_at — string. ISO 8601 datetime or null.

trashed_at — string or null. ISO 8601 datetime if trashed, null if active.


Get a single link

GET /wp-json/gt-link-manager/v1/links/{id}

Returns a single link object by its database ID. Returns 404 Not Found if no link exists with that ID.


Create a link

POST /wp-json/gt-link-manager/v1/links

Creates a new link. Send the request body as JSON.

Required fields:

name — string. The display name.

url — string. The destination URL. Must be a valid URL.

Optional fields:

slug — string. If omitted, auto-generated from the name (standard mode only).

redirect_type — integer. 301, 302, or 307. Defaults to the plugin’s configured default.

rel — string. Comma-separated rel values.

noindex — integer. 0 or 1. Defaults to 0.

is_active — integer. 0 or 1. Defaults to 1.

category_id — integer. Defaults to 0.

tags — string.

notes — string.

link_mode — string. standard, direct, or regex. Defaults to standard.

regex_replacement — string. Only used when link_mode is regex.

priority — integer. Only used when link_mode is regex. Defaults to 10.

Returns the created link object with a 201 Created status. Returns a validation error if the slug is already in use.


Update a link

PUT /wp-json/gt-link-manager/v1/links/{id}

Updates an existing link. Send the full or partial link object as JSON. Only fields present in the request body are updated.

Returns the updated link object. Returns 404 Not Found if the link doesn’t exist.


Delete a link

DELETE /wp-json/gt-link-manager/v1/links/{id}

Soft-deletes (trashes) a link by default. Pass ?force=true to permanently delete the link from the database.

Returns a confirmation object with the deleted/trashed link data. Returns 404 Not Found if the link doesn’t exist.


Restore a trashed link

PUT /wp-json/gt-link-manager/v1/links/{id}/restore

Restores a previously trashed link by clearing the trashed_at timestamp. The link becomes active again and will resume resolving redirects (if is_active is 1).

Returns the restored link object. Returns 404 Not Found if the link doesn’t exist.


Toggle active status

PUT /wp-json/gt-link-manager/v1/links/{id}/toggle-active

Toggles a link’s is_active flag between 0 and 1. Returns the updated link object with the new active state.


Bulk category assignment

POST /wp-json/gt-link-manager/v1/links/bulk-category

Moves or copies multiple links to a category in a single request.

Request body:

link_ids — array of integers. The IDs of the links to act on. Required.

category_id — integer. The target category ID. Use 0 to uncategorize. Required.

mode — string. Either move or copy. Required.

move updates the category_id of each specified link. copy creates duplicates of each specified link assigned to the target category, with auto-suffixed slugs. Copied links preserve all fields including link_mode, regex_replacement, priority, and is_active.

Returns a summary object with counts of affected links.


Categories endpoints

List categories

GET /wp-json/gt-link-manager/v1/categories

Returns all categories as an array. Accepts an optional search query parameter to filter by name.

Each category object has: id, name, slug, description, parent_id, count.


Create a category

POST /wp-json/gt-link-manager/v1/categories

Creates a new category.

Required fields:

name — string. The category display name.

Optional fields:

slug — string. Auto-generated from name if omitted.

description — string.

parent_id — integer. Default 0.

Returns the created category object.


Update a category

PUT /wp-json/gt-link-manager/v1/categories/{id}

Updates an existing category. Partial updates are supported.

Returns the updated category object.


Delete a category

DELETE /wp-json/gt-link-manager/v1/categories/{id}

Deletes a category. Links assigned to the deleted category are uncategorized (their category_id is set to 0). Returns a confirmation object.


Authentication

For server-side requests, use Basic Authentication with an application password (WordPress 5.6+). For browser-based requests, the WordPress REST API nonce is included automatically when making requests from within the WordPress admin.

For headless or external integrations, generate an application password at Users → Profile → Application Passwords. Send requests with Authorization: Basic base64(username:application_password).

Error responses

All error responses follow the standard WordPress REST API error format: an object with code, message, and data fields. The data field includes a status integer with the HTTP status code.

Common error codes used by GT Link Manager:

gt_link_not_found — the requested link or category does not exist.

gt_link_invalid_slug — the slug is already in use or contains invalid characters.

gt_link_missing_required — a required field was not provided.

gt_link_invalid_value — a field value fails validation (e.g., redirect_type is not 301, 302, or 307).

Example: Creating a regex redirect via the API

curl -X POST https://yoursite.com/wp-json/gt-link-manager/v1/links \
  -u "username:application_password" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Old Blog Migration",
    "slug": "old-blog/(.*)",
    "url": "https://newsite.com/blog/$1",
    "link_mode": "regex",
    "regex_replacement": "https://newsite.com/blog/$1",
    "priority": 5,
    "redirect_type": 301
  }'

This creates a regex rule that redirects any URL matching yoursite.com/old-blog/anything to newsite.com/blog/anything, evaluated at priority 5 (before the default priority 10 rules).