Login to see what the code below returns from the XBRL API.

The XBRL API is a unified interface to stored XBRL data (facts and taxonomies) that enables developers with limited XBRL knowledge to learn a single interface and access any data repository structured to the XBRL Specification.

<?php

// NOTES: Highlighted rows correspond to sample
//        query parameters ( $args ) for requested
//        report and fact endpoints ( $recent_filings ).
// OAuth logic is omitted from this example. 

// Whitespace/breaks in $concepts variable is for illustrative purposes only.
 
    $limit = 5;
    if (isset($args['limit']) && $args['limit'] !='' ) {
        $limit = $args['limit'];
    }
    $api = new XBRLUSCall ();

    $concepts = '
       CashAndCashEquivalentsAtCarryingValue,
       LiabilitiesAndStockholdersEquity,
       RetainedEarningsAccumulatedDeficit';

    $args = array('fields' => "
     report.accepted-timestamp.sort(DESC),
     period.instant.sort(DESC),
     concept.local-name.sort(ASC),
     entity.cik,
     fact.value,
     fact.decimals,
     report.creation-software,
     report.document-type,
     report.entity-name,
     report.entry-type,
     report.limit(" . $limit . "),
     report.sec-url,",
           'concept.local-name' => $concepts,
           'fact.has-dimensions' => 'false',
           'period.fiscal-year' => '2018,2017',
           'report.document-type' =>
              '10-K,10-K/A,10-Q,10-Q/A,8-K,8-K/A',
           'report.is-most-current' => 'true'
    );

    $recent_filings = $api->call ( 
    '/api/v1/report/fact/search', 'GET', $args );

    $recent_filings = json_decode ( $recent_filings, true );
            $output = "

<!-- return api results as html -->

			<table class=api-sample>
            <thead><tr><th class=api-row-head>
            Report for company (CIK) plus filing detail &amp; select reported facts</th><th class=api-row-head style=text-align:right;>
            Accepted (ET)</th></tr></thead>";

    if (! isset ( $recent_filings ['error'] ) && count ( $recent_filings['data'] ) > 0) {
        $num = 0;
        foreach ( 
        $recent_filings['data'] as $recent_row ) { 
        $date = strtotime($recent_row ['report.accepted-timestamp']);
            $output .= "

<!-- row 1 - document type, entity, cik, date accepted -->

			<tr class=api-background>";
            $output .= "<td class=api-row-1 style='font-weight:600;'>" .
              $recent_row ['report.document-type'] . " for " .
              $recent_row ['report.entity-name'] . " (" .
              $recent_row ['entity.cik'] . ")</td>";
		            $output .= "<td class=api-row-1 nowrap style=text-align:right>" .
              date('D, n/j g:i A', $date) . "</td>";
            $output .= "</tr>

<!-- row 2 - entry (instance or inline), link to EDGAR, report software used -->

			<tr class=api-background>";
			$output .= "<td class=api-row-2 colspan=2><a href=" .
              $recent_row ['report.sec-url'] . " target=blank>" .
              ucfirst ($recent_row ['report.entry-type']) . " document on EDGAR <i class='fa fa-external-link' aria-hidden='true'></i></a><div style='text-align:right;float:right'>" .
              $recent_row ['report.creation-software'] . "</div></td>";
			$output .= "</tr><tr class=api-background><td colspan=2 class=api-row-data><table class=api-row-detail>

<!-- row 3+ - each queried element, instance date, amount-->

			<tr class=api-background>";
        foreach ( 
        $recent_row['fact']['data'] as $fact ) {
        $period = strtotime($fact['period.instant']);
        $element = preg_replace('/(?<!\ )[A-Z]/', ' $0', $fact['concept.local-name']);
        $value = $fact['fact.value'];
        $decimals = abs($fact['fact.decimals']);
        $amount = str_pad($value , $decimals , '0' , STR_PAD_RIGHT);
            $output .= "<tr><td class=api-cell-element><pre>" .
              $element . " as of " .
              date('F j, Y', $period) . "</pre></td><td class=api-cell-element><pre>$</pre></td><td class=api-cell-value><pre style=text-align:right>" . 
              number_format($amount) . "</pre></td></tr>" ; }
            $output .= "</tr></table></td></tr>";
        }
    } else {
        $output .= "<tr><td colspan=2>You might need to log in again to refresh your view of the data in this report <em>OR</em> no filings have been submitted matching these query parameters.</td></tr>";
    }
		$output .= "</table>

<!-- end api results as html -->

";";

    return $output;
} ?>

Comment