{"id":16120,"library":"mg-api-node","title":"MyGeotab Node.js API Client","description":"This package, `mg-api-node`, functions as an unofficial Node.js client for programmatically interacting with the MyGeotab API. It offers capabilities for authentication, executing API calls (such as `Get`, `call`, and `multicall`), and managing request timeouts and session IDs to optimize repeated interactions. The latest stable version is 1.3.1. Its release cadence has been infrequent, with the most recent feature addition (request timeout functionality) in v1.3.0. While it once served as a direct Node.js interface for MyGeotab, this project is now officially deprecated. Users are strongly advised to transition to the `mg-api-js` package for ongoing support, new feature development, and improved maintainability.","status":"deprecated","version":"1.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/Geotab/mg-api-node","tags":["javascript","mygeotab","geotab","api","node","nodejs"],"install":[{"cmd":"npm install mg-api-node","lang":"bash","label":"npm"},{"cmd":"yarn add mg-api-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add mg-api-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This library uses CommonJS `require` syntax. Attempting to use ES module `import` will result in a runtime error.","wrong":"import API from 'mg-api-node';","symbol":"API","correct":"const API = require('mg-api-node');"},{"note":"The primary export is a class/constructor function named `API`, which must be instantiated with `new`.","wrong":"const api = mg_api_node(userName, password, database);","symbol":"API constructor","correct":"const api = new API(userName, password, database);"}],"quickstart":{"code":"const API = require('mg-api-node');\n\nconst userName = process.env.GEOTAB_USERNAME ?? 'YOUR_USERNAME';\nconst password = process.env.GEOTAB_PASSWORD ?? 'YOUR_PASSWORD';\nconst database = process.env.GEOTAB_DATABASE ?? 'YOUR_DATABASE'; // e.g., 'geotab-live'\n\nconst api = new API(userName, password, database);\n\napi.authenticate(function(err, data) {\n  if (err) {\n    console.error('Authentication Error:', err);\n    return;\n  }\n\n  console.log('Authenticated successfully. User:', data.userName);\n\n  api.call('Get', {\n    typeName: 'User',\n    search: {\n      name: data.userName\n    }\n  }, function(err, userData) {\n    if (err) {\n      console.error('API Call Error:', err);\n      return;\n    }\n    console.log('User Data:', userData);\n  });\n});","lang":"javascript","description":"Demonstrates basic authentication and a 'Get' API call to fetch user data using callback patterns."},"warnings":[{"fix":"Migrate to the `mg-api-js` package, which is the officially supported successor. `mg-api-js` offers modern features, active maintenance, and improved API patterns.","message":"This project has been officially deprecated. No further development, bug fixes, or security updates will be provided for `mg-api-node`.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"For new projects or migrations, consider `mg-api-js` which utilizes Promises/async-await. If stuck with `mg-api-node`, use utility libraries like `util.promisify` (Node.js built-in) or `async` to manage callbacks.","message":"The API exclusively uses Node.js callback patterns for asynchronous operations, which can lead to 'callback hell' in complex scenarios.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure `userName`, `password`, and `database` are correct. Verify user permissions within MyGeotab. The library includes reauthentication logic for `InvalidUserException` but correct initial setup is critical.","message":"Authentication failures, such as `InvalidUserException`, are common if credentials or the database name are incorrect or user permissions are insufficient.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"From v1.3.0 onwards, you can pass a timeout (milliseconds) and an optional timeout callback to `api.call()` and `api.multicall()` to prevent indefinite waits. For example: `api.call(..., 10000, () => console.log('Request timed out'))`.","message":"By default, HTTP requests have no explicit timeout, potentially causing long hangs on slow network connections or unresponsive API endpoints.","severity":"gotcha","affected_versions":"<1.3.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change your import statement to `const API = require('mg-api-node');` to correctly load the CommonJS module.","cause":"Attempting to use `mg-api-node` with ES module `import` syntax.","error":"TypeError: API is not a constructor"},{"fix":"Double-check your `userName`, `password`, and `database` parameters. Ensure the provided user has necessary API access within the MyGeotab system.","cause":"Authentication failed due to incorrect username, password, or database name, or insufficient user permissions.","error":"Error: InvalidUserException"},{"fix":"Implement robust error handling and retry mechanisms. Verify network connectivity and check MyGeotab's status page for outages. Ensure your environment's proxy settings are correct if applicable.","cause":"The connection to the MyGeotab API server was reset, possibly due to server-side issues, network instability, or an intermediate proxy.","error":"Error: read ECONNRESET"}],"ecosystem":"npm"}