Skip to content

Commit

Permalink
invokable (influxdata#3405)
Browse files Browse the repository at this point in the history
* invokable

* update filename and add alias

* fix: rename samples to api-invokable-scripts

Co-authored-by: Jason Stirnaman <[email protected]>
  • Loading branch information
kelseiv and jstirnaman authored Nov 16, 2021
1 parent 042f2f2 commit 5ffaff1
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 45 deletions.
20 changes: 10 additions & 10 deletions api-docs/cloud/ref.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9992,7 +9992,7 @@ paths:
description: Unexpected error
summary: List scripts
tags:
- Invocable Scripts
- Invokable Scripts
post:
operationId: PostScripts
requestBody:
Expand All @@ -10014,7 +10014,7 @@ paths:
description: Unexpected error
summary: Create a script
tags:
- Invocable Scripts
- Invokable Scripts
/api/v2/scripts/{scriptID}:
delete:
description: Deletes a script and all associated records.
Expand All @@ -10034,9 +10034,9 @@ paths:
description: Unexpected error
summary: Delete a script
tags:
- Invocable Scripts
- Invokable Scripts
get:
description: Uses script ID to retrieve details of an invocable script.
description: Uses script ID to retrieve details of an invokable script.
operationId: GetScriptsID
parameters:
- description: The script ID.
Expand All @@ -10057,10 +10057,10 @@ paths:
description: Unexpected error
summary: Retrieve a script
tags:
- Invocable Scripts
- Invokable Scripts
patch:
description: >
Updates properties (`name`, `description`, and `script`) of an invocable
Updates properties (`name`, `description`, and `script`) of an invokable
script.
operationId: PatchScriptsID
parameters:
Expand Down Expand Up @@ -10089,7 +10089,7 @@ paths:
description: Unexpected error
summary: Update a script
tags:
- Invocable Scripts
- Invokable Scripts
/api/v2/scripts/{scriptID}/invoke:
post:
description: >-
Expand Down Expand Up @@ -10119,7 +10119,7 @@ paths:
description: Unexpected error
summary: Invoke a script
tags:
- Invocable Scripts
- Invokable Scripts
/api/v2/setup:
get:
description: >-
Expand Down Expand Up @@ -12382,7 +12382,7 @@ tags:
- DBRPs
- Delete
- DemoDataBuckets
- Invocable Scripts
- Invokable Scripts
- Labels
- Limits
- NotificationEndpoints
Expand Down Expand Up @@ -12514,7 +12514,7 @@ x-tagGroups:
- DBRPs
- Delete
- DemoDataBuckets
- Invocable Scripts
- Invokable Scripts
- Labels
- Limits
- NotificationEndpoints
Expand Down
10 changes: 5 additions & 5 deletions api-docs/openapi/content/cloud/tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
- [Querystring authentication](#section/Authentication/QuerystringAuthentication)
<!-- ReDoc-Inject: <security-definitions> -->
x-traitTag: true
- name: Invocable Scripts
- name: Invokable Scripts
description: |
Manage and execute scripts as API endpoints in InfluxDB.
An API Invocable Script assigns your custom Flux script to a new InfluxDB API endpoint for your organization.
Invocable scripts let you execute your script as an HTTP request to the endpoint.
An API Invokable Script assigns your custom Flux script to a new InfluxDB API endpoint for your organization.
Invokable scripts let you execute your script as an HTTP request to the endpoint.
Invocable scripts accept parameters. Add parameter references in your script as `params.myparameter`.
Invokable scripts accept parameters. Add parameter references in your script as `params.myparameter`.
When you `invoke` your script, you send parameters as key-value pairs in the `params` object.
Then, InfluxDB executes your script with the key-value pairs as arguments, and returns the result.
For more information and examples, see [Invoke custom scripts](https://docs.influxdata.com/influxdb/cloud/api-guide/api-invocable-scripts).
For more information and examples, see [Invoke custom scripts](https://docs.influxdata.com/influxdb/cloud/api-guide/api-invokable-scripts).
- name: Quick start
x-traitTag: true
description: |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
---
title: Invoke custom scripts as API endpoints
seotitle: Use InfluxDB API-invocable scripts
seotitle: Use InfluxDB API-invokable scripts
description: >
Use API-invocable scripts to create your own InfluxDB API endpoints that execute custom scripts.
Use API-invokable scripts to create your own InfluxDB API endpoints that execute custom scripts.
weight: 101
menu:
influxdb_cloud:
name: Invoke custom scripts
parent: Develop with the API
influxdb/cloud/tags: [api guides]
aliases:
- /influxdb/cloud/api-guide/api-invocable-scripts/
influxdb/cloud/tags: [api guides]
---

Use API invocable scripts to create custom InfluxDB API endpoints that query, process, and shape data. API invocable scripts let you assign scripts to API endpoints and then execute them as standard REST operations in InfluxDB Cloud. Learn how to manage API invocable scripts and invoke them with runtime parameters.
Use API invokable scripts to create custom InfluxDB API endpoints that query, process, and shape data. API invokable scripts let you assign scripts to API endpoints and then execute them as standard REST operations in InfluxDB Cloud. Learn how to manage API invokable scripts and invoke them with runtime parameters.

Use the `/api/v2/scripts` InfluxDB API endpoint to:
- [Create a script](#create-an-invocable-script)
- [Create a script](#create-an-invokable-script)
- [Invoke a script](#invoke-a-script)
- [List scripts](#list-invocable-scripts)
- [Update a script](#update-an-invocable-script)
- [Delete a script](#delete-an-invocable-script)
- [List scripts](#list-invokable-scripts)
- [Update a script](#update-an-invokable-script)
- [Delete a script](#delete-an-invokable-script)

## Create an invocable script
To create an API-invocable script
## Create an invokable script
To create an API-invokable script
for your [organization](/influxdb/v2.0/reference/glossary/#organization),
send a request using the `POST` method to the `/api/v2/scripts` InfluxDB API endpoint.

Expand All @@ -44,7 +46,7 @@ JSON object with the following fields:
- **orgID**: your [InfluxDB organization ID](/influxdb/v2.0/organizations/view-orgs/#view-your-organization-id)

### Use parameters in a script
To create an invocable script that accepts parameters (variables),
To create an invokable script that accepts parameters (variables),
reference the parameters as properties of the `params` object, e.g. `params.firstparam`.
`params` is an InfluxDB object that defines runtime variables.
You provide values for `params` when you [invoke a script](#invoke-a-script).
Expand All @@ -58,11 +60,11 @@ If you don't provide a value for a referenced parameter, InfluxDB returns the fo

## Examples

### Create an invocable Flux script
### Create an invokable Flux script
The following example creates a new Flux script that references the `params.mybucket` parameter and returns the last point from the [bucket](/influxdb/v2.0/reference/glossary/#bucket).

```sh
{{% get-shared-text "api/v2.0/api-invocable-scripts/create-flux-script.sh" %}}
{{% get-shared-text "api/v2.0/api-invokable-scripts/create-flux-script.sh" %}}
```
Replace the following:
- *`INFLUX_API_TOKEN`*: your [InfluxDB API token](/influxdb/cloud/reference/glossary/#token)
Expand Down Expand Up @@ -99,7 +101,7 @@ Provide the following in your request:

### Request body
JSON object that contains a `params` object. In `params`, provide key-value pairs for parameters referenced in your script.
The [create](#create-an-invocable-script) example references the parameter `params.mybucket`.
The [create](#create-an-invokable-script) example references the parameter `params.mybucket`.
```json
"from(bucket: params.mybucket) \
|> range(start: -7d) \
Expand All @@ -109,7 +111,7 @@ The [create](#create-an-invocable-script) example references the parameter `para
The following example invokes the created script and passes "air_sensor" as the value for `params.mybucket`.

```sh
{{% get-shared-text "api/v2.0/api-invocable-scripts/invoke-post.sh" %}}
{{% get-shared-text "api/v2.0/api-invokable-scripts/invoke-post.sh" %}}
```

InfluxDB returns query results in [annotated CSV](/influxdb/cloud/reference/syntax/annotated-csv/) from the `air_sensor` bucket.
Expand All @@ -119,7 +121,7 @@ If the script references multiple parameters, provide values for all parameters.
To provide values for multiple parameters, send an object that contains a `params` object.
In `params`, add the parameter names as keys and define a value for each key.

The following **invocable script** object references four parameters:
The following **invokable script** object references four parameters:

```json
{
Expand Down Expand Up @@ -166,7 +168,7 @@ The following `params` object provides a key-value pair for each parameter refer

The following example uses the `/api/v2/scripts` InfluxDB API endpoint to create the script and invoke the new script ID with `params`.
```sh
{{% get-shared-text "api/v2.0/api-invocable-scripts/invoke_with_params.sh" %}}
{{% get-shared-text "api/v2.0/api-invokable-scripts/invoke_with_params.sh" %}}
```

InfluxDB returns points from `air_sensor` that have `temperature` or `humidity` fields.
Expand All @@ -183,7 +185,7 @@ Each unique `table` value represents a group.
,_result,1,2021-09-25T21:10:01.810564864Z,2021-10-25T21:10:01.810564864Z,2021-09-28T16:57:57Z,35.651929918691714,humidity,airSensors,TLM0202
```

## List invocable scripts
## List invokable scripts
To list scripts for an organization, send a request using the `GET` method to the `/api/v2/scripts` InfluxDB API endpoint.

Provide the following in your request:
Expand All @@ -199,7 +201,7 @@ Provide the following in your request:
- **offset**: (Optional) number to offset the pagination

```sh
{{% get-shared-text "api/v2.0/api-invocable-scripts/list.sh" %}}
{{% get-shared-text "api/v2.0/api-invokable-scripts/list.sh" %}}
```

To find a specific script for an organization, send a request using the `GET` method to the `/api/v2/scripts/SCRIPT_ID` InfluxDB API endpoint.
Expand All @@ -215,10 +217,10 @@ Provide the following in your request:
- **Accept**: application/json

```sh
{{% get-shared-text "api/v2.0/api-invocable-scripts/find.sh" %}}
{{% get-shared-text "api/v2.0/api-invokable-scripts/find.sh" %}}
```
## Update an invocable script
Use the API to replace the following properties of an invocable script:
## Update an invokable script
Use the API to replace the following properties of an invokable script:
- name
- description
- script
Expand All @@ -236,23 +238,23 @@ Provide the following in your request:
- **Accept**: application/json'

#### Request body
- A modified **invocable script** as a JSON object.
- A modified **invokable script** as a JSON object.

The following example finds an invocable script containing a numeric date range,
replaces the date with a new parameter, and updates the invocable script.
The following example finds an invokable script containing a numeric date range,
replaces the date with a new parameter, and updates the invokable script.

```sh
{{% get-shared-text "api/v2.0/api-invocable-scripts/update-flux-script.sh" %}}
{{% get-shared-text "api/v2.0/api-invokable-scripts/update-flux-script.sh" %}}
```
1. Use `GET /api/v2/scripts` to retrieve an object that contains a list of scripts.
2. With the scripts array, use [`jq`](https://stedolan.github.io/jq/) to find the first **invocable script** object that has a `script` property that contains a hard-coded numeric date range.
2. With the scripts array, use [`jq`](https://stedolan.github.io/jq/) to find the first **invokable script** object that has a `script` property that contains a hard-coded numeric date range.
3. Replace the hard-coded date range in the `script` property with a new `params.myrangestart` dynamic parameter and assign the object to a `new_script` variable.
4. Assign the script ID to a `script_id` variable.
5. Update the script by sending a request to `PATCH /api/v2/scripts/` with `$script_id` in the URL path and `$new_script` as data (in the request body).

InfluxDB returns the updated invocable script.
InfluxDB returns the updated invokable script.

## Delete an invocable script
## Delete an invokable script
To delete a script, send a request using the `DELETE` method to the `/api/v2/scripts/SCRIPT_ID` InfluxDB API endpoint.
Replace *`SCRIPT_ID`* with the ID of the script you want to update.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To find information about the latest Flux updates in InfluxDB Cloud, see [Flux r

### API invokable scripts

Use [API invokable scripts](/influxdb/cloud/api-guide/api-invocable-scripts/) to assign and execute a script through an API endpoint.
Use [API invokable scripts](/influxdb/cloud/api-guide/api-invokable-scripts/) to assign and execute a script through an API endpoint.

### New UI design

Expand Down

0 comments on commit 5ffaff1

Please sign in to comment.