Code Examples

End-to-end examples for short links and deeplinks.

Short Link Flow (Create + Retrieve)

const apiKey = 'your_workspace_api_key';
const baseUrl = 'https://app.shortify.com/api/mobile';

async function createShortLink() {
  const formData = new FormData();
  formData.append('url', 'https://example.com/pricing');
  formData.append('slug', 'pricing-2026');
  formData.append('objects', JSON.stringify({ campaign: 'spring-2026' }));
  formData.append('tags', JSON.stringify(['pricing', 'email']));

  const response = await fetch(`${baseUrl}/link/create`, {
    method: 'POST',
    headers: { 'api-key': apiKey },
    body: formData,
  });

  const data = await response.json();
  if (!data.success) throw new Error(data.msg || data.error || 'Create failed');
  return data.data;
}

async function getShortLink(fullShortLink) {
  const query = encodeURIComponent(fullShortLink);
  const response = await fetch(`${baseUrl}/link?shortLink=${query}`, {
    method: 'GET',
    headers: { 'api-key': apiKey },
  });

  const data = await response.json();
  if (!data.success) throw new Error(data.msg || data.error || 'Retrieve failed');
  return data.data;
}

(async () => {
  const created = await createShortLink();
  const fetched = await getShortLink(created.shortLink);
  console.log('Created:', created);
  console.log('Fetched:', fetched);
})();

Deeplink Flow (Create + Retrieve)

const deeplinkApiKey = 'your_deeplink_app_api_key';
const baseUrl = 'https://app.shortify.com/api/mobile';

async function createDeeplink() {
  const formData = new FormData();
  formData.append('slug', 'invite-abc');
  formData.append('objects', JSON.stringify({ campaign: 'invite-2026' }));
  formData.append('tags', JSON.stringify(['invite', 'mobile']));

  const response = await fetch(`${baseUrl}/deeplink`, {
    method: 'POST',
    headers: { 'api-key': deeplinkApiKey },
    body: formData,
  });

  const data = await response.json();
  if (!data.success) throw new Error(data.msg || data.error || 'Create failed');
  return data.data;
}

async function getDeeplink(fullShortLink) {
  const query = encodeURIComponent(fullShortLink);
  const response = await fetch(`${baseUrl}/deeplink?shortLink=${query}`, {
    method: 'GET',
    headers: { 'api-key': deeplinkApiKey },
  });

  const data = await response.json();
  if (!data.success) throw new Error(data.msg || data.error || 'Retrieve failed');
  return data.data;
}

(async () => {
  const created = await createDeeplink();
  const fetched = await getDeeplink(created.shortLink);
  console.log('Created:', created);
  console.log('Fetched:', fetched);
})();