Skip to content

Add link management API: list, rename, update, toggle, delete - #647

Open
PLNech wants to merge 1 commit into
cydrobolt:masterfrom
PLNech:feature/link-management-api
Open

Add link management API: list, rename, update, toggle, delete#647
PLNech wants to merge 1 commit into
cydrobolt:masterfrom
PLNech:feature/link-management-api

Conversation

@PLNech

@PLNech PLNech commented Jun 11, 2026

Copy link
Copy Markdown

Summary

polr's v2 API can shorten, look up, and report analytics, but managing existing links is only possible through the admin web UI. This adds five api-key-protected endpoints under /api/v2/action/, reusing the existing api middleware so authentication and quotas are unchanged:

Method Endpoint Does
GET action/list list your links (admins: all), optional substring filter
POST action/rename rename a link ending in place (destination/clicks/date kept)
POST action/update change a link's destination URL
POST action/toggle enable/disable a link without deleting it
POST action/delete delete a link

Ownership & safety

All five enforce ownership: a user may manage links they created, admins may manage any link, and anonymous API users are refused. Validation and error handling mirror the existing shorten/lookup endpoints (ApiException codes, alpha_dash endings, URL validation, collision checks on rename).

Credit

The delete endpoint builds on the approach in #632 (thanks @technowhizz), adding ownership enforcement, POST + action/ namespacing for consistency with the rest of the v2 API, and a structured JSON response.

Tests & CI

  • tests/ApiLinkManagementTest.php — 20 tests (success, validation, ownership, admin override, not-found). Full suite passes (20 tests, 58 assertions).
  • Since Travis CI is no longer active, this also adds a GitHub Actions workflow (PHP 7.2/7.3 + MySQL 5.7) running the existing + new suite. Note: the committed composer.lock currently requires PHP ≥ 7.2 (doctrine/lexer 1.2.1), which is why the matrix starts at 7.2.

Docs

All five endpoints documented in docs/developer-guide/api.md in the existing style.

Closes #221, closes #442, closes #538.

polr's v2 API can shorten, look up, and report analytics, but managing
existing links is only possible through the admin web UI. This adds five
api-key-protected endpoints under /api/v2/action/, reusing the existing
`api` middleware (authentication and quotas are unchanged):

  GET  action/list    list your links (admins: all), optional substring filter
  POST action/rename  rename a link ending in place (destination/clicks kept)
  POST action/update  change a link's destination URL
  POST action/toggle  enable/disable a link without deleting it
  POST action/delete  delete a link

All five enforce ownership: a user may manage links they created, admins
may manage any link, and anonymous API users are refused. Validation and
error handling mirror the existing shorten/lookup endpoints (ApiException
codes, alpha_dash endings, URL validation, collision checks on rename).

The delete endpoint builds on the approach in cydrobolt#632 (thanks @technowhizz),
adding ownership enforcement, POST + action/ namespacing for consistency,
and a structured response.

Adds tests/ApiLinkManagementTest.php (20 tests pass) covering success,
validation, ownership, admin override, and not-found paths. Documents all
five endpoints in docs/developer-guide/api.md. Adds a GitHub Actions CI
workflow (PHP 7.2/7.3 + MySQL) since Travis CI is no longer active.

Closes cydrobolt#221, cydrobolt#442, cydrobolt#538.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to delete my own links Update and/or delete a link via API Add Short URL List API Endpoint

1 participant