# External Contexts

## Overview

An external data source can be configured to be used as a dynamic data source outside the normal data you would be entering into DevHub or Google Sheets tied to DevHub projects.

## Options

* Support for endpoints that support the following formats:
  * JSON
  * XML
  * Custom API clients (requires integration)
* Passing of Site/Landing page IDs along on the external context URL
* Passing of URL parameters (full path, partial path, UTM parameters) along on the external context URL

## Example External Context File

Below is an example of a simple JSON External Context that contains a JSON list of products with a nested array of values for each product.

```javascript
[
  {
    "product_id": 12345,
    "product_name": "Product 1",
    "price": "$55.99",
    "features": ["Feature 1", "Feature 2"],
    "images": {
      "large": "https://example.com/large-image.jpg",
      "small": "https://example.com/small-image.jpg"
    }
  },
  {
    "product_id": 54321,
    "product_name": "Product 2",
    "price": "$19.99",
    "features": ["Feature 3", "Feature 4"],
    "images": {
      "large": "https://example.com/large-image-2.jpg",
      "small": "https://example.com/small-image-2.jpg"
    }
  },
  ...
]
```

## Configuration Settings

```javascript
"EXTERNAL_CONTEXTS": [
  {
    "url": "http://sb-whitelabel.s3.amazonaws.com/product_feed.json",
    "key": "product_feed",
    "type": "json",
    "cache_time": 3600
  },
  {
    "url": "http://sb-whitelabel.s3.amazonaws.com/pricing_feed.json",
    "key": "pricing_feed",
    "type": "json",
    "cache_time": 3600
  }
]
```

## Using data within templates and themes

Once configured, you will be able to access the External Context data from any Theme, HTML code module, or Template the same way you access other variables.

The `key` value on the External Context setting defines what variable that your data will be mapped to. In the case below, the `product_feed` variable was configured and the External Context was a list of products.

```javascript
{% for product in product_feed %}
<div class="product">
  <h3>{{ product.product_name }}</h3>
  <p>{{ product.price }}</p>
</div>
{% endfor %}
```


---

# 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.devhub.com/data-sources/external-contexts.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.
