PHP code example of stichoza / jira-webhooks-data

1. Go to this page and download the library: Download stichoza/jira-webhooks-data library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stichoza / jira-webhooks-data example snippets


// Example payload received from Jira webhook
$data = [
    "timestamp" => 1629835026055,
    "webhookEvent" => "jira:issue_updated",
    // ... other webhook data ...
    "issue" => [
        // ... issue data ...
    ],
    "changelog" => [
        // ... changelog data ...
    ],
    // ... other data ...
];

use Stichoza\JiraWebhooksData\Models\JiraWebhookData;

$webhookData = new JiraWebhookData($data);

$message = 'New comment by ' . $webhookData->comment->author->displayName
    . ' on issue ' . $webhookData->issue->key;
    . ': ' . $webhookData->comment->body;

$timestamp = $webhookData->timestamp;
$webhookEvent = $webhookData->webhookEvent;
$issueEvent = $webhookData->issueEvent;
$user = $webhookData->user; // JiraUser instance
$issue = $webhookData->issue; // JiraIssue instance
$changelog = $webhookData->changelog; // JiraChangelog instance
$worklog = $webhookData->worklog; // JiraWorklog instance

$issueId = $issue->id;
$issueKey = $issue->key;
$issueTypeName = $issue->issueTypeName;
$priorityName = $issue->priorityName;

if ($user) {
    $userAccountId = $user->accountId;
    $userDisplayName = $user->displayName;
    // ... and other properties ...
}

$changelogId = $changelog->id;
$changelogItems = $changelog->items; // Array of JiraChangelogItem instances
// ... and other properties ...

if ($issue && $issue->isStatusResolved()) {
    // Do something for resolved issues
}

if ($user && $user->active) {
    // Do something for active users
}

use Stichoza\JiraWebhooksData\Models\JiraWebhookData;
use Stichoza\JiraWebhooksData\Exceptions\JiraWebhookDataException;

try {
    $webhookData = new JiraWebhookData($data);
} catch (JiraWebhookDataException $e) {
    // Handle the error
}

$to = $webhookData->issue?->assignee?->email;

if ($to !== null) {
    // Do something
}