# Want to send File with Zoom Team Chat API in php framwork codeigniter 4

**URL:** <https://devforum.zoom.us/t/want-to-send-file-with-zoom-team-chat-api-in-php-framwork-codeigniter-4/107924>\
**Category:** Chat\
**Tags:** webhooks, api\
**Created:** [April 15, 2024, 5:27pm UTC](https://devforum.zoom.us/t/want-to-send-file-with-zoom-team-chat-api-in-php-framwork-codeigniter-4/107924 "2024-04-15T17:27:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![muhammad.irfan4894](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/muhammad.irfan4894/32/58693_2.png) [@muhammad.irfan4894](https://devforum.zoom.us/u/muhammad.irfan4894)\
**Post date:** [April 15, 2024, 5:27pm UTC](https://devforum.zoom.us/t/want-to-send-file-with-zoom-team-chat-api-in-php-framwork-codeigniter-4/107924/1 "2024-04-15T17:27:33Z")

</div>

I have this function in codeigniter 4

public function sendChatFile($file, $input)  
{  
// Check if file size exceeds the limits  
$maxImageSize = 16 \* 1024 \* 1024; // 16 MB  
$maxFileSize = 20 \* 1024 \* 1024; // 20 MB

```
    if ($file->getSize() > $maxImageSize && !in_array($file->getClientMediaType(), ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'])) {
        throw new Exception('File size exceeds the limit for images (16 MB)');
    } elseif ($file->getSize() > $maxFileSize) {
        throw new Exception('File size exceeds the limit for other file types (20 MB)');
    }
    $userId = $input['user_id'];
    $zoomFileApiUrl = "https://file.zoom.us/v2/chat/users/{$userId}/messages/files";

    $fileData = [];

    // Get the binary contents of the file
    $fileContents = file_get_contents($file->getPathname());

    // Add file data to the array
    $fileData = [
        [
            'name' => 'files',
            'contents' => $fileContents,
        ]
    ];

    if (!empty($input['to_channel_id'])) {
        $fileData[] = [
            'name' => 'to_channel',
            'contents' => $input['to_channel_id']
        ];
    } elseif (!empty($input['to_contact'])) {
        $fileData[] = [
            'name' => 'to_contact',
            'contents' => $input['to_contact']
        ];
    }
    if (!empty($input['reply_main_message_id'])) {
        $fileData[] = [
            'name' => 'reply_main_message_id',
            'contents' => $input['reply_main_message_id']
        ];
    }

    $client = new Client([
        'verify' => false,
    ]);

    try {
        $response = $client->post($zoomFileApiUrl, [
            'headers' => [
                'Authorization' => 'Bearer ' . $this->generateAccessToken(),
            ],
            'multipart' => $fileData,
        ]);

        $responseData = json_decode($response->getBody(), true);

        if (isset($responseData['code']) && $responseData['code'] === 1001) {
            throw new Exception('Unlicensed Zoom Id');
        }
      
        return $responseData;
    } catch (ClientException $e) {
        $responseBody = $e->getResponse()->getBody()->getContents();
        return $responseBody;
    } catch (Exception $e) {
        return $e->getMessage();
    }
}

```

its giving this error  
{“message”:“Invalid parameter: files.”,“code”:300}

where is mistake in my code

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [April 16, 2024, 1:46am UTC](https://devforum.zoom.us/t/want-to-send-file-with-zoom-team-chat-api-in-php-framwork-codeigniter-4/107924/2 "2024-04-16T01:46:28Z")

</div>

@muhammad.irfan4894 ,

Thank you for your post on the Zoom Developer Forum. To resolve this issue, I suggest utilizing a tool like postman to initiate the request. You can then either generate a code snippet from a successful request or analyze the request to identify what functions correctly.
