Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Created September 10, 2016 10:58
Show Gist options
  • Save wmakeev/728bfa8154fce86c723c4a0406894cf6 to your computer and use it in GitHub Desktop.
Save wmakeev/728bfa8154fce86c723c4a0406894cf6 to your computer and use it in GitHub Desktop.
Moysklad JSON API #moysklad #api #json
'use strict'
require('dotenv').config()
const log = require('debug')('temp')
const nodeFetch = require('node-fetch')
const ENDPOINT = 'https://online.moysklad.ru/api/remap/1.1'
const { MOYSKLAD_LOGIN, MOYSKLAD_PASSWORD } = process.env
const auth = 'Basic ' + Buffer.from(`${MOYSKLAD_LOGIN}:${MOYSKLAD_PASSWORD}`, 'utf8')
.toString('base64')
log(auth)
nodeFetch(ENDPOINT + '/entity/product?limit=100', {
method: 'GET',
headers: { Authorization: auth }
})
.then(res => {
log('status:', res.status)
return res.json()
})
.then(res => {
// log(JSON.stringify(res, null, 2))
if (res.errors) {
return Promise.reject(new Error(res.errors[0].error))
} else {
return res.rows
}
})
.then(products => {
log(products.map(p => `${p.code} ${p.updated}`))
})
.catch(err => log(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment