Back

API Documentation

Programmatically create short links from your applications.

Getting Started

To use the API, you need an API key. Create one by signing in and visiting the API Keys page.

Include your API key in the Authorization header as a Bearer token.

Create Short Link

POST/api/external/shorten

Request Body

ParameterTypeDescription
originalUrlstringRequired. The URL to shorten.
slugstringOptional. Custom slug (4-20 chars, alphanumeric with - and _).

Example Request

curl -X POST https://cory.to/api/external/shorten \
  -H "Authorization: Bearer sk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"originalUrl": "https://example.com/very-long-url"}'

Response

{
  "slug": "abc1",
  "shortUrl": "https://cory.to/abc1",
  "originalUrl": "https://example.com/very-long-url",
  "createdAt": "2024-01-15T12:00:00Z"
}

JavaScript Example

const response = await fetch('https://cory.to/api/external/shorten', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk_your_api_key',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    originalUrl: 'https://example.com/very-long-url',
    slug: 'custom-slug' // optional
  }),
});

const data = await response.json();
console.log(data.shortUrl); // https://cory.to/custom-slug

Error Codes

CodeDescription
400Bad request - Missing or invalid parameters
401Unauthorized - Invalid or missing API key
409Conflict - Slug already exists
500Server error

Ready to get started?

Create an account to generate your API key.