Skip to content

Instantly share code, notes, and snippets.

@proudcommerce
Last active July 11, 2023 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proudcommerce/956457e04b4aa63b6303b54dd217a782 to your computer and use it in GitHub Desktop.
Save proudcommerce/956457e04b4aa63b6303b54dd217a782 to your computer and use it in GitHub Desktop.
Clockify Webhook Zeitreintrag bearbeiten
<?php
$rawData = file_get_contents('php://input');
$jsonData = json_decode($rawData);
if(!empty($jsonData->description)) {
$timeEntryId = $jsonData->id;
$workspaceId = $jsonData->workspaceId;
$description = prepareDescription($jsonData->description);
$newTags = prepareTags($jsonData->tags);
}
if(!empty($workspaceId) && !empty($timeEntryId) && !empty($description)) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.clockify.me/api/v1/workspaces/$workspaceId/time-entries/$timeEntryId",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode(array(
"start" => $jsonData->timeInterval->start,
"end" => $jsonData->timeInterval->end,
"projectId" => $jsonData->projectId,
"description" => $description,
"tagIds" => $newTags,
"taskId" => $jsonData->task->id
)),
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"X-Api-Key: YOUR_API_KEY"
),
));
$response = json_decode(curl_exec($curl));
curl_close($curl);
}
// prepare description
function prepareDescription($description)
{
$description = str_replace('replace_anything_with', 'xxx', $description);
return $description;
}
// remove some tags
function prepareTags($tags)
{
$newTags = [];
foreach($tags as $key => $tag) {
if(!in_array($tag->name, ['Task', 'Sub-Task'])) {
$newTags[] = $tag->id;
}
}
return $newTags;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment