PHPackages                             havenondemand/havenondemand - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. havenondemand/havenondemand

ActiveLibrary[API Development](/categories/api)

havenondemand/havenondemand
===========================

This library allows you to quickly and easily make requests to Haven OnDemand's APIs.

1.0.0(10y ago)101593MITPHPPHP &gt;=5.3

Since Apr 7Pushed 9y ago3 watchersCompare

[ Source](https://github.com/HPE-Haven-OnDemand/havenondemand-php)[ Packagist](https://packagist.org/packages/havenondemand/havenondemand)[ Docs](https://github.com/HPE-Haven-OnDemand/havenondemand-php)[ RSS](/packages/havenondemand-havenondemand/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

HODClient Library for PHP
=========================

[](#hodclient-library-for-php)

Official PHP client library to help with calling [Haven OnDemand APIs](http://havenondemand.com).

What is Haven OnDemand?
-----------------------

[](#what-is-haven-ondemand)

Haven OnDemand is a set of over 70 APIs for handling all sorts of unstructured data. Here are just some of our APIs' capabilities:

- Speech to text
- OCR
- Text extraction
- Indexing documents
- Smart search
- Language identification
- Concept extraction
- Sentiment analysis
- Web crawlers
- Machine learning

For a full list of all the APIs and to try them out, check out

Integrate HODClient into php project
------------------------------------

[](#integrate-hodclient-into-php-project)

### Download from Packagist and include in app

[](#download-from-packagist-and-include-in-app)

Run the following command from your terminal (composer must be installed)

```
composer require havenondemand/havenondemand

```

Place the following line in your app to include the library

```
include './vendor/havenondemand/havenondemand/lib/hodclient.php';
include './vendor/havenondemand/havenondemand/lib/hodresponseparser.php';

```

### Download directly from Github

[](#download-directly-from-github)

1. Download the HODClient and HODResponseParser libraries for PHP.
2. Unzip the file and copy the hodclient.php and hodresponseparser.php under the lib folder to your project folder.

### Using the library

[](#using-the-library)

Creates and initializes a HODClient object.

```
HODClient($apiKey, $version = "v1")

```

- `$apiKey` is your developer apikey.
- `$version` Haven OnDemand API version. The default value is "v1".

*Example code:*

```
include "hodclient.php"
$hodClient = new HODClient("API_KEY");

```

If you want to change the API version without the need to recreate the instance of the HOD client.

```
SetVersion($newversion)

```

- `$newVersion` a string to specify an API version as "v1" or "v2"

If you want to change the API\_KEY without the need to recreate the instance of the HOD client.

```
SetAPIKey($newApiKey)

```

- `newApiKey` a string to specify a new API\_KEY

**Function GetRequest**

Sends a HTTP GET request to call an Haven OnDemand API.

```
GetRequest($paramArr, $hodApp, $async, $callback)

```

- `$paramArr` is an array() containing key/value pair parameters to be sent to a Haven OnDemand API, where the keys are the parameters of that Haven OnDemand API.

*Note:* If a parameter type is an array&lt;&gt;, the value must be defined as an array() or \[\].

E.g.:

```
$sources = array();
array_push($sources, "http://www.cnn.com");
array_push($sources, "http://www.bbc.com");
$paramArr = array(
    'url' => $sources,
    'entity_type' => ["people_eng","places_eng","companies_eng"]
);
```

- `$hodApp` is a string to identify a Haven OnDemand API. E.g. "extractentities".
- `$async [true | false]` specifies API call as Asynchronous or Synchronous.
- `$callback` the name of a callback function. If the $callback is omitted, or is an empty string "", this function will return a response.

*Example code:*

```
// Call the Entity Extraction API synchronously to find people, places and companies from CNN website.
$paramArr = array(
    'url' => "http://www.cnn.com",
    'entity_type' => ["people_eng","places_eng","companies_eng"]
);
$response = GetRequest($paramArr, HODApps::ENTITY_EXTRACTION, false);

```

**Function PostRequest**

Sends a HTTP POST request to call a Haven OnDemand API.

```
PostRequest($paramArr, $hodApp, $async, $callback)

```

- `$paramArr` is an array() containing key/value pair parameters to be sent to a Haven OnDemand API, where the keys are the parameters of that Haven OnDemand API.

*Note:* If a parameter type is an array&lt;&gt;, the value must be defined as an array() or \[\].

E.g.:

```
$sources = array();
array_push($sources, "http://www.cnn.com");
array_push($sources, "http://www.bbc.com");
$paramArr = array(
    'url' => $sources,
    'entity_type' => ["people_eng","places_eng","companies_eng"]
);

```

- `$hodApp` is a string to identify an Haven OnDemand API. E.g. "ocrdocument".
- `$async [true | false]` specifies API call as Asynchronous or Synchronous.
- `$callback` the name of a callback function. If the $callback is omitted, or is an empty string "", this function will return a response.

*Example code:*

```
// Call the OCR Document API asynchronously to scan text from an image file.
$paramArr = array(
    'file' => "full/path/filename.jpg",
    'mode' => "document_photo")
);
$response = $hodClient->PostRequest($paramArr, HODApps::OCR_DOCUMENT, true);

```

**Function GetJobResult**

Sends a request to Haven OnDemand to retrieve content identified by a job ID.

```
GetJobResult($jobID, $callback)

```

- `$jobID` the job ID returned from an Haven OnDemand API upon an asynchronous call.
- `$callback` the name of a callback function, which the HODClient will call back and pass the response from server. If the $callback is omitted, or is an empty string "", this function will return a response.

**Function GetJobStatus**

Sends a request to Haven OnDemand to retrieve the status of a job identified by a job ID.

```
GetJobStatus($jobID, $callback)

```

- `$jobID` the job ID returned from an Haven OnDemand API upon an asynchronous call.
- `$callback` the name of a callback function, which the HODClient will call back and pass the response from server. If the $callback is omitted, or is an empty string "", this function will return a response.

**Function GetRequestCombination**

Sends a HTTP GET request to call a combination API.

```
GetRequestCombination($paramArr, $hodApp, $async, $callback)

```

- `$paramArr` is an array() containing key/value pair parameters to be sent to a Haven OnDemand API, where the keys are the parameters of the calling API.

*Note:* If a parameter type is an array \[\] or a JSON object {}, the value must be quoted as a string. E.g.:

```
$paramArr = array(
    'url' => 'http://www.bbc.com',
    'entity_type' => '["people_eng","places_eng","companies_eng"]'
);

```

- `$hodApp` is the name of the combination API you are calling
- `$async [true | false]` specifies API call as Asynchronous or Synchronous.
- `$callback` the name of a callback function. If the $callback is omitted, or is an empty string "", this function will return a response.

*Example code:*

```
// Call the Entity Extraction API synchronously to find people, places and companies from CNN website.
$paramArr = array(
    'url' => "http://www.cnn.com",
    'entity_type' => '["people_eng","places_eng","companies_eng"]'
);
$response = GetRequestCombination($paramArr, "combination_api_name", false);

```

**Function PostRequestCombination**

Sends a HTTP POST request to call a combination API.

```
PostRequestCombination($paramArr, $hodApp, $async, $callback)

```

- `$paramArr` is an array() containing key/value pair parameters to be sent to a Haven OnDemand API, where the keys are the parameters of the calling API.

*Note:* If a parameter type is an array \[\] or a JSON object {}, the value must be quoted as a string. E.g.:

```
$paramArr = array(
    'url' => 'http://www.bbc.com',
    'entity_type' => '["people_eng","places_eng","companies_eng"]'
);

```

- `$hodApp` is the name of the combination API you are calling
- `$async [true | false]` specifies API call as Asynchronous or Synchronous.
- `$callback` the name of a callback function. If the $callback is omitted, or is an empty string "", this function will return a response.

*Example code:*

```
// Call the Entity Extraction API synchronously to find people, places and companies from CNN website.
$paramArr = array(
    'url' => "http://www.cnn.com",
    'entity_type' => '["people_eng","places_eng","companies_eng"]'
);
$response = PostRequestCombination($paramArr, "combination_api_name", false);

```

Demo code 1:
------------

[](#demo-code-1)

**Call the Entity Extraction API to extract people and places from cnn.com website with a synchronous GET request**

```
