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

# Initiate file upload to GCS

> Generates a signed URL for direct file upload to Google Cloud Storage. Returns a signed URL valid for 15 minutes. Upload file via PUT request, then call /complete to finalize.

Generates a signed URL for direct file upload to Google Cloud Storage. Returns a signed URL valid for 15 minutes. Upload file via PUT request, then call /complete to finalize.

```http theme={null}
POST https://services.leadconnectorhq.com/conversations/messages/upload/initiate
```

## Autorización

<ParamField header="Authorization" type="string" required>
  Bearer token generado desde el portal Leadway. Ver [Autenticación](/authentication).
</ParamField>

<ParamField header="Version" type="string" required default="2021-07-28">
  Versión de la API.
</ParamField>

## Body

<ParamField body="locationId" type="string" required default="ve9EPM428h8vShlRW1KT">
  Account ID
</ParamField>

<ParamField body="conversationId" type="string" required default="ve9EPM428h8vShlRW1KT">
  Conversation ID
</ParamField>

<ParamField body="filename" type="string" required default="video.mp4">
  Original filename with extension
</ParamField>

<ParamField body="contentType" type="string" required default="video/mp4">
  MIME type of the file
</ParamField>

<ParamField body="fileSize" type="number" default="52428800">
  File size in bytes (optional, for pre-validation)
</ParamField>

<ParamField body="channel" type="string" required default="WHATSAPP">
  Channel type for size limits (WHATSAPP for 100MB limit, others for 5MB)
</ParamField>

## Respuestas

<Accordion title="200 - Signed URL generated successfully">
  <ResponseField name="uploadUrl" type="string" required default="https://storage.googleapis.com/bucket/path?X-Goog-Algorithm=...">
    Signed URL for direct upload to GCS. Use PUT request with file content.
  </ResponseField>

  <ResponseField name="uploadId" type="string" required default="a1b2c3d4-e5f6-7890-abcd-ef1234567890">
    Unique upload ID for tracking and completing the upload
  </ResponseField>

  <ResponseField name="filePath" type="string" required default="account/loc123/conversations/conv456/uuid.mp4">
    File path in GCS bucket (needed for confirmation endpoint)
  </ResponseField>

  <ResponseField name="expiresAt" type="number" required default="1701619200000">
    URL expiration timestamp (Unix milliseconds)
  </ResponseField>

  <ResponseField name="maxFileSize" type="number" required default="104857600">
    Maximum allowed file size in bytes
  </ResponseField>

  ```json theme={null}
  {
    "uploadUrl": "https://storage.googleapis.com/bucket/path?X-Goog-Algorithm=...",
    "uploadId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    "filePath": "account/loc123/conversations/conv456/uuid.mp4",
    "expiresAt": 1701619200000,
    "maxFileSize": 104857600
  }
  ```
</Accordion>

<Accordion title="400 - Bad Request - Invalid parameters" />

<Accordion title="401 - Unauthorized">
  ```json theme={null}
  {}
  ```
</Accordion>

<Accordion title="413 - File size exceeds maximum allowed limit" />

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://services.leadconnectorhq.com/conversations/messages/upload/initiate' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "locationId": "ve9EPM428h8vShlRW1KT",
    "conversationId": "ve9EPM428h8vShlRW1KT",
    "filename": "video.mp4",
    "contentType": "video/mp4",
    "fileSize": 52428800,
    "channel": "WHATSAPP"
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/conversations/messages/upload/initiate', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"locationId": "ve9EPM428h8vShlRW1KT", "conversationId": "ve9EPM428h8vShlRW1KT", "filename": "video.mp4", "contentType": "video/mp4", "fileSize": 52428800, "channel": "WHATSAPP"}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/conversations/messages/upload/initiate',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"locationId": "ve9EPM428h8vShlRW1KT", "conversationId": "ve9EPM428h8vShlRW1KT", "filename": "video.mp4", "contentType": "video/mp4", "fileSize": 52428800, "channel": "WHATSAPP"},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/conversations/messages/upload/initiate');
  curl_setopt_array($ch, [
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_CUSTOMREQUEST => 'POST',
      CURLOPT_HTTPHEADER => [
          'Authorization: Bearer ' . getenv('LEADWAY_TOKEN'),
          'Version: 2021-07-28',
          'Content-Type: application/json',
      ],
      CURLOPT_POSTFIELDS => json_encode({'locationId': 've9EPM428h8vShlRW1KT', 'conversationId': 've9EPM428h8vShlRW1KT', 'filename': 'video.mp4', 'contentType': 'video/mp4', 'fileSize': 52428800, 'channel': 'WHATSAPP'}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
