PHP code example of footbridge-media / accelo-php-sdk

1. Go to this page and download the library: Download footbridge-media/accelo-php-sdk 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/ */

    

footbridge-media / accelo-php-sdk example snippets


use FootbridgeMedia\Accelo\Accelo;

$accelo = new Accelo();

use FootbridgeMedia\Accelo\Authentication\AuthenticationType;
use FootbridgeMedia\Accelo\Authentication\WebAuthentication;
use FootbridgeMedia\Accelo\Authentication\ServiceAuthentication;

// For web authentication
$authentication = new WebAuthentication();
$authentication->authType = AuthenticationType::Bearer;
$authentication->accessToken = "USER_ACCESS_TOKEN";
$authentication->refreshToken = "USER_REFRESH_TOKEN";

// For service authentication, use the below INSTEAD of the above
$authentication = new ServiceAuthentication();
$authentication->authType = AuthenticationType::Bearer;
$authentication->accessToken = "SERVICE_ACCESS_TOKEN";

use FootbridgeMedia\Accelo\ClientCredentials\ClientCredentials;

$clientCredentials = new ClientCredentials();
$clientCredentials->deploymentName = "DEPLOYMENT_NAME";
$clientCredentials->clientID = "CLIENT_ID";
$clientCredentials->clientSecret = "CLIENT_SECRET";

$accelo->setAuthentication($authentication);
$accelo->setCredentials($clientCredentials);

use FootbridgeMedia\Accelo\Companies\Company;

// Set up a search query for the company results
$search = new Search();
$search->setQuery("Footbridge Media");

// Setup filters
$filters = new Filters();
$filters->addFilter(
    filterName:"standing",
    filterValue: "active",
);

// Perform the request
try{
    $requestResponse = self::$accelo->list(
        endpoint: "/companies",
        objectType: Company::class,
        filters: $filters,
        search: $search,
    );
}catch (\FootbridgeMedia\Resources\Exceptions\APIException $e) {
    print($e->getMessage());
} catch (\GuzzleHttp\Exception\GuzzleException $e) {
    // HTTP error from Guzzle
    print($e->getMessage());
}

/** @var Company[] $companies */
$companies = $requestResponse->getListResult();

foreach($companies as $company){
    printf("{$company->name}\n");
}

// ORDER BY filter
$filters = new Filters();
$filters->addFilter(
    filterName:"order_by_asc",
    filterValue: "name",
);

$paginator = new Paginator();
$paginator->setLimit(15);
$paginator->setPage(0); // Page 0 is the starting page

// Perform the request
$requestResponse = self::$accelo->list(
    endpoint: "/companies",
    objectType: Company::class,
    filters: $filters,
    paginator: $paginator,
);

/** @var Company[] $companies */
$companies = $requestResponse->getListResult();

foreach($companies as $company){
    printf("{$company->name}\n");
}

if ($requestResponse->hasMorePages){
    // Increment the paginator
    $paginator->incrementPage();
    
    // Repeat the same request
    $requestResponseNextPage = self::$accelo->list(
        endpoint: "/companies",
        objectType: Company::class,
        filters: $filters,
        paginator: $paginator,
    );
    
    /** @var Company[] $companies */
    $companiesFromNextPage = $requestResponseNextPage->getListResult();
}

$companyIDToUpdate = 11; // ID of the company to update records of

$updateFields = new Fields();
$updateFields->addField(
    fieldName: "name",
    fieldValue:"Company's New Name!",
);

$requestResponse = self::$accelo->update(
    endpoint: "/companies/" . $companyID,
    objectType: Company::class,
    fields: $updateFields,
    additionalFields: null,
);

/** @var Company $companyUpdated */
$companyUpdated = $requestResponse->getUpdatedObject();

print($companyUpdated->name);

$creationFields = new Fields();
$creationFields->addField(
    fieldName: "name",
    fieldValue:"My New Company",
);

$creationFields->addField(
    fieldName: "standing",
    fieldValue: Standing::INACTIVE->value,
);

$additionalReturnFields = new AdditionalFields();
$additionalReturnFields->addField(
    fieldName:"standing",
);

$requestResponse = self::$accelo->create(
    endpoint: "/companies",
    objectType: Company::class,
    fields:$creationFields,
    additionalFields: $additionalReturnFields,
);

/** @var Company $newCompany */
$newCompany = $requestResponse->getCreatedObject();

print($newCompany->name);
print($newCompany->standing);

self::$accelo->delete(
    endpoint: "/companies/1",
);

// Create a dummy object with the desired ID to run a progression on
$issueID = 30155;
$issue = new Issue();
$issue->id = $issueID;

$progressionID = 100; // Get this from your Accelo deployment. It would be in the URL after you click a progression on a ticket type (NOT a status)

$additionalReturnFields = new AdditionalFields();
$additionalReturnFields->addField(
    fieldName: "status",
);

$requestResponse = $issue->runProgression(
    accelo: self::$accelo,
    progressionID: $testProgressionID,
    additionalFields:$additionalReturnFields,
);

/** @var Issue $progressedIssue */
$progressedIssue = $requestResponse->getProgressedObject();
print($progressedIssue->status); // Will be the new status after the progression is ran

$accelo->setAPIBaseUrl("https://...");
$accelo->setAPIVersionString("v0");

// Getters
$accelo->getAPIBaseUrl();
$accelo->getAPIVersionString();

composer 

php vendor/footbridge-media/accelo-php-sdk/src/Resources/CLIScripts/WebAuthenticate.php

php vendor/footbridge-media/accelo-php-sdk/src/Resources/CLIScripts/ServiceAuthenticate.php