Notorious Penguin Magicians

    This package has been deprecated

    Author message:

    Development has been discontinued

    node-sageone

    0.2.0 • Public • Published

    node-sageone

    Node client library for sageOne (OAuth2 and request handling). For more details on the API see [https://developers.sageone.com].

    Installation

    npm install node-sageone --save

    Usage

    Here is an example using express

    var express = require('express');
    var router = express.Router();
    var request = require('request');
    var url = require('url');
    
    var qs = require('querystring');
    var sage = require('node-sage');
    
    /* SageOne data */
    var sageOptions = {
      clientId: 'xxx',
      clientSecret: 'xxx',
      signingSecret: 'TestSigningSecret',
      redirectUri: 'https://test.org/sage/callback', // see example router below
      userAgent: 'YOUR APP',
      saveTokens: saveTokens, // a method used to save the tokens (e.g. in a database) saveTokens(accessToken, refreshToken, callback)
    };
    
    /* Init sage */
    var Sage = sage(sageOptions);
    
    /* Example for saveTokens method */
    function saveTokens(accessToken, refreshToken, cb) {
      /* Do something async */
      cb(err)
    }
    
    router.get('/', function(req, res) {
      /* render the request link here as described in the documentation
    }
    
    router.get('/business', function(req, res) {
      /* get something from sage - token will be refreshed automatically if necessary */ 
        Sage.get(
          'https://api.sageone.com/core/v2/business',
          null,
          null,
          function(err, result, body) {
            var business = JSON.parse(body);
            res.render('sage', {
              title: 'SageOne Status',
              status: 'Verbunden mit ' + business.name,
            });
          }
        );
      }
    });
    
    /* Example router for auth callback */
    router.get('/callback', function(req, res) {
      var url_parts = url.parse(req.url, true);
      var query = url_parts.query;
    
      var code = query.code;
    
      Sage.getAccessToken(code, function (err, accessToken, refreshToken) {
        if (err) {
          console.log(err);
        }
        res.redirect('/sage');
      });
    });
    
    module.exports = router;
    

    Install

    npm i node-sageone

    DownloadsWeekly Downloads

    5

    Version

    0.2.0

    License

    LGPL-3.0

    Last publish

    Collaborators

    • jhs-s