Skip to content

Add API v2 support; move the real-time service to v2 - #16

Merged
arjunjain merged 1 commit into
mainfrom
api-v2
Nov 25, 2026
Merged

arjunjain merged 1 commit into
mainfrom
api-v2

Conversation

@arjunjain

Copy link
Copy Markdown
Collaborator

Adds the v2 endpoints (newsV2, marketV2, cryptoV2, sourcesV2 and the three count endpoints) alongside v1, each taking v2's snake_case filter vocabulary: source_url / exclude_source_url replace the four domain filters, source_priority replaces prioritydomain, and content replaces full_content. There is no /2/archive — newsV2 covers historical news through from_date / to_date. Responses read v2's total_results / next_page as well as v1's totalResults / nextPage, so callers need not branch on the version.

A 429 whose body says the API credits are exhausted is no longer retried and now throws NewsdataApiLimitExceededError (the account's whole pool) or NewsdataApiKeyLimitExceededError (this one key's cap). Both extend NewsdataRateLimitError, so existing catches keep working.

Breaking

  • The real-time service moved to API v2. The management endpoints are now /2/websocket/{register,fetch,delete}, news_type is news rather than latest, and websocketRegister takes the v2 filter vocabulary. Streamed responses and websocketFetch now carry total_results, and websocketFetch answers with a flat results list (one entry per query, each with a new last_used timestamp) rather than nesting it under results['queries']. RegistrationLimitExceeded — every registration the plan allows is in use — is likewise never retried, but keeps the plain NewsdataRateLimitError, since it is about slots rather than credits.
  • The base URL is now the API root without a version segment (https://newsdata.io/api/); the endpoint paths carry 1/ or 2/. Drop the trailing 1/ if you override it.

Because this breaks the public surface and the package is on 1.2.1, it is intended to release as 2.0.0, matching the reactjs client.

Verification

phpunit 83 tests / 153 assertions OK; phpstan reports no errors; php-cs-fixer finds 0 of 32 files to fix.

Adds the v2 endpoints (newsV2, marketV2, cryptoV2, sourcesV2 and the three
count endpoints) alongside v1, each taking v2's snake_case filter vocabulary:
source_url / exclude_source_url replace the four domain filters,
source_priority replaces prioritydomain, and content replaces full_content.
There is no /2/archive — newsV2 covers historical news through from_date /
to_date. Responses read v2's total_results / next_page as well as v1's
totalResults / nextPage, so callers need not branch on the version.

A 429 whose body says the API credits are exhausted is no longer retried and
now throws NewsdataApiLimitExceededError (the account's whole pool) or
NewsdataApiKeyLimitExceededError (this one key's cap). Both extend
NewsdataRateLimitError, so existing catches keep working.

BREAKING: the real-time service moved to API v2. The management endpoints are
now /2/websocket/{register,fetch,delete}, news_type is "news" rather than
"latest", and websocketRegister takes the v2 filter vocabulary. Streamed
responses and websocketFetch now carry total_results, and websocketFetch
answers with a flat results list (one entry per query, each with a new
last_used timestamp) rather than nesting it under results['queries'].
RegistrationLimitExceeded — every registration the plan allows is in use — is
likewise never retried, but keeps the plain NewsdataRateLimitError, since it
is about slots rather than credits.

BREAKING: the base URL is now the API root without a version segment
(https://newsdata.io/api/); the endpoint paths carry 1/ or 2/. Drop the
trailing 1/ if you override it.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 15.38462% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/NewsdataApi.php 0.00% 14 Missing ⚠️
src/NewsdataApiBase.php 33.33% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

@arjunjain
arjunjain merged commit a60a1d2 into main Nov 25, 2026
9 checks passed
@arjunjain
arjunjain deleted the api-v2 branch November 25, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants