Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to call B24 from external Library #6

Open
lamnot opened this issue Apr 11, 2018 · 0 comments
Open

Unable to call B24 from external Library #6

lamnot opened this issue Apr 11, 2018 · 0 comments

Comments

@lamnot
Copy link

lamnot commented Apr 11, 2018

Hi baws,
I have tried everything i can but can't get to call the methods from inside my libray, kindly have a look

const express = require('express');
const b24 = require('b24');
const app = express();
var ethers = require('ethers');

// Connect to the network
var providers = require('ethers').providers;
var network = providers.networks.ropsten;
// Connect to a local Parity instance
var provider = new providers.JsonRpcProvider('http://localhost:8545', network);

const bitrix24 = new b24.Bitrix24({
config: {
mode: "api",
host: "xxxxxxxxx",
client_id : "local.cccccccccccccccccccccccccc",
client_secret : "dddddddddddddddddddddddddddd",
redirect_uri : "http://localhost:3000/callback"
},
methods: {
async saveToken(data){
//Save token to database
},
async retriveToken(){
//Retrive token from database
return {
access_token: "youraccesstoken",
refresh_token: "yourrefreshtoken"
}
}
}
})

// Get notified when a contract event is logged
var eventTopic = '0xf538d33cf0aeab2f474d1ec307854fed7e411946cb8e4239785e4f7d2c424047';
provider.on([ eventTopic ], function(log) {
console.log('Event Log');
console.log(log);
var Call = log;

// Bitrix auth
app.get('/auth', (req, res) => {
res.redirect(bitrix24.auth.authorization_uri);
});

// Callback service parsing the authorization token and asking for the access token
app.get('/callback', async (req, res) => {
try{
const code = req.query.code;
const result = await bitrix24.auth.getToken(code);
return res.json(result);
}catch(err){
console.log(err)
return res.status(500).json({message:"Authentication Failed"});
}
});

// if (Call == "xxxxxxx") {

app.get('/allUser', async (req, res) => {
try{
const result = await bitrix24.callMethod('user.add', {"EMAIL": "test@xxxxx.net"});
return res.json(result);
}catch(err){
console.log(err)
return res.status(222).json({"result":222});
}
});
});

app.listen(3000, () => {
console.log('Server started on port 3000');
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant