Automattic / Automattic/jetpack

JSON API: allow more query parameters

Open
#5,860 4 comments 0 reactions 0 assignees View on GitHub
[Feature] WPCOM API [Pri] Normal [Status] Stale Bug Customer Report [LEGACY]
Dominant language
PHP
Stars
1.8k
Forks
898
Avg merge
1d 18h
Merged PRs (30d)
774

Description

`wpcom_json_api_request_as_blog()` is currently used by Jetpack itself, but can also be used by third-party plugin authors via functions like `stats_get_from_restapi()`.

Unfortunately, one cannot make custom API queries via `stats_get_from_restapi()` right now, because the query parameters are filtered out here:
https://github.com/Automattic/jetpack/blob/4.4.2/class.jetpack-client.php#L273

Would it be possible to allow more parameters, so one can do requests like this for example:

```php
// Retrieve the 50 more popular posts every week in the past 7 weeks.
$args = array(
'num' => 7,
'period' => 'week',
'max' => 50,
);
$stats = stats_get_from_restapi( $args, 'top-posts' );
```

Reported in 2872802-t

Contributor guide

Open the contributing guide

Research direction

Start in class.jetpack-client.php at the linked filtering code around line 273, then trace how wpcom_json_api_request_as_blog() and stats_get_from_restapi() pass query arguments. Confirm the filtering prevents the example parameters from reaching the JSON API; done means custom parameters such as num, period, and max are accepted without removing existing safeguards.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Feature
Difficulty
2/5
Estimated time
Half a day
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.