How do you fetch the authors email or IP from /comments? (REST API)

Question

Does anyone know how to get the email and IP for WordPress comments using the REST API? The docs. Are the fields just not provided in the response? “author_url” is there. But not “author_email” etc.

import requests
import json
import base64

wordpress_user = "xxx"
wordpress_password = "xA5t xcxN xmxK nxyx Fxgx OxKx"
wordpress_credentials = wordpress_user + ":" + wordpress_password
wordpress_token = base64.b64encode(wordpress_credentials.encode())
wordpress_header = {'Authorization': 'Basic ' + wordpress_token.decode('utf-8')}

api_url="https://[site-here].com/wp-json/wp/v2/comments?status=all"
response = requests.get(api_url, headers = wordpress_header)
response_json = response.json()
if ( response.status_code == 200 ):
    #
    approved_comments_list = []
    unapproved_comments_list = []   
    for j in response_json:
        if j['status'] == 'approved':
            approved_comments_list.append(j)
        elif j['status'] == 'hold':
            unapproved_comments_list.append(j)

for j in unapproved_comments_list:
    comment_url="https://x.com/wp-json/wp/v2/comments/" + str(j['id'])
    response = requests.get(comment_url, headers = wordpress_header)
    response_json = response.json()
    print(json.dumps(response_json, indent=4))

Output:

{
    "id": 122,
    "post": 560,
    "parent": 0,
    "author": 0,
    "author_name": "jeff",
    "author_url": "",
    "date": "2022-11-30T20:50:24",
    "date_gmt": "2022-11-30T20:50:24",
    "content": {
        "rendered": "<p>yo dawg. you suck lol</p>\n"
    },
    "link": "https://x.com/hello-world/comment-page-1/#comment-122",
    "status": "hold",
    "type": "comment",
    "meta": [],
    "_links": {
        "self": [
            {
                "href": "https://x.com/wp-json/wp/v2/comments/122"
            }
        ],
        "collection": [
            {
                "href": "https://x.com/wp-json/wp/v2/comments"
            }
        ],
        "up": [
            {
                "embeddable": true,
                "post_type": "post",
                "href": "https://x.com/wp-json/wp/v2/posts/560"
            }
        ]
    } }

enter image description here

0
baldest_programmer 2 months 2022-12-01T12:16:33-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse