Created
September 10, 2016 10:58
-
-
Save wmakeev/728bfa8154fce86c723c4a0406894cf6 to your computer and use it in GitHub Desktop.
Moysklad JSON API #moysklad #api #json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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