API Docs
Examples

Code Examples

These examples use JSON request bodies, stable resource IDs, and the standard v1 response envelope. Keep server keys on your backend.

Create And Read A Link

JavaScript
const apiKey = process.env.SHORTIFY_API_KEY;
const baseUrl = 'https://api.shortify.com';

async function request(path, options = {}) {
  const response = await fetch(`${baseUrl}${path}`, {
    ...options,
    headers: {
      'api-key': apiKey,
      'Content-Type': 'application/json',
      ...options.headers,
    },
  });
  const body = await response.json();
  if (!response.ok || !body.success) {
    throw new Error(body.error?.message || 'Shortify request failed');
  }
  return body;
}

async function createAndReadLink() {
  const created = await request('/v1/links', {
    method: 'POST',
    headers: {'Idempotency-Key': 'pricing-2026-create'},
    body: JSON.stringify({
      url: 'https://example.com/pricing',
      domain: 'go.example.com',
      key: 'pricing-2026',
      title: 'Pricing campaign',
      tags: ['pricing', 'email'],
      objects: {campaign: 'spring-2026'},
    }),
  });

  const fetched = await request(`/v1/links/${created.data.id}`);
  return {created: created.data, fetched: fetched.data};
}

Client Attribution Flow

Browser or SDK wrapper
const publishableKey = 'pk_live_your_publishable_key';
const baseUrl = 'https://api.shortify.com';

async function clientRequest(path, body) {
  const response = await fetch(`${baseUrl}${path}`, {
    method: 'POST',
    headers: {
      'x-publishable-key': publishableKey,
      'x-shortify-platform': 'browser',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(body),
  });
  const data = await response.json();
  if (!response.ok || !data.success) {
    throw new Error(data.error?.message || 'Shortify client request failed');
  }
  return data.data;
}

const click = await clientRequest('/v1/client/attribution/click', {
  shortLink: 'https://go.example.com/invite-abc',
  sessionId: 'anon-session-123',
});

await clientRequest('/v1/client/events', {
  events: [{
    name: 'signup_completed',
    eventId: 'signup-123',
    attributionId: click.attributionId,
    properties: {plan: 'pro'},
  }],
});

Analytics Export

Raw events
curl "https://api.shortify.com/v1/analytics/events?range=30d&eventType=customer_event&limit=50" \
  -H "api-key: sk_live_your_server_key"