Effective use of Backlog's API

table of contents
Hello.
I'm Mandai, the Wild team member in charge of development.
At our company, we use Backlog as our development tool.
Backlog can be used as a repository server for Git, Subversion, etc., as a progress management tool, or to consolidate knowledge in a wiki, or to create tasks for issues, and much more.
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
OAuth 2.0 is available, but to be honest, I don't use it.
I mostly use it from batch programs, so I have no choice but to use API Key requests.
// 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');
GET requests are easy to access by changing the subdomain and path.
The most difficult part is figuring out which API to use, as there are many features and the API is well-developed.
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
Since API endpoints are often the same, please be careful not to delete important data by using the wrong HTTP method.
The difference between PUT and PATCH when editing is not a matter of choosing one over the other, but rather the method accepted is determined by the API, sothe Backlog API documentationplease check
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 the 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, you submit the DELETE method.
Conversely, if you don't specify the DELETE method, the information will not be deleted unless there is an intention to delete it (or 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
You're probably familiar with Chrome, as it's a very popular browser app, but do you use it all the time?
When you run the Backlog API in Chrome, the API results are garbled, and since version 55 or so, it's no longer possible to change the character encoding, so there's no way to fix it.
(Probably because it's not HTML, and therefore the encoding isn't 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 pasting JSON data for information exchange isn't ideal for sophisticated systems, I find it very useful as a data storage location when automating tasks with small shell scripts for personal work.
When running detailed processes across multiple servers, constantly changing database connection restrictions is cumbersome, and the ease of API access makes it very convenient.
That's all
1
