Effectively utilize Backlog's API

table of contents
Hello.
I'm Mandai, in charge of Wild on the development team.
At our company, we use Backlog as a development tool.
Backlog can be used as a repository server for git, subversion, etc., as a progress management tool, to aggregate knowledge in a wiki, and to accumulate tasks in issues. It's a tool that can do a lot of things.
I occasionally use the API, but my brain is starting to feel a bit messed up and I keep forgetting how to use it, so I'll paste some code that I think I can copy and paste
certification
OAuth2.0 is provided, but honestly I don't use it.
I mostly use it from batch programs, so requests using an API key are the only option.
// Get it with curl curl https://xx.backlog.jp/api/v2/users/myself?apiKey=abcdefghijklmn
Get with PHP $response = file_get_contents('https://xxx.backlog.jp/api/v2/users/myself?apiKey=abcdefghijklmn');
If you change the subdomain and path, GET access is easy.
The hardest part is figuring out which API to use, as there are many functions and the API is well-established.
CRUD operations
The Backlog API is RESTful, so it clearly defines HTTP methods for various CRUD operations
- To get information, use GET
- For creating information, POST
- To edit information, use PUT or PATCH
- To delete information, click DELETE
Please note that since API endpoints are often the same, using the wrong HTTP method could result in the deletion of important data.
The difference between PUT and PATCH when editing does not mean which one to use, but rather the accepted methods are determined by the API, so please check the Backlog API documentation
When you want to obtain information
If you want to retrieve information, use the GET method
# Get space information curl https://[subdomain].backlog.jp/api/v2/space?apiKey=[API KEY]
When you want to create information
If you want to create information, send it using the POST method
# Add a Wiki page curl -X POST https://[subdomain].backlog.jp/api/v2/wikis?apiKey=[API KEY] -d "projectId=xxx" -d "name=wiki_name" -d "content=hogehoge" # Register a new issue curl -X POST https://[subdomain].backlog.jp/api/v2/issues?apiKey=[API KEY] -d "projectId=xxx" -d "summary=issue_title" -d "issueTypeId=1" -d "priorityId=3" # Get type information # Rewrite subdomain, project ID, and API KEY curl https://[subdomain].backlog.jp/api/v2/projects/[xxx]/issueTypes?apiKey=[API KEY] # Get a list of priorities # Rewrite subdomain and API KEY curl https://[subdomain].backlog.jp/api/v2/priorities?apiKey=[API KEY]
If you want to edit the information
If you want to edit information, send it using either the POST or PATCH method.
The method varies depending on the API, so please refer to the documentation.
# Update project information # You can specify either ProjectID or ProjectKey where projectIdOrKey is specified curl -X PATCH https://[subdomain].backlog.jp/api/v2/projects/[projectIdOrKey]?apiKey=[API KEY] -d "name=changed_name" # Mark a notification as read curl -X POST https://[subdomain].backlog.jp/api/v2/notifications/[notification_id]/markAsRead?apiKey=[API KEY] # Get notification_id curl https://[subdomain].backlog.jp/api/v2/notifications?apiKey=[API KEY]
When you want to delete information
If you want to delete information, send the DELETE method.
Conversely, if you do not include the DELETE method, it will not be deleted unless you intend to delete it (or there is a programming error).
# Delete an issue # Either ID or Key can be specified in the issueIdOrKey part curl -X DELETE https://[subdomain].backlog.jp/api/v2/issues/[issueIdOrKey]?apiKey=[API KEY]
A useful tool for checking API operation
A useful tool for executing APIs is Firefox
As you probably know, Chrome is a very popular browser app, but do you use it all the time?
When you run Backlog's API in Chrome, the results are garbled. However, since version 55, it has become impossible to change the character encoding, so there is no way to fix this.
(Probably because it is not HTML, so no encoding is specified.)
In this regard, Firefox displays the text without garbled characters, and at some point it introduced a mechanism to automatically parse JSON data, making it much easier to read
Additionally, both Chrome and Firefox have many add-ons and extensions for RESTful APIs, so using one that you are familiar with will speed up your development
I often use these tools for API development, but I still tend to create shell scripts using curl that also serve as test cases, so I can't provide any recommended API browser information..
summary
I've summarized it briefly, but what do you think?
In addition to task management and progress management, you can also use it as a database by pasting JSON into the Wiki, or as a file storage space, and it can be used in ways other than just as a development tool, depending on your imagination
While exchanging information by pasting JSON is not recommended for proper systems, I find it useful as a data repository when automating tasks with small shell scripts for personal use.
When running detailed processes across multiple servers, it can be a hassle to change the database connection restrictions every time, and the ease of API access makes it easy to just throw things away.
That's it.
1