Copying tasks from ChatWork to Backlog

table of contents
Hello, this is Goto from the Web System Development Department
Our company uses ChatWork, but even though tasks are assigned via ChatWork,
if there are many tasks, they can get lost in the stream, and it can be difficult to understand priorities and deadlines.
On the other hand, Backlog allows you to manage tasks using a Gantt chart, making it easy to understand deadlines and importance
So,some code to transfer tasks from ChatWork to BacklogI've written
I hope it will be helpful for anyone planning to use the ChatWork API or Backlog API.
Each function will be introduced
1. Get tasks from ChatWork
You will need four pieces of information to retrieve a task from ChatWork
- Account ID of the person assigned the task
- Account ID of the person who assigned the task
- The chat room ID where the task was assigned
- Selecting completed or incomplete tasks
Each of these pieces of information can be found below
- The number after To: to the person assigned the task
- The number after To: to the person who assigned the task
- https://www.chatwork.com/#!ridThe number here (rid is not required)
- Completed done : Incomplete open
By adding these to the URL as GET parameters and making a request, task information will be returned in JSON format
function get_tasks_from_cw($account_id, $assigned_by_account_id, $room_id){ $params = array( 'account_id' = $account_id, // ID of the person who was assigned the task 'assigned_by_account_id' = $assigned_by_account_id, // ID of the person who assigned the task 'status' = 'open', // Open task ); $url = 'https://api.chatwork.com/v1/rooms/'.$room_id.'/tasks?'.http_build_query($params); $headers = array( 'http' => array( 'method' = 'GET', 'header' = implode("rn", $headers), ) ); $json_cw_tasks = file_get_contents($url, false, stream_context_create($context)); return json_decode($json_cw_tasks); }
2. Register an issue in Backlog
The following items are required to register with Backlog
- Project ID to register
- Issue type ID
- priority
- Issue subject
These are set as follows:
-
- The ID of the project you want to register can be determined from the URL of the project's "Project Settings" page
https://byd.backlog.jp/EditProject.action?project.id=the number here
-
- For the types of assignments, see 2-a
- Priority is 2 is high, 3 is medium, and 4 is low
- Feel free to choose the subject
function add_task_to_backlog($task, $project_id, $backlog_api_key){ $issue_type_id = get_issue_type_id_of_tasks($project_id); //Get the issueTypeId of the task mb_regex_encoding('UTF-8'); $params = array( 'projectId' = $project_id, 'issueTypeId' = $issue_type_id, 'priorityId' = 3, //Medium priority 'summary' = 'Task from ChatWork', 'description' = $task['body'], //Content of the issue to be registered (text of the task (body) obtained from CW) ); $url = 'https://space_name.backlog.jp/api/v2/issues?apiKey='.$backlog_api_key'&'.http_build_query($params, '&'); $header = array('Content-Type:application/x-www-form-urlencoded'); $context= array( 'http' => array( 'method' = 'POST', 'header' = $header, 'ignore_errors' = true, ) ); file_get_contents($url, false, stream_context_create($context)); }
2-a. Get the issueTypeId of the issue type "Task"
The type of issue depends on the project, so we'll retrieve the issueTypeId for that project from the API.
This time, we'll retrieve the issueTypeId for the "Task" type.
*There is no need to use curl here. I just tried it
function get_issue_type_id_of_tasks($project_id, $backlog_api_key){ $param = array('apiKey' = $backlog_api_key); $url = 'https://space_name.backlog.jp/api/v2/projects/'.$project_id.'/issueTypes?'.http_build_query($param); $ch = curl_init(); $options = array( CURLOPT_URL = $url, CURLOPT_HTTPGET = true, CURLOPT_HTTPHEADER = array( 'HTTP/1.0', 'Content-Type: application/x-www-form-urlencoded', ), CURLOPT_RETURNTRANSFER = true, ); curl_setopt_array($ch, $options); $issue_type_json = curl_exec($ch); $issue_types = json_decode($issue_type_json); //The return value is the ID of the retrieved issue whose type is "Task". foreach ($issue_types as $issue_type) { if ($issue_type->name == 'Task'){ $issu_type = $issue_type->id; } } return $issu_type; }
It's roughly like this
ChatWork tasks have a timestamp value that can be obtained from the `limit_time` element, so
I think it would be convenient to convert it when registering in backlog and put it in the `dueDate` parameter so that the due date is also copied.
Please try extending it.
0
