- Notifications
You must be signed in to change notification settings - Fork12
Backlog API version 2 client for browser and node.
NotificationsYou must be signed in to change notification settings
nulab/backlog-js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Backlog API version 2 client for browser and node.
Please check out theNulab Backlog API page.
npm:
$ npm install --save backlog-js
Append your "API Key" or "OAuth2 Access Token" to requests to the API to return data.
import'isomorphic-form-data';import'isomorphic-fetch';import*asbacklogjsfrom'backlog-js';// 'xxx.backlog.jp' or 'xxx.backlogtool.com' or 'your package host'consthost='yourSpaceHost';constapiKey='yourApiKey';constaccessToken='yourAccessToken';// Use API Keyconstbacklog=newbacklogjs.Backlog({ host, apiKey});// Use OAuth2 Access Tokenconstbacklog=newbacklogjs.Backlog({ host, accessToken});// Returns information about your space.backlog.getSpace().then(data=>{console.log('space:',data);}).catch(err=>{console.log('error:',err.message);});
// nodebacklog.getSpaceIcon().then(data=>{data.body.pipe(fs.createWriteStream(`./${data.filename}`));}).catch(err=>{console.log('error:',err.message);});// browserbacklog.getSpaceIcon().then(data=>{data.blob().then((blob)=>{constobjectURL=URL.createObjectURL(blob);constelement=window.document.querySelector('#image');element.src=objectURL;});}).catch(err=>{console.log('error:',err.message);});
// nodeconstformData=newFormData();formData.append("filename","sample.png");formData.append("file",fs.createReadStream("./sample.png"));// browser// <form method="post" enctype="multipart/form-data" >// <input type="file" name="file" >// </form>const$form=window.document.querySelector('#upload_form');constformData=newFormData($form);backlog.postSpaceAttachment(formData).then(data=>{console.log('success:',data);}).catch(err=>{console.log('error:',err.message);});
Details on the OAuth2 process are availablehere.
Here are the basic steps for OAuth2 using the Express:
import*asexpressfrom'express';import*asbacklogjsfrom'backlog-js';constapp=express();consthost='xxx.backlog.jp';// or 'xxx.backlogtool.com' or 'your package host'constclientId='yourClientId';constclientSecret='yourClientSecret';constredirectUri='https://localhost:3000/callback';conststate='yourState';constcredentials={ clientId, clientSecret}constoauth2=newbacklogjs.OAuth2(credentials);constauthorizationURL=oauth2.getAuthorizationURL({ host, redirectUri, state});app.get('/auth',(req,res)=>{res.redirect(authorizationURL);});app.get('/callback',async(req,res)=>{constcode=req.query.code;try{constaccessToken=awaitoauth2.getAccessToken({ host, code, redirectUri});console.log('Access Token:',accessToken);// save access token.constmyself=awaitnewbacklogjs.Backlog({ host,accessToken:accessToken.access_token}).getMyself();console.log('Myself:',myself);res.redirect('/');}catch(e){console.log('Access Token Error',e.message);res.redirect('/login');}});app.get('/',(req,res)=>{res.send('Hello');});app.get('/login',(req,res)=>{res.send('<a href="/auth">Login with Backlog</a>');});app.listen(3000);console.log('Express server started on port 3000');
MIT License
About
Backlog API version 2 client for browser and node.
Resources
Stars
Watchers
Forks
Packages0
No packages published