> ## 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.

# Upload file attachments

> Post the necessary fields for the API to upload files. The files need to be a buffer with the key "fileAttachment". <br /><br /> The allowed file types are: <br/> <ul><li>JPG</li><li>JPEG</li><li>PNG<

Post the necessary fields for the API to upload files. The files need to be a buffer with the key "fileAttachment". \<br />\<br /> The allowed file types are: \<br/> \<ul>\<li>JPG\</li>\<li>JPEG\</li>\<li>PNG\</li>\<li>MP4\</li>\<li>MPEG\</li>\<li>ZIP\</li>\<li>RAR\</li>\<li>PDF\</li>\<li>DOC\</li>\<li>DOCX\</li>\<li>TXT\</li>\<li>MP3\</li>\<li>WAV\</li>\</ul> \<br />\<br /> The API will return an object with the URLs

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

## 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="conversationId" type="string" required default="ve9EPM428h8vShlRW1KT">
  Conversation Id
</ParamField>

<ParamField body="contactId" type="string" required default="ve9EPM428h8vShlRW1KT">
  Contact Id
</ParamField>

<ParamField body="locationId" type="string" required />

<ParamField body="attachmentUrls" type="string[]" required />

<ParamField body="chatServiceSid" type="string" default="ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx">
  Twilio chat service SID for group SMS uploads
</ParamField>

<ParamField body="isGroupSms" type="string" default="true">
  Flag to indicate group SMS upload flow. When true, only 1 file upload is allowed per request.
</ParamField>

## Respuestas

<Accordion title="200 - Uploaded the file successfully">
  <ResponseField name="uploadedFiles" type="object" required />

  <ResponseField name="twilioMediaSids" type="string[]">
    Twilio media SIDs for group SMS (when isGroupSms=true)
  </ResponseField>

  ```json theme={null}
  {
    "uploadedFiles": {},
    "twilioMediaSids": [
      "MExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    ]
  }
  ```
</Accordion>

<Accordion title="400 - Bad Request">
  ```json theme={null}
  {}
  ```
</Accordion>

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

<Accordion title="413 - Payload Too Large">
  <ResponseField name="status" type="number" required default="413">
    HTTP Status code of the request Posibles valores: 400, 413, 415
  </ResponseField>

  <ResponseField name="message" type="string" required default="Failed to upload the files">
    Error message of the request
  </ResponseField>

  ```json theme={null}
  {
    "status": 413,
    "message": "Failed to upload the files"
  }
  ```
</Accordion>

<Accordion title="415 - Unsupported Media Type">
  <ResponseField name="status" type="number" required default="413">
    HTTP Status code of the request Posibles valores: 400, 413, 415
  </ResponseField>

  <ResponseField name="message" type="string" required default="Failed to upload the files">
    Error message of the request
  </ResponseField>

  ```json theme={null}
  {
    "status": 413,
    "message": "Failed to upload the files"
  }
  ```
</Accordion>

## Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST 'https://services.leadconnectorhq.com/conversations/messages/upload' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Version: 2021-07-28' \
    -H 'Content-Type: application/json' \
    -d '{
    "conversationId": "ve9EPM428h8vShlRW1KT",
    "contactId": "ve9EPM428h8vShlRW1KT",
    "locationId": "string",
    "attachmentUrls": [
      "string"
    ],
    "chatServiceSid": "ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "isGroupSms": "true"
  }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://services.leadconnectorhq.com/conversations/messages/upload', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.LEADWAY_TOKEN}`,
      Version: '2021-07-28',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({"conversationId": "ve9EPM428h8vShlRW1KT", "contactId": "ve9EPM428h8vShlRW1KT", "locationId": "string", "attachmentUrls": ["string"], "chatServiceSid": "ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "isGroupSms": "true"}),
  });
  const data = await response.json();
  ```

  ```python Python theme={null}
  import os, requests
  response = requests.request(
      'POST',
      'https://services.leadconnectorhq.com/conversations/messages/upload',
      headers={
          'Authorization': f"Bearer {os.environ['LEADWAY_TOKEN']}",
          'Version': '2021-07-28',
          'Content-Type': 'application/json',
      },
      json={"conversationId": "ve9EPM428h8vShlRW1KT", "contactId": "ve9EPM428h8vShlRW1KT", "locationId": "string", "attachmentUrls": ["string"], "chatServiceSid": "ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "isGroupSms": "true"},
  )
  data = response.json()
  ```

  ```php PHP theme={null}
  <?php
  $ch = curl_init('https://services.leadconnectorhq.com/conversations/messages/upload');
  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({'conversationId': 've9EPM428h8vShlRW1KT', 'contactId': 've9EPM428h8vShlRW1KT', 'locationId': 'string', 'attachmentUrls': ['string'], 'chatServiceSid': 'ISxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'isGroupSms': 'true'}),
  ]);
  $data = json_decode(curl_exec($ch), true);
  ```
</CodeGroup>
