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

# Send Messages and Read Tenant Logs

> Send text and media messages and read tenant message logs through the Sinjapp Business Tenant API using the messages.send and messages.read scopes.

## Send A Text Message

Requires `messages.send` scope. Use either `sender_phone` or `sender_number_id`.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://{tenant}.sinjapp.org/api/v1/messages" \
    -H "X-Api-Key: {tenant_api_key}" \
    -H "Accept: application/json" \
    -H "Content-Type: application/json" \
    -d '{
      "sender_phone": "{sender_phone}",
      "to_phone": "{recipient_phone}",
      "type": "text",
      "content": "Hello from Sinjapp Business"
    }'
  ```

  ```js JavaScript theme={null}
  const response = await fetch('https://{tenant}.sinjapp.org/api/v1/messages', {
    method: 'POST',
    headers: {
      'X-Api-Key': tenantApiKey,
      'Accept': 'application/json',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      sender_phone: senderPhone,
      to_phone: recipientPhone,
      type: 'text',
      content: 'Hello from Sinjapp Business',
    }),
  })

  const message = await response.json()
  ```

  ```php PHP theme={null}
  <?php

  $response = file_get_contents('https://{tenant}.sinjapp.org/api/v1/messages', false, stream_context_create([
      'http' => [
          'method' => 'POST',
          'header' => [
              'X-Api-Key: ' . $tenantApiKey,
              'Accept: application/json',
              'Content-Type: application/json',
          ],
          'content' => json_encode([
              'sender_phone' => $senderPhone,
              'to_phone' => $recipientPhone,
              'type' => 'text',
              'content' => 'Hello from Sinjapp Business',
          ]),
          'timeout' => 30,
      ],
  ]));

  $message = json_decode($response, true);
  ```

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

  response = requests.post(
      "https://{tenant}.sinjapp.org/api/v1/messages",
      headers={
          "X-Api-Key": tenant_api_key,
          "Accept": "application/json",
          "Content-Type": "application/json",
      },
      json={
          "sender_phone": sender_phone,
          "to_phone": recipient_phone,
          "type": "text",
          "content": "Hello from Sinjapp Business",
      },
      timeout=30,
  )

  message = response.json()
  ```
</CodeGroup>

## Send Media

For images, documents, and voice files, use `multipart/form-data` with the `media` field. Supported message types are `image`, `voice`, and `document`.

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://{tenant}.sinjapp.org/api/v1/messages" \
    -H "X-Api-Key: {tenant_api_key}" \
    -H "Accept: application/json" \
    -F "sender_phone={sender_phone}" \
    -F "to_phone={recipient_phone}" \
    -F "type=image" \
    -F "content=Image caption" \
    -F "media=@/path/to/image.png"
  ```

  ```js JavaScript theme={null}
  const formData = new FormData()
  formData.append('sender_phone', senderPhone)
  formData.append('to_phone', recipientPhone)
  formData.append('type', 'image')
  formData.append('content', 'Image caption')
  formData.append('media', file)

  const response = await fetch('https://{tenant}.sinjapp.org/api/v1/messages', {
    method: 'POST',
    headers: {
      'X-Api-Key': tenantApiKey,
      'Accept': 'application/json',
    },
    body: formData,
  })

  const message = await response.json()
  ```

  ```php PHP theme={null}
  <?php

  $client = curl_init('https://{tenant}.sinjapp.org/api/v1/messages');

  curl_setopt_array($client, [
      CURLOPT_POST => true,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_HTTPHEADER => [
          'X-Api-Key: ' . $tenantApiKey,
          'Accept: application/json',
      ],
      CURLOPT_POSTFIELDS => [
          'sender_phone' => $senderPhone,
          'to_phone' => $recipientPhone,
          'type' => 'image',
          'content' => 'Image caption',
          'media' => new CURLFile('/path/to/image.png'),
      ],
  ]);

  $message = json_decode(curl_exec($client), true);
  curl_close($client);
  ```

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

  with open("/path/to/image.png", "rb") as media:
      response = requests.post(
          "https://{tenant}.sinjapp.org/api/v1/messages",
          headers={
              "X-Api-Key": tenant_api_key,
              "Accept": "application/json",
          },
          data={
              "sender_phone": sender_phone,
              "to_phone": recipient_phone,
              "type": "image",
              "content": "Image caption",
          },
          files={"media": media},
          timeout=30,
      )

  message = response.json()
  ```
</CodeGroup>

## Read Message Logs

Requires `messages.read` scope.

<CodeGroup>
  ```bash cURL theme={null}
  curl "https://{tenant}.sinjapp.org/api/v1/messages" \
    -H "X-Api-Key: {tenant_api_key}" \
    -H "Accept: application/json"
  ```

  ```js JavaScript theme={null}
  const response = await fetch('https://{tenant}.sinjapp.org/api/v1/messages', {
    headers: {
      'X-Api-Key': tenantApiKey,
      'Accept': 'application/json',
    },
  })

  const messages = await response.json()
  ```

  ```php PHP theme={null}
  <?php

  $response = file_get_contents('https://{tenant}.sinjapp.org/api/v1/messages', false, stream_context_create([
      'http' => [
          'method' => 'GET',
          'header' => [
              'X-Api-Key: ' . $tenantApiKey,
              'Accept: application/json',
          ],
          'timeout' => 30,
      ],
  ]));

  $messages = json_decode($response, true);
  ```

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

  response = requests.get(
      "https://{tenant}.sinjapp.org/api/v1/messages",
      headers={
          "X-Api-Key": tenant_api_key,
          "Accept": "application/json",
      },
      timeout=30,
  )

  messages = response.json()
  ```
</CodeGroup>
