# Getting started with Ruby

### Request code

To query the API, you can use any HTTP client of choice or any specialized GraphQL API Clients.

{% hint style="info" %}
Make sure to replace `<REPLACE_WITH_YOUR_KEY>` with your unique API key.
{% endhint %}

```ruby
require 'net/http'
require 'json'

API_KEY = "<REPLACE_WITH_YOUR_KEY>"
API_ENDPOINT = "https://api.craft.co/v1/query"
GRAPHQL_QUERY = "query getAlerts($first: Int!) { alerts(first: $first) { id dataset variable } }"

request_headers= { "Content-Type": "application/json", "x-craft-api-key": API_KEY }
request_data = {
    "query": GRAPHQL_QUERY,
    "variables": { "first": 3 }
}

response = Net::HTTP.post(URI(API_ENDPOINT), request_data.to_json, request_headers)
puts response.body
```

### Response

The above command returns JSON structured like this:

```javascript
{
  "data": {
    "alerts": [
      {
        "id": "8da58037-d0b9-8365-75b4-6754aed4e9b0",
        "dataset": "news",
        "variable": "news_article"
      },
      {
        "id": "8489a57b-7be9-0364-a95d-65ad84ed430a",
        "dataset": "news",
        "variable": "news_article"
      },
      {
        "id": "8489a57b-7be9-0364-a90d-65ad84ed430a",
        "dataset": "news",
        "variable": "news_article"
      },
      ...
    ]
  }
}
```

#### Read more

* [Querying Alerts API](/alerts-api/alerts-api-queries.md)
* [Alerts API Reference](/alerts-api/alerts-api-reference.md)
* [Query examples](/alerts-api/query-examples.md)


---

# 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.craft.co/alerts-api/getting-started/getting-started-with-ruby.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.
