> For the complete documentation index, see [llms.txt](https://docs.taco.build/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.taco.build/for-developers/conditions/json-endpoint-conditions/jsonapicondition.md).

# JsonApiCondition

The `JsonApiCondition` works by sending an HTTPS GET request to a specified JSON API endpoint, extracting relevant data from the response using a [`JSONPath`](https://goessner.net/articles/JsonPath/) query, and then comparing the extracted value against an expected result.

It is composed of the following properties:

* `endpoint`: the HTTPS URI for the JSON API endpoint that will be queried, e.g.`https://api.example.com/user/status`
* `parameters`*(Optional)*: a key-value mapping of parameter names and values to pass as part of the HTTPS GET request. These parameters will be appended to the URL as query string parameters.
* `query`*(Optional)*: a `JSONPath` query used to extract specific data from the JSON response.
* [`authorizationToken`](/for-developers/conditions/json-endpoint-conditions.md#authorization) (Optional): A token that will be included in the HTTPS `Authorization` header. It enables the use of endpoints that require OAuth/JWT authorization.
* `authorizationType` (Optional): If an `authorizationToken` is specified, the type specifies the request header information to specify. Can be `Bearer`, `Basic`, or `X-API-Key`.
* [`returnValueTest`](/for-developers/conditions.md#returnvaluetest): the test to validate the value extracted by the JSONPath query.

**Error Handling**

* If the HTTPS response does not return a status code of `200`, the condition will fail automatically, and access will be denied.
* If the `JSONPath` query is provided but cannot properly extract the desired value, the condition will fail, resulting in access being denied.
* If an invalid `authorizationToken` is provided, the call to the API will fail, causing the condition to fail and access to be denied.

## **Use Cases**

Any JSON REST API endpoint including:

* Social media APIs e.g. Twitter, Facebook
* Communication application APIs e.g. Discord, Telegram
* Oracle endpoints e.g. prices, weather etc.

## Example

```typescript
import { conditions } from '@nucypher/taco';

const firstBookPrice = new conditions.base.jsonApi.JsonApiCondition({
  endpoint: 'https://api.books.com/data',
  parameters: {
    'name': 'It'
  },
  query: '$.store.book[0].price',
  authorizationToken: ":authToken",
  returnValueTest: {
    comparator: "==",
    value: 1
  },
});
```

The condition would be satisfied if the API endpoint returned something analogous to the following:

<pre class="language-json"><code class="lang-json"><strong>{  
</strong>  "store":{
    "book":[
      {
        "name": "It",
        "author": "Stephen King",
        "price": 1
      }
    ]
  }
}
</code></pre>

## Development References

* Client-side:
  * <https://github.com/nucypher/taco-web/pull/550>
  * <https://github.com/nucypher/taco-web/pull/561>
  * <https://github.com/nucypher/taco-web/pull/599>
* Server-side:
  * <https://github.com/nucypher/nucypher/pull/3511>
  * <https://github.com/nucypher/nucypher/pull/3560>


---

# 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 following URL with the `ask` and `goal` query parameters:

```
GET https://docs.taco.build/for-developers/conditions/json-endpoint-conditions/jsonapicondition.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
