# PHP

In PHP, we'll be using the cURL library to send HTTP requests. Here's how you can use the book search API with PHP:

```php
<?php
function searchBook($query) {
    $url = 'https://api.promptjoy.com/api/mVMCpq';
    $apiKey = getenv('PROMPTJOY_API_KEY');
    
    $ch = curl_init();
    
    $postData = json_encode(array('query' => $query));
    
    $options = array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => array(
            'Content-Type: application/json',
            'x-api-key: ' . $apiKey
        ),
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $postData
    );
    
    curl_setopt_array($ch, $options);
    
    $response = curl_exec($ch);
    
    if (!$response) {
        die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
    }
    
    curl_close($ch);
    
    return json_decode($response, true);
}

$books = searchBook('your_search_term');
foreach ($books as $book) {
    echo "Title: " . $book['title'] . ", Author: " . $book['author'] . "\n";
}
?>

```

Replace `"your_search_term"` with the book you're searching for. This function will return an array of books.

Remember to handle exceptions and errors as needed in your actual application code.

Note: In this example, the API key is retrieved from environment variables for security reasons. Ensure that you've set the `PROMPTJOY_API_KEY` environment variable in your environment where this code will be executed.

\
\ <br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.promptjoy.com/api/api-usage/php.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
