Closed igorfltv closed 3 years ago
You can omit the API version, since at the moment there is only one - v1. You may have confused the bot API with the RetailCRM API
API version was omited. We get this error now. api object was created successfuly after passing url+token for the bot.
const wsData = api.getWebsocketData([MgBotApiClient.types().wsMessageNew]);
TypeError: MgBotApiClient.types is not a function
We are trying WS example from GitHub page.
Did you import the library as per the instructions? Everything works fine for me:
const MgBotApiClient = require('mg-api-client');
const api = new MgBotApiClient({
host: 'bot uri',
token: 'bot token'
}).client;
const wsData = api.getWebsocketData([MgBotApiClient.types().wsMessageNew]);
console.log(wsData);
Please note that with ES6 imports the code will be somewhat different:
import MgBotApiClient, { types } from 'mg-api-client';
const api = new MgBotApiClient({
host: 'bot uri',
token: 'bot token'
}).client;
const wsData = api.getWebsocketData([types().wsMessageNew]);
console.log(wsData);
Feel free to provide a full code sample if the problem persists. The environment details (Node version, library version, etc) may also help.
Getting Error after executing code from MD:
/////////////////////////////////////////////////// `const MgBotApiClient = require('mg-api-client')
const api = new MgBotApiClient({ host: 'xxxxxxx', token: 'xxxxxxx', apiVersion: 'v5' // optional }).client;
api.getUsers() .then(function (users) { console.log(users); }) .catch(function (e) { console.log(e); });`
/////////////////////////////////////// Error: const api = new MgBotApiClient this._client = new clients[currentVersion](new Request(options)); TypeError: clients[currentVersion] is not a constructor at new MgBotApiClient (C:\Users\igora\Git\RetailCRM\node_modules\mg-api-client\dist\index.js:875:22)
Environment: Win10, Node 14.17.4