I am new to Influx and as I follow the first tutorial to setup the NodeJS package @influxdata/influxdb3-client I get the error message:
TypeError: Channel credentials must be a ChannelCredentials object
at new ChannelImplementation (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@grpc/grpc-js/build/src/channel.js:28:19)
at new Client (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@grpc/grpc-js/build/src/client.js:65:36)
at new GrpcTransport (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@protobuf-ts/grpc-transport/build/commonjs/grpc-transport.js:11:23)
at Object.Mt [as queryTransport] (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@influxdata/influxdb3-client/dist/index.js:3:13151)
at new K (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@influxdata/influxdb3-client/dist/index.js:5:39921)
at new H (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@influxdata/influxdb3-client/dist/index.js:6:975)
at getItem (/Users/silvereletellier/dev/common-ground/api-admin/build/services/items.js:77:24)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async /Users/silvereletellier/dev/common-ground/api-admin/build/graphql/types/item.js:399:70
I create the client such as:
const client = new InfluxDBClient({ host: "https://eu-central-1-1.aws.cloud2.influxdata.com", token, database });
Any idea what I’m doing wrong?
I’m only following the tutorial with the right token etc
I tried different ways of initiating the package with connexion string, but same problem always.
Sorry for the delay, I tried to follow the same tutorial but did not run into the error that you did. Can you run the following code and see if that gives you any error. This is just to test authentication and setup client that you’re trying to do:
import {InfluxDBClient} from '@influxdata/influxdb3-client'
/**
* This example shows various ways to instantiate the client.
* Make sure the following environment variables are set: INFLUX_HOST, INFLUX_TOKEN
*/
async function main() {
let client: InfluxDBClient
// Create a new client using ClientOptions
client = new InfluxDBClient({
host: 'http://localhost:8086',
token: 'my-token',
})
await client.close()
// Create a new client using connection string
client = new InfluxDBClient('http://localhost:8086?token=my-token')
await client.close()
// Create a new client using environment variables
client = new InfluxDBClient()
await client.close()
}
main()
@suyash thank you for the code snippet but I still get the same issue:
/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@grpc/grpc-js/src/channel.ts:106
throw new TypeError(
^
TypeError: Channel credentials must be a ChannelCredentials object
at new ChannelImplementation (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@grpc/grpc-js/src/channel.ts:106:13)
at new Client (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@grpc/grpc-js/src/client.ts:158:30)
at new GrpcTransport (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@protobuf-ts/grpc-transport/build/commonjs/grpc-transport.js:11:23)
at Object.Mt [as queryTransport] (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@influxdata/influxdb3-client/src/impl/node/rpc.ts:11:10)
at new G (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@influxdata/influxdb3-client/src/impl/QueryApiImpl.ts:30:28)
at new K (/Users/silvereletellier/dev/common-ground/api-admin/node_modules/@influxdata/influxdb3-client/src/InfluxDBClient.ts:101:22)
at main (/Users/silvereletellier/dev/common-ground/api-admin/build/services/items.js:63:20)
at getItem (/Users/silvereletellier/dev/common-ground/api-admin/build/services/items.js:109:5)
at /Users/silvereletellier/dev/common-ground/api-admin/build/graphql/types/item.js:401:70
I tried the different client init methods and it always end up being the same error.
Hi @Silvere_Letellier can you please watch this video I recently made and follow along, it is using our v3 client library and shows you the steps for JavaScript using environment variable. https://youtu.be/iYWJZa0Q2As
I looked at your code snippet and noticed a few things, you’re not calling main() and it seems TypeScript code but these are not the issues. I was able to modify the code a bit and used two options to call the API and was connected to it without error, you can refer to the code below. It references environment variables but feel free to hardcode that into the .js file itself for test purpose.
import { InfluxDBClient, Point } from '@influxdata/influxdb3-client';
import dotenv from 'dotenv';
dotenv.config();
const host = process.env.INFLUXDB_HOST;
const token = process.env.INFLUXDB_API_TOKEN;
const database = process.env.INFLUXDB_BUCKET;
async function main() {
let client = InfluxDBClient;
// Create a new client using ClientOptions and env variables
client = new InfluxDBClient({
host,
token
});
console.log("Connected 1");
await client.close();
// Create a new client using connection string
client = new InfluxDBClient('HOST_URL?token=YOUR_TOKEN')
console.log("Connected 2");
await client.close()
}
main();