Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Backlog API version 2 client for browser and node.

NotificationsYou must be signed in to change notification settings

nulab/backlog-js

Repository files navigation

Backlog API version 2 client for browser and node.

Required reading

Please check out theNulab Backlog API page.

Installation

npm:

$ npm install --save backlog-js

Getting started

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);});

Other Example

Download File

// 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);});

Upload File

// 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);});

Use OAuth2 for authentication

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');

License

MIT License


[8]ページ先頭

©2009-2025 Movatter.jp