NPM Package

The Infoplaza Platform NPM Package provides a JavaScript/Node.js client library for accessing the Infoplaza Platform APIs. It simplifies authentication, request handling, and error management for weather, geospatial, and mobility data.

GitHub Repository: https://github.com/infoplaza/infoplaza-lib-npmjs

Installation

Install the package using npm:

npm install @infoplaza/core

Or using yarn:

yarn add @infoplaza/core

Or using pnpm:

pnpm add @infoplaza/core

Requirements

  • Node.js 18.x or higher
  • An active Infoplaza Platform account with an API key

Usage

Basic Setup

Import and initialize the client with your API key:

import { Infoplaza } from '@infoplaza/core';

const client = new Infoplaza({
  apiKey: 'your-api-key-here'
});

// Example request
const { success, meta, data, error } = await client.v1.weather.forecast({
  lat: 52.02,
  lon: 5.16
});

Response Structure

All API methods return a standardized response object:

{
  success: true,
  meta: {
    rate: 1,
    rate_limit: 100,
    call: 1,
    call_limit: 10000,
    credits: 1,
    path: "/v1/weather/forecast",
    parameters: {
      lat: 52.02,
      lon: 5.16
    }
  },
  data: {
    // API-specific data
  }
}

Error Handling

The client library returns errors as part of the response object rather than throwing exceptions. Always check the success field and handle the error field when present.

Error Checking

import { Infoplaza } from '@infoplaza/core';

const client = new Infoplaza({
  apiKey: 'your-api-key-here'
});

const { success, meta, data, error } = await client.v1.weather.forecast({
  lat: 52.02,
  lon: 5.16
});

if (success) {
  console.log('Forecast data:', data);
} else {
  console.error('Error:', error.message);
}

Error Response Structure

When an error occurs, the response contains an error object:

{
  success: false,
  meta: {
    credits: 0,
    path: "/v1/weather/forecast"
  },
  error: {
    message: "Error message",
    path: "/v1/weather/forecast",
    missingParameters: ["lat", "lon"] // if applicable
  }
}