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

# Queued Requests

> Check the status and response of queued API requests in the V2 WhatsApp API

## Overview

In V2, all API requests are processed through a queued system for improved reliability and performance. When you make any API request (send message, react, etc.), you receive an immediate response with a `queued_request_uuid`. Use this method to check the actual response of your queued request.

<Info>
  Learn more about the V2 queued request system in the [Queued Requests Documentation](/v2/api-reference/whatsapp/queued-requests).
</Info>

## Get Queued Request

Retrieve the status and response of a queued API request using its UUID.

<Tabs>
  <Tab title="Basic Usage" icon="code">
    ```php theme={null}
    use Hypersender\Hypersender;

    $response = Hypersender::whatsapp()
      ->getQueuedRequest(
          uuid: 'a0816120-7e37-4e8b-8cf3-92deb2cdc133',
      );

    // Check if the request is completed
    $data = $response->json();
    if ($data['response_status'] !== null) {
        // Request completed
        echo "Status: " . $data['response_status'];
        echo "Response: " . json_encode($data['response_body']);
    } else {
        // Still processing
        echo "Request is still being processed...";
    }
    ```
  </Tab>

  <Tab title="Parameters" icon="sliders">
    | Parameter | Type   | Required | Description                                |
    | --------- | ------ | -------- | ------------------------------------------ |
    | uuid      | string | yes      | The UUID of the queued request to retrieve |
  </Tab>

  <Tab title="Response" icon="brackets-curly">
    ```json theme={null}
    {
      "uuid": "a0816120-7e37-4e8b-8cf3-92deb2cdc133",
      "request": {
        "chatId": "111111111111@c.us",
        "text": "Hello world!"
      },
      "response_status": 200,
      "response_body": {
        "message_id": "AAAAAA0000BBBBB00CCCCCC"
      },
      "response_header": {}
    }
    ```
  </Tab>
</Tabs>

<Note>
  The `response_status`, `response_body`, and `response_header` will be `null` while the request is still being processed.
</Note>

## Response Fields

| Field             | Type            | Description                                                                                                     |
| ----------------- | --------------- | --------------------------------------------------------------------------------------------------------------- |
| `uuid`            | string          | The unique identifier for this queued request                                                                   |
| `request`         | object          | The original request payload you submitted                                                                      |
| `response_status` | integer \| null | HTTP status code of the processed request. `null` while still processing                                        |
| `response_body`   | object \| null  | The actual API response. Contains message details on success, error details on failure. `null` while processing |
| `response_header` | object \| null  | Response headers from the processed request. `null` while processing                                            |

## Polling Example

If you need to wait for a request to complete, you can implement polling with exponential backoff:

```php theme={null}
use Hypersender\Hypersender;

function waitForCompletion(string $uuid, int $maxAttempts = 10): array
{
    $attempt = 0;

    while ($attempt < $maxAttempts) {
        $response = Hypersender::whatsapp()
            ->getQueuedRequest(uuid: $uuid);

        $data = $response->json();

        if ($data['response_status'] !== null) {
            return $data; // Request completed
        }

        // Exponential backoff: 100ms, 200ms, 400ms, 800ms...
        usleep(100000 * pow(2, $attempt));
        $attempt++;
    }

    throw new \Exception('Request did not complete in time');
}

// Usage
$sendResponse = Hypersender::whatsapp()
    ->safeSendTextMessage(
        chat_id: '20123456789@c.us',
        text: 'Hello!',
    );

$uuid = $sendResponse->json()['queued_request_uuid'];
$result = waitForCompletion($uuid);

if ($result['response_status'] === 200) {
    echo "Message sent! ID: " . $result['response_body']['message_id'];
} else {
    echo "Failed with status: " . $result['response_status'];
}
```

<Tip>
  For production applications, consider using webhooks instead of polling to receive real-time notifications when messages are sent, delivered, or fail.
</Tip>
