# Email Extraction

In this example, we imagine we are a hotel that receives E-Mails from new customers who want to book a room. We want to extract the following information:

* Name of the guest (first and last name)
* Room preferences (Things like the guests preferred room location, room size, bed type etc.)
* Reservation number (Unique number that identifies this reservation)
* Stay details (Start date and end date of the stay)

Emails from guests could look the following way:

```
Dear Resort Aroma,

I would like to book a room from the 25th of April until the 30th of April.
When I looked through the website, I saw that you have rooms with a balcony. 
It would be wonderful if I could get such a room.  

Best,
Richard Fulmar
```

We first construct a corresponding [Shape](/extract/types/shape.md) to extract those fields:

```json
[
  {
    "name": "name",
    "type": "string",
    "description": "First and last name of the guest",
    "isArray": false
  },
  {
    "name": "room_preference",
    "type": "string",
    "description": "Guest's preferred room location, room size, bed type,...",
    "isArray": false
  },
  {
    "name": "reservation_number",
    "type": "number",
    "description": "Unique number that identifies this reservation",
    "isArray": false
  },
  {
    "name": "stay_details",
    "type": "string",
    "description": "Start date and end date of the stay. (MM-DD-YYYY). It's 2023",
    "isArray": false
  }
]
```

With the shape defined, we call the [`/extract-document`](/extract/endpoints/extract-document.md) endpoint with this shape and the table as the payload:

```bash
curl -X POST "https://waveline.ai/api/v1/extract-document" \
     -H "Content-Type: text/plain" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -d '{
          "fileName": "email134.txt",
          "contentType": "application/pdf",
          "base64Content": "JVBERi0xLjMKMSAwIG9iago8PC9UeXBlL0NhdGF...",
          "shape": YOUR_SHAPE
        }'
```

After some time, we query for the result of this job with the [job](/extract/endpoints/jobs-id.md) endpoint and find the following in the `result` field:

```json
{
  "name": "Richard Fulmar",
  "room_preference": "room with a balcony",
  "reservation_number": "unsure",
  "stay_details": "04-25-2023 to 04-30-2023"
}
```


---

# 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.waveline.ai/extract/examples/email-extraction.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.
