# API Usage

Using an API created with PromptJoy can be done in several programming languages. This guide will show you how to use the book search API (<https://preview.promptjoy.com/apis/mVMCpq>) we created earlier. For this API, we will be making a POST request to `https://api.promptjoy.com/api/mVMCpq` with a JSON payload containing the book search query.

The general API request looks like this:

**Endpoint:** <https://api.promptjoy.com/api/mVMCpq>&#x20;

**HTTP Method:** POST&#x20;

**Headers:**

* Content-Type: application/json
* x-api-key: sk-6200906b6fcc732e9265028f53d5d6f01575a162&#x20;

**Data/Payload:**

```json
{
  "query": "your_search_term"
}
```

\
Before diving into language-specific examples, let's talk about how to store your API key as an environment variable. Environment variables are a great way to keep sensitive information like API keys out of your source code. Here's how to do it:

1. **Windows:** Open a new Command Prompt window and type `setx PROMPTJOY_API_KEY "your_api_key"` then press Enter. Replace "your\_api\_key" with your actual API key.
2. **macOS/Linux:** Open a new Terminal window and type `export PROMPTJOY_API_KEY="your_api_key"` then press Enter. Replace "your\_api\_key" with your actual API key.

You can then access this environment variable in your code using the specific syntax for your programming language. This will be covered in each language-specific example.

Here's how you can make the request using `curl`, a command-line tool used for transferring data with URLs.

```bash
curl -X POST https://api.promptjoy.com/api/mVMCpq \
-H 'Content-Type: application/json' \
-H 'x-api-key: '$PROMPTJOY_API_KEY \
-d '{"query":"your_search_term"}'


```

\
Replace "your\_search\_term" with the book you're searching for. The response will be a JSON object containing the search results.

For language-specific examples, please navigate to the sections for Python, JavaScript, Ruby, Go, Java, and C#. Each section will provide a detailed guide on how to use the book search API in the respective language.<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.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.
