PHP code example of cardtechie / tradingcardapi-sdk-php
1. Go to this page and download the library: Download cardtechie/tradingcardapi-sdk-php 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/ */
cardtechie / tradingcardapi-sdk-php example snippets
use CardTechie\TradingCardApiSdk\Facades\TradingCardApiSdk;
// Get a specific card
$card = TradingCardApiSdk::card()->get('card-id');
// Search for cards
$cards = TradingCardApiSdk::card()->list(['name' => 'Pikachu']);
// Get player information
$player = TradingCardApiSdk::player()->get('player-id');
// Get paginated list of players
$players = TradingCardApiSdk::player()->list(['limit' => 25, 'page' => 1]);
// Search for players (returns Collection)
$players = TradingCardApiSdk::player()->all(['full_name' => 'Michael Jordan']);
// Get a set with related data
$set = tradingcardapi()->set()->get('set-id', [' 'New Team',
'location' => 'City Name'
]);
use CardTechie\TradingCardApiSdk\Facades\TradingCardApiSdk;
// Get a specific player
$player = TradingCardApiSdk::player()->get('player-id');
// Create a new player
$player = TradingCardApiSdk::player()->create([
'first_name' => 'Michael',
'last_name' => 'Jordan'
]);
// Update player information
$player = TradingCardApiSdk::player()->update('player-id', [
'first_name' => 'Michael Jeffrey',
'last_name' => 'Jordan'
]);
// Delete a player
TradingCardApiSdk::player()->delete('player-id');
// Get paginated list of players
$players = TradingCardApiSdk::player()->list([
'limit' => 50,
'page' => 1,
'sort' => 'last_name'
]);
// Search for players (returns Collection)
$players = TradingCardApiSdk::player()->all([
'full_name' => 'Michael Jordan',
'parent_id' => null // Only parent players, not aliases
]);
// Find players by partial name
$players = TradingCardApiSdk::player()->all([
'first_name' => 'Michael'
]);
// Working with player relationships
$player = TradingCardApiSdk::player()->get('player-id');
// Get parent player (if this is an alias)
$parent = $player->getParent();
// Get all aliases of this player
$aliases = $player->getAliases();
// Get teams this player has been associated with
$teams = $player->getTeams();
// Get all player-team relationships
$playerteams = $player->getPlayerteams();
// Check if player is an alias
if ($player->isAlias()) {
echo "This is an alias of: " . $player->getParent()->full_name;
}
// Check if player has aliases
if ($player->hasAliases()) {
echo "This player has " . $player->getAliases()->count() . " aliases";
}
// Create a parent player
$parent = TradingCardApiSdk::player()->create([
'first_name' => 'Michael',
'last_name' => 'Jordan'
]);
// Create an alias player with parent relationship
$alias = TradingCardApiSdk::player()->create(
['first_name' => 'Mike', 'last_name' => 'Jordan'],
['parent' => ['data' => ['type' => 'players', 'id' => $parent->id]]]
);
// List deleted players
$deletedPlayers = TradingCardApiSdk::player()->listDeleted();
// Get a specific deleted player
$deletedPlayer = TradingCardApiSdk::player()->deleted('player-id');
// Get current counts for all entity types
$counts = $api->stats()->getCounts();
// Access counts for a specific entity type
$setsCount = $counts->getByEntityType('sets');
echo $setsCount->total; // Total count
echo $setsCount->published; // Published count
echo $setsCount->draft; // Draft count
echo $setsCount->archived; // Archived count
// Get growth metrics (default: 7 days)
$growth = $api->stats()->getGrowth();
// Or specify a period: '7d', '30d', '90d', 'week', 'month'
$growth = $api->stats()->getGrowth('30d');
$setsGrowth = $growth->getByEntityType('sets');
echo $setsGrowth->current; // Current count
echo $setsGrowth->previous; // Previous period count
echo $setsGrowth->change; // Absolute change
echo $setsGrowth->percentageChange; // Percentage change
// Get historical snapshots
$snapshots = $api->stats()->getSnapshots();
// With filters
$snapshots = $api->stats()->getSnapshots([
'entity_type' => 'sets',
'from' => '2024-11-01',
'to' => '2024-11-30',
]);
foreach ($snapshots->snapshots as $snapshot) {
echo $snapshot->date; // Snapshot date
echo $snapshot->entityType; // Entity type
echo $snapshot->total; // Total at that point
}
// Get all sources for a specific set
$sources = $api->setSource()->forSet('set-id');
// Get a specific source
$source = $api->setSource()->get('source-id');
// Create a new set source
$source = $api->setSource()->create([
'set_id' => 'set-uuid',
'source_url' => 'https://example.com/checklist',
'source_name' => 'Example Source',
'source_type' => 'checklist', // checklist, metadata, or images
]);
// Update a source
$source = $api->setSource()->update('source-id', [
'source_url' => 'https://example.com/updated-checklist',
'verified_at' => '2024-01-15T10:30:00Z',
]);
// Delete a source
$api->setSource()->delete('source-id');
// Include sources when fetching a set
$set = $api->set()->get('set-id', ['
$internal = $api->internal();
// workflow and audit-log resources are now under internal()
$actionable = $internal->workflow()->actionableSets();
$logs = $internal->auditLog()->getAuditLogs();
$workflow = $api->internal()->workflow();
// Get sets that have actionable workflow steps
// Returns a typed ActionableSetsResponse (->sets is an array of ActionableSet)
$actionable = $workflow->actionableSets();
foreach ($actionable->sets as $set) {
echo $set->attributes->name;
}
// Filter actionable sets
$actionable = $workflow->actionableSets(['filter[sport]' => 'baseball']);
// Get workflow status for a specific set (via Set resource — still public)
$workflowStatus = $api->set()->workflow('set-id');
// Update a workflow step (set-todo) status
$result = $workflow->updateSetTodo('todo-id', [
'status' => 'completed',
]);
// Bulk initialize workflow todos for all existing sets
$job = $workflow->bulkInitializeWorkflow();
echo $job->data->job_id; // Job ID to poll for status
echo $job->data->status; // 'queued'
// Initialize workflow todos for specific sets only
$job = $workflow->bulkInitializeWorkflow([
'set_ids' => ['set-id-1', 'set-id-2'],
]);
// Poll bulk initialization job status
$status = $workflow->getBulkInitializeStatus($job->data->job_id);
echo $status->data->status; // 'queued', 'processing', or 'completed'
echo $status->data->processed; // Sets processed so far
echo $status->data->total; // Total sets to process
// Get workflow todos for a specific set
$result = $workflow->getSetTodos('set-id');
foreach ($result->todos as $todo) {
echo $todo->step; // e.g. 'discover_sources'
echo $todo->status; // e.g. 'completed'
}
// Get all sets blocked for human review
$reviewQueue = $workflow->getReviewQueue();
// Filter review queue by workflow step
$parseReview = $workflow->getReviewQueue('parse');
// Flag a workflow step for human review
$workflow->flagForReview('todo-id', 'Data quality issue detected');
// Resolve a review (resets to pending)
$workflow->resolveReview('todo-id');
$workflow->resolveReview('todo-id', 'Verified card data is correct');
// Use WorkflowStatus and WorkflowStep enums instead of magic strings
$workflow->updateSetTodo('todo-id', [
'status' => \CardTechie\TradingCardApiSdk\Enums\WorkflowStatus::COMPLETED->value,
]);