> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ugc.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# Upload Social Audio

> Import audio from a TikTok or Instagram URL

## Endpoint

```
POST https://api.ugc.inc/media/social-audio/upload
```

## Overview

Import audio from TikTok or Instagram by providing a video, music, reel, or audio page URL. The API will extract the audio file and cover image, upload them to storage, and create a social audio record.

**Supported URL formats:**

* TikTok Video URL: `https://www.tiktok.com/@username/video/1234567890`
* TikTok Music URL: `https://www.tiktok.com/music/Song-Name-1234567890`
* Instagram Reel URL: `https://www.instagram.com/reel/ABC123xyz/`
* Instagram Post URL: `https://www.instagram.com/p/ABC123xyz/`
* Instagram Audio URL: `https://www.instagram.com/reels/audio/1234567890/`

## Request Body

<ParamField body="url" type="string" required>
  TikTok or Instagram URL to import audio from
</ParamField>

<ParamField body="tag" type="string">
  Optional tag for categorization
</ParamField>

## Response

<ResponseField name="data" type="SocialAudio">
  The created social audio object

  <Expandable title="SocialAudio properties">
    <ResponseField name="id" type="string">
      Unique audio identifier
    </ResponseField>

    <ResponseField name="name" type="string | null">
      Audio/song title extracted from the source platform
    </ResponseField>

    <ResponseField name="tag" type="string | null">
      Custom tag for categorization
    </ResponseField>

    <ResponseField name="social_post_link" type="string | null">
      Link to a post using this audio (TikTok video or Instagram reel)
    </ResponseField>

    <ResponseField name="social_audio_link" type="string | null">
      Direct link to the audio/music page on the source platform
    </ResponseField>

    <ResponseField name="platform_type" type="'tiktok' | 'instagram'">
      Source platform
    </ResponseField>

    <ResponseField name="preview_url" type="string | null">
      URL to uploaded cover image
    </ResponseField>

    <ResponseField name="audio_url" type="string | null">
      URL to uploaded audio file
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO timestamp of creation
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api.ugc.inc/media/social-audio/upload \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "url": "https://www.tiktok.com/@username/video/1234567890",
      "tag": "trending"
    }'
  ```

  ```python Python theme={null}
  import requests

  # Import from TikTok video URL
  response = requests.post(
      'https://api.ugc.inc/media/social-audio/upload',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
      },
      json={
          'url': 'https://www.tiktok.com/@username/video/1234567890',
          'tag': 'trending'
      }
  )

  # Import from Instagram reel URL
  response = requests.post(
      'https://api.ugc.inc/media/social-audio/upload',
      headers={
          'Authorization': 'Bearer YOUR_API_KEY',
          'Content-Type': 'application/json'
      },
      json={
          'url': 'https://www.instagram.com/reel/ABC123xyz/',
          'tag': 'instagram-audio'
      }
  )

  data = response.json()

  if data['ok']:
      audio = data['data']
      print(f"Imported: {audio['name']}")
      print(f"Audio URL: {audio['audio_url']}")
      print(f"Cover URL: {audio['preview_url']}")
  ```

  ```javascript JavaScript theme={null}
  // Import from Instagram audio page URL
  const response = await fetch('https://api.ugc.inc/media/social-audio/upload', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'https://www.instagram.com/reels/audio/1234567890/',
      tag: 'music'
    })
  });

  const data = await response.json();

  if (data.ok) {
    console.log('Imported:', data.data.name);
    console.log('Audio URL:', data.data.audio_url);
  }
  ```

  ```typescript React theme={null}
  import { UGCClient } from 'ugcinc';

  const client = new UGCClient({
    apiKey: 'YOUR_API_KEY'
  });

  // Import from TikTok video URL
  const response = await client.media.createSocialAudio({
    url: 'https://www.tiktok.com/@username/video/1234567890',
    tag: 'trending'
  });

  // Import from Instagram reel URL
  const igResponse = await client.media.createSocialAudio({
    url: 'https://www.instagram.com/reel/ABC123xyz/',
    tag: 'instagram-audio'
  });

  if (response.ok) {
    console.log('Imported:', response.data.name);
    console.log('Audio URL:', response.data.audio_url);
    console.log('Cover URL:', response.data.preview_url);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json Success Response (TikTok) theme={null}
  {
    "ok": true,
    "code": 200,
    "data": {
      "id": "audio_abc123",
      "org_id": "org_xyz789",
      "name": "Trending Sound - Artist Name",
      "tag": "trending",
      "social_post_link": "https://www.tiktok.com/@username/video/1234567890",
      "social_audio_link": "https://www.tiktok.com/music/Trending-Sound-1234567890",
      "platform_type": "tiktok",
      "preview_url": "https://api.ugc.inc/media/file/audio_abc123/preview",
      "audio_url": "https://api.ugc.inc/media/file/audio_abc123/audio",
      "created_at": "2024-01-15T10:30:00.000Z"
    }
  }
  ```

  ```json Success Response (Instagram) theme={null}
  {
    "ok": true,
    "code": 200,
    "data": {
      "id": "audio_def456",
      "org_id": "org_xyz789",
      "name": "Original Audio - artistname",
      "tag": "instagram-audio",
      "social_post_link": "https://www.instagram.com/reel/ABC123xyz/",
      "social_audio_link": "https://www.instagram.com/reels/audio/1234567890/",
      "platform_type": "instagram",
      "preview_url": "https://api.ugc.inc/media/file/audio_def456/preview",
      "audio_url": "https://api.ugc.inc/media/file/audio_def456/audio",
      "created_at": "2024-01-15T10:30:00.000Z"
    }
  }
  ```

  ```json Error Response - Invalid URL theme={null}
  {
    "ok": false,
    "code": 400,
    "message": "Invalid URL format. Must be a TikTok or Instagram URL"
  }
  ```

  ```json Error Response - No Posts Found theme={null}
  {
    "ok": false,
    "code": 404,
    "message": "No posts found for this music"
  }
  ```
</ResponseExample>
