Custom API

The Custom API is user defined in the Diffbot UI.

For a tutorial on creating a Custom API in the Diffbot UI, see here.

Custom API Class

class Swader\Diffbot\Api\Custom

When you have a Custom API ready on Diffbot’s end, you instantiate the Custom API class and pass in the Custom API name, along with the URL to process. Everything from that point on is identical to the other APIs, except the fact that instead of specific entities being returned, all Custom API calls return an iterator of Swader\Diffbot\Entity\Wildcard entities.

Swader\Diffbot\Api\Custom::__construct($url, $name)
  • $url (string) – The URL to process
  • $name (string) – The name of the API

The construct method is identical to the one in Swader\Diffbot\Abstracts\Api with one difference - it also needs the name of the Custom API in question, so that it can build the API URL to which the call will be dispatched when Swader\Diffbot\Abstracts\Api::call is called:


require_once '../vendor/autoload.php';

use Swader\Diffbot\Diffbot;

$diffbot = new Diffbot($my_token);

$url = '';
$api = $diffbot->createCustomApi($url, "AuthorFolio");

$result = $api->call();

echo $result->getBio(); // "Bruno is a coder from Croatia..."

In the example above, AuthorFolio is a custom API from this tutorial, which processes a SitePoint author’s portfolio. The getBio call works because of the magic methods in Swader\Diffbot\Abstracts\Entity which Swader\Diffbot\Entity\Wildcard inherits.

Wildcard Entity Class

class Swader\Diffbot\Entity\Wildcard

The Wildcard entity is returned when the type of a processed post does not match a type defined in the currently set EntityFactory (see Swader\Diffbot\Factory\Entity and Swader\Diffbot\Diffbot::setEntityFactory).

It is nothing more than a concretization of Swader\Diffbot\Abstracts\Entity and as such contains no additional methods.

In the example above, the getBio method is called on a Wilcard instance, returned by the call to the AuthorFolio. custom API.