> For the complete documentation index, see [llms.txt](https://docs.redivis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redivis.com/api/client-libraries/redivis-js/examples.md).

# Examples

### Reading table data

```javascript
import * as redivis from 'redivis'

const rows = await redivis
  .organization('demo')
  .dataset('nyt covid us cases deaths')
  .table('covid_us states')
  // max_results and variables parameters are optional
  // If not specified will return all records and variables
  .listRows({ max_results: 100, variables: ['state', 'cases'] }) 
```

### **Execute a query**

```javascript
// Execute a query against fully qualified tables on Redivis. 
// Dataset at https://redivis.com/Demo/datasets/1921

import * as redivis from 'redivis'

const rows = await redivis
  .query(`
    SELECT * 
    FROM demo.nyt_covid_us_cases_deaths.covid_us_counties 
    WHERE state = 'California'
  `)
  .listRows()
```

### **Execute a scoped query**

```javascript
// Perform a query scoped to the "nyt covid us cases deaths" dataset. 
// Table at https://redivis.com/Demo/datasets/1921/tables

// We don't need to include fully-qualified table names 
//    if we scope our query to the appropriate dataset or workflow

import * as redivis from 'redivis'

const rows = await redivis
  .organization('demo')
  .dataset('nyt covid us cases_deaths')
  .query(`
    SELECT * 
    FROM covid_us_states
    WHERE state = 'California'
  `)
  .listRows()

```

### Embedding in an HTML page

```html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Redivis Query Example</title>
</head>
<body>
  <script type="module">
    import * as redivis from 'https://cdn.jsdelivr.net/npm/redivis/+esm';

    const rows = await redivis
      .query(`
        SELECT *
        FROM demo.nyt_covid_us_cases_deaths.covid_us_counties
        WHERE state = 'California'
      `)
      .listRows();

    console.log(rows);
  </script>
</body>
</html>
```

### Authorization

{% hint style="info" %}
Authorization will happen automatically when querying data, but you can force an authorization flow via this method.
{% endhint %}

```javascript
import * as redivis from 'redivis'

redivis.authorize()
  .then(() => {
    // Authorization was successful!
  })
  .catch((e) => {
    // Authorization failed :/
  })
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.redivis.com/api/client-libraries/redivis-js/examples.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
