Saltar al contenido

Esta documentación solo está disponible en inglés.

REST API

Base URL: https://linkmag.net/v1. The OpenAPI document at https://linkmag.net/v1/openapi.json is the machine-readable contract; GET /v1 lists the same endpoints.

Formats

AcceptResponse
defaultJSON
text/markdownWhat happened and the next call
text/plainkey=value lines a shell can parse without a JSON tool

Authentication

Requests send Authorization: Bearer <key>. Keys start with lm_. Signed-in users create and revoke keys on the API keys page; without a browser session, the device flow issues one:

curl -s -X POST https://linkmag.net/v1/keys/requests \
  -H 'Content-Type: application/json' -d '{"client_name": "My agent"}'

The response holds user_code, approve_url, request_id and device_code. The user opens the link, signs in and approves the code. Meanwhile the claim endpoint is polled every interval seconds:

curl -s -X POST https://linkmag.net/v1/keys/requests/REQUEST_ID/claim \
  -H 'Content-Type: application/json' -d '{"device_code": "DEVICE_CODE"}'

It answers 202 {"status":"pending"} until approval, then 200 with api_key, exactly once. Requests expire after 15 minutes.

Endpoints

MethodPathKeyPurpose
POST/v1/keys/requestsnoStart a key request
POST/v1/keys/requests/{requestId}/claimnoClaim the key after approval
GET/v1/validate?url=noAudit any public page's tags
GET/v1/sitesyesList sites
POST/v1/sitesyesCreate a site
GET/v1/sites/{siteId}yesSite, domains, usage
DELETE/v1/sites/{siteId}yesDelete a site
POST/v1/sites/{siteId}/domainsyesRegister a hostname
POST/v1/sites/{siteId}/domains/{hostname}/verifyyesVerify by DNS or meta tag
DELETE/v1/sites/{siteId}/domains/{hostname}yesRemove a hostname
PATCH/v1/sites/{siteId}/templateyesLayout, colors, logo, caption, badge
GET/v1/sites/{siteId}/usageyesPlan, period and new cards drawn (cache misses)
GET/v1/sites/{siteId}/snippet?framework=yesInstall code for a framework
GET/v1/sites/{siteId}/preview?path=yesCard URL for a path
POST/v1/sites/{siteId}/purgeyesDrop cached cards (Pro, Business)
GET/v1/sites/{siteId}/linksyesShort links with click totals, newest first (?before= pages)
POST/v1/sites/{siteId}/linksyesShort link to a page on a served domain: {"url": "https://…"}
GET/v1/links/{linkId}/stats?days=yesClicks per day, referrers, countries, devices (1 to 90 days)
DELETE/v1/links/{linkId}yesDelete a link and its click history
GET/v1/sites/{siteId}/short-domainyesRe-check the custom short domain and return the DNS still needed
PUT/v1/sites/{siteId}/short-domainyesSet a custom short domain (Business): {"hostname": "go.example.com"}
DELETE/v1/sites/{siteId}/short-domainyesRemove the custom short domain
POST/v1/sites/{siteId}/checkoutyesStripe Checkout link for Pro or Business: {"plan": "pro"}
POST/v1/sites/{siteId}/billing-portalyesStripe portal link: payment method, invoices, cancellation
GET/v1/og/{siteId}noThe card image itself

Checkout and portal links are for the user to open; plan rules are in Pricing.

Errors

Errors carry a machine code, a message and a fix:

{"error": {"code": "unauthorized", "message": "This call needs an API key.", "fix": "Request one with POST /v1/keys/requests, …"}}
CodeHTTP
invalid_request400
unauthorized401
forbidden, plan_required403
not_found404
conflict, limit_reached409
server_error500 or 503
billing_unavailable503

The card endpoint answers 403 for a verified domain past the plan's domain limit. Past the fair-use limit of 20,000 new cards per site per UTC day, it redirects (302) to the page's own og:image, or answers 503 with Retry-After when the page has none; cached cards keep serving.

  • Destination: a page on one of the site's served domains (the verified domains its plan covers). Any other URL is refused with forbidden. A destination the site already links to returns the existing link.
  • Limit: 10,000 links per site. Deleting a site deletes its links.
  • People get a 302 to the page and are counted.
  • Crawlers for link previews and search (X, LinkedIn, Slack, Discord, iMessage, Google, Bing and others) get the page's title and description with the site's card as the image, and are not counted. The card is drawn and cached like any other. Other automated visits may be counted.
  • Older links created before sites existed no longer redirect: ones made without an account are retired (404), and ones made from an account open a page that shows the destination with a button to continue. New links always belong to a site.

Custom short domain

On Business, PUT /v1/sites/{siteId}/short-domain serves the site's links on a subdomain of a served domain, such as go.example.com. The response names a CNAME record for the user to add, plus a TXT record when Vercel asks for one. The domain activates once the records resolve; GET on the same path re-checks it, and pending domains are re-checked every hour for 7 days.

If the site leaves Business, or the parent domain stops being served, the short domain stops serving and is removed within the hour. Links shared on it stop working; the same links keep working on the LinkMagnet URL.

Los agentes pueden pedir cualquier página de este sitio en markdown enviando Accept: text/markdown.