Unable to write data to InfluxDB 2 using Influx API call

Hi,

I’m trying to insert data to influxdb2 using API.

I tried but facing some error.

Can you help where I’m doing wrong.

Hi @debnath,
Nice to meet you digitally. I took a look and managed to get an example working with some of your data. I have attached an export of my Postman collection:

{
	"info": {
		"_postman_id": "8dbb3787-d3e2-444b-98a7-d6edb794f015",
		"name": "Influx",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "List Buckets",
			"protocolProfileBehavior": {
				"disableBodyPruning": true
			},
			"request": {
				"method": "GET",
				"header": [
					{
						"key": "Authorization",
						"value": "Token mytoken"
					}
				],
				"body": {
					"mode": "raw",
					"raw": ""
				},
				"url": {
					"raw": "localhost:8086/api/v2/buckets",
					"host": [
						"localhost"
					],
					"port": "8086",
					"path": [
						"api",
						"v2",
						"buckets"
					]
				}
			},
			"response": []
		},
		{
			"name": "Write Example",
			"request": {
				"method": "POST",
				"header": [
					{
						"key": "Authorization",
						"value": "Token mytoken"
					}
				],
				"body": {
					"mode": "raw",
					"raw": "sensor_data_665,assetId=TLM0201 originalTime=1633339479,featureName=\"TST\",sensorID=\"SENSOR555\" 1633339479"
				},
				"url": {
					"raw": "localhost:8086/api/v2/write?bucket=sensors&precision=s&org=ProjectOWL",
					"host": [
						"localhost"
					],
					"port": "8086",
					"path": [
						"api",
						"v2",
						"write"
					],
					"query": [
						{
							"key": "bucket",
							"value": "sensors"
						},
						{
							"key": "precision",
							"value": "s"
						},
						{
							"key": "org",
							"value": "ProjectOWL"
						}
					]
				}
			},
			"response": []
		}
	]
}

I believe the main reason why current tests are failing is due to line protocol format:
Based on the docs your line protocol structure should look like this:

measurement,<tag>=value,<tag>=value <field>=value,<field>=value <time-stamp>

Notice in line protocol apart from <measurement> spaces are important for defining separation between tags and fields.

@Jay_Clifford Thank you so much.

1 Like

no worries at all :slight_smile: