1.0.1 • Published 4 years ago

@brielov/mercadolibre v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

MercadoLibre

MercadoLibre SDK for Node.js (That doesn't suck)

Install

npm install @brielov/mercadolibre

Or

yarn add @brielov/mercadolibre

Use

require:

import { Meli } from '@brielov/mercadolibre'

Or

const { Meli } = require('@brielov/mercadolibre');

Constructor:

const client_id = process.env.MELI_CLIENT_ID;
const client_secret = process.env.MELI_CLIENT_SECRET;
const redirect_uri = process.env.MELI_REDIRECT_URI;

const meli = new Meli({
	client_id: number,
	client_secret: string,
	redirect_uri: string,
	access_token: string,
	refresh_token: string,
});

authorize

const credentials = await meli.authorize(code: string);

refreshAccessToken

const credentials = await meli.refreshAccessToken();

Request methods

get

const response = await meli.get(path: string, params?: object);
Examples
//Get categories from mercado libre argentina
const categories = await meli.get('sites/MLA/categories');

[
	{ id: 'MLA5725', name: 'Accesorios para Vehículos' },
	{ id: 'MLA1071', name: 'Animales y Mascotas' },
	{ id: 'MLA1367', name: 'Antigüedades' },
	{ id: 'MLA1368', name: 'Arte y Artesanías' },
	{ id: 'MLA1743', name: 'Autos, Motos y Otros' },
	{ id: 'MLA1384', name: 'Bebés' },
]

//Get users with ids 145925943 and 145925951
const users = await meli.get('users', {
    ids: [145925943, 145925951]
});

[
	{
		id: 145925943,
		nickname: 'TETE2780570',
		registration_date: '2013-09-17T14:20:30.000-04:00',
		country_id: 'AR',
		address: { state: 'AR-C', city: 'Palermo' },
		user_type: 'normal',
		tags: [ 'normal', 'test_user', 'user_info_verified' ],
		logo: null,
		points: 100,
		site_id: 'MLA',
		permalink: 'http://perfil.mercadolibre.com.ar/TETE2780570',
		seller_reputation:
		 { level_id: null,
		   power_seller_status: null,
		   transactions: [Object] },
		buyer_reputation: { tags: [] },
		status: { site_status: 'deactive' }
	},
	{
		id: 145925951,
		nickname: 'TETE1341752',
		registration_date: '2013-09-17T14:20:43.000-04:00',
		country_id: 'AR',
		address: { state: 'AR-C', city: 'Palermo' },
		user_type: 'normal',
		tags: [ 'normal', 'test_user', 'user_info_verified' ],
		logo: null,
		points: 100,
		site_id: 'MLA',
		permalink: 'http://perfil.mercadolibre.com.ar/TETE1341752',
		seller_reputation:
		 { level_id: null,
		   power_seller_status: null,
		   transactions: [Object] },
		buyer_reputation: { tags: [] },
		status: { site_status: 'deactive' }
	}
]

post

const response = await meli.post(path: string, body?: object, params?: object);

upload (post with multipart)

const response = await meli.upload(path: string, body: File | Blob | Buffer, params?: object);

put

const response = await meli.put(path: string, body?: object, params?: object);

delete

const response = await meli.delete(path: string, params?: object);

Details necessary

The object passed in the params parameter in functions get, post, put and delete is automatically converted to a query string.

Example:

meli.get('/users/', { ids: [77169310, 1231233] });

The request is GET ​​to the following address:

https://api.mercadolibre.com/users/?ids=77169310,1231233
1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago