Skip to content

Commit f44de0b

Browse files
docs: Clarify supported post types and update usage examples in README.md and api-documentation.md
- Added details to specify that only posts and products are supported for the `post_id` parameter, excluding pages. - Updated cURL examples to reflect correct usage with real post/product IDs and Application Passwords. - Enhanced error handling documentation to include specific cases for invalid `post_id`.
1 parent 6b6935d commit f44de0b

2 files changed

Lines changed: 66 additions & 14 deletions

File tree

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ This extension enhances the WordPress REST API with custom endpoints that allow
3333

3434
Updates Rank Math SEO metadata for a specific post or product.
3535

36+
**Supported post types:** Only **posts** (`post`) and **products** (`product`, if WooCommerce is active). Page IDs are not accepted and will return a validation error.
37+
3638
**Parameters:**
3739

38-
- `post_id` (required) - ID of the post/product
40+
- `post_id` (required) - ID of the post or product (must be a post or product, not a page)
3941
- `rank_math_title` (optional) - SEO title
4042
- `rank_math_description` (optional) - SEO description
4143
- `rank_math_canonical_url` (optional) - Canonical URL
@@ -46,10 +48,12 @@ Updates Rank Math SEO metadata for a specific post or product.
4648
```bash
4749
curl -X POST "https://example.com/wp-json/rank-math-api/v1/update-meta" \
4850
-H "Content-Type: application/x-www-form-urlencoded" \
49-
-H "Authorization: Basic [base64-encoded-credentials]" \
50-
-d "post_id=123&rank_math_title=Optimized title&rank_math_description=SEO description&rank_math_focus_keyword=keyword"
51+
--user "USERNAME:APPLICATION_PASSWORD" \
52+
-d "post_id=14&rank_math_title=Optimized title&rank_math_description=SEO description&rank_math_focus_keyword=keyword"
5153
```
5254

55+
Replace `USERNAME` and `APPLICATION_PASSWORD` with your WordPress username and [Application Password](https://wordpress.org/documentation/article/application-passwords/). Use a real **post** (or product) ID; page IDs are not supported.
56+
5357
**Response:**
5458

5559
```json
@@ -381,7 +385,7 @@ A: Check that the Application Password is correctly configured and that the user
381385
A: Verify that the plugin is active and that the WordPress REST API is available.
382386

383387
**Q: I get 400 Bad Request errors?**
384-
A: Check that the `post_id` exists and that all parameters are correctly formatted.
388+
A: Ensure `post_id` is a **post** or **product** (pages are not supported). Check that the post exists and that all parameters are correctly formatted.
385389

386390
**Q: WooCommerce integration doesn't work?**
387391
A: Check that WooCommerce is installed and activated.
@@ -412,6 +416,7 @@ A: Yes, webhook support is planned for phase 3.
412416
- Verify that the REST API is available
413417

414418
3. **400 Bad Request**
419+
- Ensure `post_id` is a **post** or **product** (not a page)
415420
- Check that `post_id` exists
416421
- Validate that all parameters are correctly formatted
417422

docs/api-documentation.md

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,35 @@ POST /wp-json/rank-math-api/v1/update-meta
7070

7171
| Parameter | Type | Required | Description | Example |
7272
| ------------------------- | ------- | -------- | ------------------------------------ | ---------------------------------------------------------------------------------- |
73-
| `post_id` | integer | Yes | ID of the post or product | `123` |
73+
| `post_id` | integer | Yes | ID of the post or product | `14` |
7474
| `rank_math_title` | string | No | SEO title (max 60 characters) | `"How to Optimize WordPress SEO"` |
7575
| `rank_math_description` | string | No | SEO description (max 160 characters) | `"Learn the best practices for optimizing your WordPress site for search engines"` |
7676
| `rank_math_canonical_url` | URL | No | Canonical URL | `"https://example.com/post-url"` |
7777
| `rank_math_focus_keyword` | string | No | Primary focus keyword | `"WordPress SEO optimization"` |
7878

79+
**Supported post types:** Only **posts** (`post`) and **products** (`product`, if WooCommerce is active). The `post_id` must refer to one of these. Page IDs and other post types will return `rest_invalid_param`.
80+
7981
#### Request Examples
8082

81-
##### cURL
83+
##### Quick test (local or production)
84+
85+
Use a real **post** (or product) ID; page IDs are not supported. Replace the URL and credentials with your site and [Application Password](https://wordpress.org/documentation/article/application-passwords/).
86+
87+
```bash
88+
# Local (e.g. Local by Flywheel)
89+
curl -X POST "http://devora-ny.local/wp-json/rank-math-api/v1/update-meta" \
90+
-H "Content-Type: application/x-www-form-urlencoded" \
91+
--user "YOUR_USERNAME:YOUR_APPLICATION_PASSWORD" \
92+
-d "post_id=14&rank_math_title=Test title&rank_math_description=Test description&rank_math_focus_keyword=test keyword"
93+
94+
# Production
95+
curl -X POST "https://your-site.com/wp-json/rank-math-api/v1/update-meta" \
96+
-H "Content-Type: application/x-www-form-urlencoded" \
97+
--user "YOUR_USERNAME:YOUR_APPLICATION_PASSWORD" \
98+
-d "post_id=14&rank_math_title=Test title&rank_math_description=Test description&rank_math_focus_keyword=test keyword"
99+
```
100+
101+
##### cURL (with Base64 Authorization header)
82102

83103
```bash
84104
curl -X POST "https://your-site.com/wp-json/rank-math-api/v1/update-meta" \
@@ -235,6 +255,21 @@ except Exception as e:
235255
236256
###### 400 Bad Request
237257
258+
Invalid `post_id` (e.g. not a post/product, or parameter invalid):
259+
260+
```json
261+
{
262+
"code": "rest_invalid_param",
263+
"message": "Invalid parameter(s): post_id",
264+
"data": {
265+
"status": 400,
266+
"params": { "post_id": "Invalid parameter." }
267+
}
268+
}
269+
```
270+
271+
No metadata was updated:
272+
238273
```json
239274
{
240275
"code": "no_update",
@@ -310,12 +345,13 @@ The plugin uses WordPress's default CORS settings. For enhanced security, consid
310345
311346
### Common Error Codes
312347
313-
| Error Code | HTTP Status | Description | Solution |
314-
| --------------------- | ----------- | ------------------------------------------------- | -------------------------------------- |
315-
| `rest_forbidden` | 401 | Authentication failed or insufficient permissions | Check credentials and user permissions |
316-
| `rest_post_not_found` | 404 | Post ID does not exist | Verify the post ID is correct |
317-
| `no_update` | 400 | No metadata was updated | Ensure at least one field is provided |
318-
| `rest_no_route` | 404 | Endpoint not found | Verify the plugin is activated |
348+
| Error Code | HTTP Status | Description | Solution |
349+
| --------------------- | ----------- | ------------------------------------------------- | ------------------------------------------------------------------------ |
350+
| `rest_forbidden` | 401 | Authentication failed or insufficient permissions | Check credentials and user permissions |
351+
| `rest_post_not_found` | 404 | Post ID does not exist | Verify the post ID is correct |
352+
| `rest_invalid_param` | 400 | Invalid `post_id` (e.g. page ID or wrong type) | Use a **post** or **product** ID; pages are not supported |
353+
| `no_update` | 400 | No metadata was updated | Ensure at least one field is provided |
354+
| `rest_no_route` | 404 | Endpoint not found | Verify the plugin is activated |
319355
320356
### Error Handling Examples
321357
@@ -453,12 +489,23 @@ Expected response:
453489
454490
### Test Valid Request
455491
492+
Use a real **post** (or product) ID. Page IDs will return `rest_invalid_param`.
493+
494+
```bash
495+
# Using --user (curl encodes credentials as Basic auth)
496+
curl -X POST "https://your-site.com/wp-json/rank-math-api/v1/update-meta" \
497+
-H "Content-Type: application/x-www-form-urlencoded" \
498+
--user "USERNAME:APPLICATION_PASSWORD" \
499+
-d "post_id=14&rank_math_title=Test Title&rank_math_description=Test description&rank_math_focus_keyword=test"
500+
```
501+
502+
Alternative with explicit Basic header:
503+
456504
```bash
457-
# Test with valid credentials and data
458505
curl -X POST "https://your-site.com/wp-json/rank-math-api/v1/update-meta" \
459506
-H "Content-Type: application/x-www-form-urlencoded" \
460507
-H "Authorization: Basic [base64-encoded-credentials]" \
461-
-d "post_id=123&rank_math_title=Test Title"
508+
-d "post_id=14&rank_math_title=Test Title"
462509
```
463510
464511
Expected response:

0 commit comments

Comments
 (0)