Versies vergeleken

Uitleg

  • Deze regel is toegevoegd.
  • Deze regel is verwijderd.
  • Opmaak is veranderd.

Introduction

Influxdb uses API token for secure interaction with the database.

...

The first token listed above (influxdb's Token) is he setup token and grants access to all resources in the database.

Queries

The following example shows how to create a new bucket using one of these tokens:

Code Block
#!/bin/sh
INFLUX_ORG_ID="4a43da86fa150161"
INFLUX_TOKEN="UQ5ayNlN33QK-c6G6fOBU7lKVVynpEF_TijIGxNuhWkSs75TMjnv4yucHjOmDXhSMJmxZzYe9xjQI1MDlEAPuw=="

curl --request POST "http://localhost:8086/api/v2/buckets"   
--header "Authorization: Token ${INFLUX_TOKEN}"   
--header "Content-type: application/json"   
--data '{
    "orgID": "'"${INFLUX_ORG_ID}"'",
    "name": "iot-bucket",
    "retentionRules": [
      {
        "type": "expire",
        "everySeconds": 86400,
        "shardGroupDurationSeconds": 0
      }
    ]
  }'


We can also use the version 1 APIs with a username and password if required.

First create a v1 user and assign read an write permissions for a particular bucket:

influx v1 auth create -o EST --username influxv1 --password influxv1  --read-bucket 272626d8c766fd27 --write-bucket 272626d8c766fd27 -t UQ5ayNlN33QK-c6G6fOBU7lKVVynpEF_TijIGxNuhWkSs75TMjnv4yucHjOmDXhSMJmxZzYe9xjQI1MDlEAPuw==

We can then write to the bucket like this:

Code Block
curl -iv -XPOST "http://localhost:8086/write?db=ts-bucket&precision=ns" \
  --user "influxv1":"influxv1" 
  --header "Content-Type: text/plain; charset=utf-8" \
  --header "Accept: application/json" \
  --data-binary '
    airSensors,sensor_id=TLM0201 temperature=73.97038159354763,humidity=35.23103248356096,co=0.48445310567793615
    airSensors,sensor_id=TLM0202 temperature=75.30007505999716,humidity=35.651929918691714,co=0.5141876544505826
    '


and read the data back like this:

Code Block
curl -v --get "http://localhost:8086/query" \
  --user "influxv1":"influxv1" \
  --data-urlencode "db=ts-bucket" \
  --data-urlencode "q=SELECT * FROM airSensors WHERE \"time\" > now()-1h"

Note: If we are using a measurement with special characters like SubNetwork=CountryNN,MeContext=MEC-Gbg-1,ManagedElement=RNC-Gbg-1ManagedElement=RNC-Gbg-1,ENodeBFunction=1 we need to surrounds the measurement name in quotes : "q=SELECT * FROM \"SubNetwork=CountryNN,MeContext=MEC-Gbg-1,ManagedElement=RNC-Gbg-1ManagedElement=RNC-Gbg-1,ENodeBFunction=1\""

Note: JWT authorization is no longer supported in Influxdb v. 2

Links

Manage security and authorization

Manage API tokens

API Quick Start

InfluxDB OSS API Service

Write data with the InfluxDB API V1