PHPackages                             newsdataio/newsdataapi - 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. newsdataio/newsdataapi

ActiveLibrary[API Development](/categories/api)

newsdataio/newsdataapi
======================

Official PHP client (SDK) for the Newsdata.io News API — fetch real-time, historical, crypto, and stock-market news via REST with validation, retries, and error handling.

1.0.1(1mo ago)23.1kMITPHPPHP ^7.3 || ^8.0CI passing

Since Oct 13Pushed 3w ago1 watchersCompare

[ Source](https://github.com/newsdataapi/php-client)[ Packagist](https://packagist.org/packages/newsdataio/newsdataapi)[ Docs](https://newsdata.io)[ RSS](/packages/newsdataio-newsdataapi/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (2)Versions (8)Used By (0)

[![Newsdata.io logo](https://raw.githubusercontent.com/newsdataapi/php-client/main/newsdata-logo.png)](https://raw.githubusercontent.com/newsdataapi/php-client/main/newsdata-logo.png)

Newsdata.io PHP Client
======================

[](#newsdataio-php-client)

[![Packagist Version](https://camo.githubusercontent.com/e0338791cf8c43cfb797fc4d108ebf33f0b0f19dac450c3a53266e9de302a922/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e65777364617461696f2f6e657773646174616170693f6c6f676f3d7061636b616769737426636f6c6f723d663238643161)](https://packagist.org/packages/newsdataio/newsdataapi)[![CI](https://camo.githubusercontent.com/4ea9c70a1301d87c311a59a4b740441d3389aa84958b622ba19e37be47cd662c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e657773646174616170692f7068702d636c69656e742f63692e796d6c3f6272616e63683d6d61696e266c6f676f3d676974687562266c6162656c3d4349)](https://github.com/newsdataapi/php-client/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/dd9c96ee7a44440cbd600e6319e49ac57e5f5b09866b58cb40c0254dc739dc3c/68747470733a2f2f636f6465636f762e696f2f67682f6e657773646174616170692f7068702d636c69656e742f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/newsdataapi/php-client)[![PHP](https://camo.githubusercontent.com/9cb1d5c364899bfb45ac627fb18ab20397f365bb9e0928304ced7bd203b0981a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e33253230253743253743253230253545382e302d677265656e3f6c6f676f3d706870)](https://github.com/newsdataapi/php-client/blob/main/LICENSE)[![License](https://camo.githubusercontent.com/b8cadaa967891081f8f165695470689986c028821dd8a040132f6e661795dc0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c7565)](https://github.com/newsdataapi/php-client/blob/main/LICENSE)[![OpenAPI](https://camo.githubusercontent.com/d075cce4f3da0e25c719c3972e3651c750acf2e6c6079c50493d0bb7c1e11c69/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4f70656e4150492d332e312d383545413244)](https://newsdata.io/openapi.json)

The official PHP client for the [Newsdata.io](https://newsdata.io) REST API. It wraps every endpoint (`latest`, `archive`, `sources`, `crypto`, `market`, `count`, `crypto/count`, `market/count`) with client-side parameter validation, automatic retries with exponential backoff, and a typed exception hierarchy.

Requirements
------------

[](#requirements)

PHP 7.3+ with the `curl` and `json` extensions.

Installation
------------

[](#installation)

With [Composer](https://getcomposer.org/):

```
composer require newsdataio/newsdataapi
```

Without Composer, include the bundled autoloader:

```
require_once '/path/to/php-client/autoload.php';
```

Quickstart
----------

[](#quickstart)

```
use NewsdataIO\NewsdataApi;
use NewsdataIO\Exception\NewsdataException;

$client = new NewsdataApi(NEWSDATA_API_KEY);

try {
    $response = $client->get_latest_news([
        'q'        => 'bitcoin',
        'country'  => ['us', 'gb'],   // string or array of strings
        'language' => 'en',
    ]);

    foreach ($response->results as $article) {
        echo $article->title, PHP_EOL;
    }
} catch (NewsdataException $e) {
    echo 'Request failed: ', $e->getMessage(), PHP_EOL;
}
```

Pass `['language' => ['en', 'fr']]` and the array is sent comma-separated. By default the response is decoded to objects; call `$client->setDecodeJsonAsArray(true)` to get associative arrays instead.

Endpoints
---------

[](#endpoints)

MethodEndpointNotes`get_latest_news($data)``/1/latest`Real-time news`news_archive($data)``/1/archive`Historical news`news_sources($data)``/1/sources`Available sources`get_crypto_news($data)``/1/crypto`Cryptocurrency news`get_market_news($data)``/1/market`Market / financial news`get_news_count($data)``/1/count`Aggregate counts (requires `from_date`, `to_date`)`get_crypto_count($data)``/1/crypto/count`Aggregate crypto counts (requires dates)`get_market_count($data)``/1/market/count`Aggregate market counts (requires dates)Each `$data` value may be a single string or an array of strings. Parameter names are case-insensitive. See the [Newsdata.io documentation](https://newsdata.io/documentation) — or the [OpenAPI 3.1 spec](https://newsdata.io/openapi.json) — for the full parameter reference per endpoint.

```
$client->get_market_news(['q' => 'apple', 'symbol' => 'AAPL']);

$client->get_news_count([
    'from_date' => '2024-01-01',
    'to_date'   => '2024-01-31',
    'interval'  => 'day',
]);
```

### Raw query

[](#raw-query)

To pass a query string or full URL verbatim, use `raw_query`. It is mutually exclusive with every other parameter and is validated against the endpoint's allowed keys:

```
$client->get_latest_news(['raw_query' => 'q=bitcoin&country=us&language=en']);
```

Client-side validation
----------------------

[](#client-side-validation)

Before any request is sent, parameters are validated and normalized. A `NewsdataValidationError` is raised (without spending API quota) when:

- a parameter is not accepted by that endpoint;
- mutually-exclusive parameters are set together — `q`/`qInTitle`/`qInMeta`, `country`/`excludecountry`, `category`/`excludecategory`, `language`/`excludelanguage`, `domain`/`domainurl`/`excludedomain`;
- `size` is outside 1–50;
- `sentiment_score` is set without `sentiment`;
- a count endpoint is missing `from_date` or `to_date`.

Booleans (`full_content`, `image`, `video`, `removeduplicate`) are coerced to `1` / `0`.

Error handling
--------------

[](#error-handling)

```
use NewsdataIO\Exception\NewsdataValidationError;
use NewsdataIO\Exception\NewsdataAuthError;
use NewsdataIO\Exception\NewsdataRateLimitError;
use NewsdataIO\Exception\NewsdataAPIError;
use NewsdataIO\Exception\NewsdataNetworkError;

try {
    $client->get_latest_news(['q' => 'news']);
} catch (NewsdataValidationError $e) {
    // bad parameter — $e->getParam()
} catch (NewsdataAuthError $e) {
    // 401 / 403
} catch (NewsdataRateLimitError $e) {
    // 429 — $e->getRetryAfter()
} catch (NewsdataAPIError $e) {
    // other API error — $e->getStatusCode(), $e->getResponseBody()
} catch (NewsdataNetworkError $e) {
    // cURL / connectivity failure
}
```

Hierarchy (all under the `NewsdataIO\Exception` namespace):

```
NewsdataException                       (catch-all base)
├── NewsdataValidationError             (getParam())
├── NewsdataAPIError                    (getStatusCode(), getResponseBody())
│   ├── NewsdataAuthError               (401 / 403)
│   ├── NewsdataRateLimitError          (429; getRetryAfter())
│   └── NewsdataServerError             (5xx)
└── NewsdataNetworkError                (cURL / connectivity)

```

Configuration
-------------

[](#configuration)

```
$client->setTimeouts($connectSeconds = 10, $totalSeconds = 30);
$client->setRetries($maxAttempts = 5, $backoffBaseSeconds = 2.0);
$client->setRetryBackoffMax($seconds = 60.0);
$client->setDecodeJsonAsArray(true);
$client->setProxy([
    'CURLOPT_PROXY'        => 'proxy.example.com',
    'CURLOPT_PROXYPORT'    => 8080,
    'CURLOPT_PROXYUSERPWD' => 'user:pass',
]);
$client->setLogger($psr3Logger);   // API key is redacted from logged URLs
```

Retries cover network errors, HTTP 429, and 5xx responses. 429 honors the `Retry-After` header (integer seconds or HTTP-date); otherwise backoff is exponential (`2s → 4s → 8s …`, capped). Auth and other 4xx errors are never retried.

Response metadata for the most recent call:

```
$client->getLastResponse()->getHttpCode();
$client->getLastResponse()->getHeaders();
```

Development
-----------

[](#development)

```
composer install
composer test        # or: vendor/bin/phpunit
```

The test suite (`tests/`) covers the parameter validator and runs entirely offline — no API key required.

Related libraries
-----------------

[](#related-libraries)

Official Newsdata.io clients across languages and runtimes:

- **Python** — [newsdataapi/python-client](https://github.com/newsdataapi/python-client) ([PyPI](https://pypi.org/project/newsdataapi/))
- **Node.js** — [newsdataapi/newsdata-nodejs-client](https://github.com/newsdataapi/newsdata-nodejs-client) ([npm](https://www.npmjs.com/package/newsdata-nodejs-client))
- **React (hooks)** — [newsdataapi/newsdata-reactjs-client](https://github.com/newsdataapi/newsdata-reactjs-client) ([npm](https://www.npmjs.com/package/newsdataapi))
- **Java** — [newsdataapi/newsdata-java-sdk](https://github.com/newsdataapi/newsdata-java-sdk) ([Maven Central](https://central.sonatype.com/artifact/io.newsdata/newsdataapi))
- **.NET** — [newsdataapi/newsdata-dotnet-sdk](https://github.com/newsdataapi/newsdata-dotnet-sdk) ([NuGet](https://www.nuget.org/packages/Newsdata.Api/))
- **Go** — [newsdataapi/newsdata-go-client](https://github.com/newsdataapi/newsdata-go-client) ([pkg.go.dev](https://pkg.go.dev/github.com/newsdataapi/newsdata-go-client))
- **Dart / Flutter** — [newsdataapi/newsdata-flutter-client](https://github.com/newsdataapi/newsdata-flutter-client) ([pub.dev](https://pub.dev/packages/newsdataapi))
- **MCP Server (AI assistants)** — [newsdataapi/newsdata.io-mcp](https://github.com/newsdataapi/newsdata.io-mcp) ([PyPI](https://pypi.org/project/newsdata-mcp/))

Also see [free news datasets](https://github.com/newsdataapi/newsdata.io-free-datasets) for ML / NLP work.

License
-------

[](#license)

[MIT](https://github.com/newsdataapi/php-client/blob/main/LICENSE).

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance94

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 61.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~562 days

Total

4

Last Release

38d ago

Major Versions

0.1.1 → 1.0.02026-05-27

PHP version history (2 changes)0.1.0PHP ^7.3 || ^7.4 || ^8.0

1.0.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/11637aa37394dc2252e96f940d378899f491a5e3c83027b6072172b812b9a03d?d=identicon)[newsdata](/maintainers/newsdata)

---

Top Contributors

[![arjunjain](https://avatars.githubusercontent.com/u/532104?v=4)](https://github.com/arjunjain "arjunjain (8 commits)")[![tarunrana1998](https://avatars.githubusercontent.com/u/36396750?v=4)](https://github.com/tarunrana1998 "tarunrana1998 (4 commits)")[![newsdataapi](https://avatars.githubusercontent.com/u/81237429?v=4)](https://github.com/newsdataapi "newsdataapi (1 commits)")

---

Tags

api-clientcrypto-newsfinancial-newsmarket-newsnewsnews-aggregatornews-apinewsdatanewsdata-iophpphp-clientphp-sdkrest-apisdkapisdkcryptoarchive newslatestcountmarketsourceshistoricalnewsdata

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/newsdataio-newsdataapi/health.svg)

```
[![Health](https://phpackages.com/badges/newsdataio-newsdataapi/health.svg)](https://phpackages.com/packages/newsdataio-newsdataapi)
```

###  Alternatives

[manamine/php-eos-rpc-sdk

PHP SDK for the EOS RPC API

187.5k](/packages/manamine-php-eos-rpc-sdk)[mocking-magician/coinbase-pro-sdk

Library for coinbase pro API calls

223.2k](/packages/mocking-magician-coinbase-pro-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
