Skip to content

Instantly share code, notes, and snippets.

@GromNaN
Created March 14, 2016 12:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save GromNaN/bfbcd31554cb0f4fe3e9 to your computer and use it in GitHub Desktop.
Rollbar : Find and resolve items using the API
<?php
$term = 'This resource is not routable';
$read_access_token = '<READ ACCESS TOKEN>';
$write_access_token = '<WRITE ACCESS TOKEN>';
$total = 0;
do {
$items = file_get_contents('https://api.rollbar.com/api/1/items/?access_token='.$read_access_token.'&status=active&query='.urlencode($term));
$items = json_decode($items, true);
echo 'Found '.count($items['result']['items']).' items'.PHP_EOL;
foreach ($items['result']['items'] as $item) {
echo ' > Processing '.$item['id'].' : '.$item['title'].PHP_EOL;
$postdata = http_build_query(['status' => 'resolved']);
$opts = ['http' => [
'method' => 'PATCH',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
]];
$context = stream_context_create($opts);
file_get_contents('https://api.rollbar.com/api/1/item/'.$item['id'].'?access_token='.$write_access_token, false, $context);
$total++;
}
} while (0 !== count($items['result']['items']));
echo PHP_EOL.'Processed '.$total.' items'.PHP_EOL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment