Typescript

Instructions on how to install and use the MetaCopier API Client package

Create API Key from metacopier.io

To generate yourself an API Key please navigate to metacopier.io > Your Projects > (Choose a project) > API Keys

Note: Please do not share your API Key to people whom you don't trust.

Package Information

The package is based on the following OpenAPI configuration:

Angular

Install with npm

Execute the following command to install the api package to your project:

npm i ng-metacopier-api

Or you can manually download it directly from npmjs.com

Example

App Module

Import both MetaCopierAPIApiModule and HttpClientModule

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { DashboardComponent } from './dashboard/dashboard.component';
import { HttpClientModule } from '@angular/common/http';
import { RouterOutlet } from '@angular/router';
import { MetaCopierAPIApiModule } from 'ng-metacopier-api';

@NgModule({
  declarations: [AppComponent, DashboardComponent],
  imports: [
    RouterOutlet,
    BrowserModule,
    AppRoutingModule,
    MetaCopierAPIApiModule,
    HttpClientModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Component

import { Component, OnInit } from '@angular/core';
import {
  MetaCopierAPIConfigurationParameters,
  AccountAPIService,
  MetaCopierAPIConfiguration,
  AccountDTO,
} from 'ng-metacopier-api';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrl: './dashboard.component.scss',
})
export class DashboardComponent implements OnInit {
  private _paramsConfig: MetaCopierAPIConfigurationParameters = {
    apiKeys: {
      'X-API-KEY': 'YOUR_API_KEY', // Replace this value with your API key
    },
    basePath: 'https://api.metacopier.io',
  };

  constructor(private _accountAPIService: AccountAPIService) {}

  ngOnInit(): void {
    this._accountAPIService.configuration = new MetaCopierAPIConfiguration(
      this._paramsConfig
    );

    this._accountAPIService.getAccounts().subscribe({
      next: (data: AccountDTO[]) => {
        console.log(data);
      },
      error: (e: Error) => {
        console.error(e);
      },
    });
  }
}

Generate your own package

With the following command, you can generate your own package for the metacopier api:

Be sure that you have installed the OpenAPI Generator. See Generation page for more information.

openapi-generator-cli generate -i https://api.metacopier.io/rest/api/documentation/v3/api-docs -g typescript-angular

For more information regarding the Open API generator, please visit their offical page:

React

Install with npm

npm i js-metacopier-api

Or you can manually download it directly from npmjs.com

Example

You need to have the axios package installed too

App

import "./App.css";
import axios from "axios";
import { useEffect, useState } from "react";
import { AccountAPIApi, Configuration } from "js-metacopier-api";

function App() {
  const [data, setData] = useState<any>(null);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    const apiConfig = new Configuration({
      apiKey: "YOUR_API_KEY", // Replace this value with your API key
      basePath: "https://api.metacopier.io",
    });

    const fetchData = async () => {
      const api = new AccountAPIApi(apiConfig, apiConfig.basePath, axios);

      try {
        const response = await api.getAccounts();
        setData(response.data);
      } catch (err: any) {
        setError(err.message);
      }
    };

    fetchData();
  }, []);

  return (
    <div>
      <h1>React App with Generated API Client</h1>
      {error ? (
        <p>Error: {error}</p>
      ) : (
        <pre>{JSON.stringify(data, null, 2)}</pre>
      )}
    </div>
  );
}

export default App;

Generate your own package

With the following command, you can generate your own package for the metacopier api:

Be sure that you have installed the OpenAPI Generator. See Generation page for more information.

openapi-generator-cli generate -i https://api.metacopier.io/rest/api/documentation/v3/api-docs -g typescript-axios

For more information regarding the Open API generator, please visit their offical page:

What endpoints can I call?

To check all available endpoints see either of the two pages:

Readme.ioSwagger

Last updated

Was this helpful?