Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There has been an error with the Apple News API: INVALID_DOCUMENT - (null or null (JSON) or Property was not an array (JSON)) (keyPath metadata->authors) #1156

Open
fernandogarciarc opened this issue Sep 4, 2024 · 4 comments

Comments

@fernandogarciarc
Copy link

fernandogarciarc commented Sep 4, 2024

Description of the bug

Hello,
I'm dropping this question here because I haven't seen any similar issues in this forum.

Whenever one publishes a post (and as far as I could test, this is only for a particular post type - Micropost), we got the error: "There has been an error with the Apple News API: INVALID_DOCUMENT - (null or null (JSON) or Property was not an array (JSON)) (keyPath metadata->authors)"

I already checked if the authors are set for this post type, and they are, so I have no idea why this is happening. I'm hoping to have some guidance here.

Here's the code from the "debug" option for the try (I see the authors coming as "1", but have no idea how to fix it):

Article: {
    "version": "1.11",
    "identifier": "post-986015",
    "language": "en-US",
    "title": "Here's the latest vexing Dak Prescott contract update",
    "documentStyle": {
        "backgroundColor": "#ffffff",
        "conditional": {
            "backgroundColor": "#000000",
            "conditions": {
                "minSpecVersion": "1.14",
                "preferredColorScheme": "dark"
            }
        }
    },
    "layout": {
        "columns": 9,
        "width": 1024,
        "margin": 50,
        "gutter": 20
    },
    "components": [
        {
            "role": "heading",
            "text": "[Football](https://www.dmagazine.com/%22https://www.dmagazine.com/category/football//%22)",
            "format": "html",
            "textStyle": "kicker",
            "layout": {
                "margin": {
                    "top": 10,
                    "bottom": 10
                }
            }
        },
        {
            "role": "title",
            "text": "Here’s the latest vexing Dak Prescott contract update",
            "format": "html",
            "textStyle": "default-title",
            "layout": "title-layout"
        },
        {
            "role": "byline",
            "text": "By Mike Piellucci   |   Sep 3, 2024   |   12:10 PM",
            "format": "html",
            "textStyle": "default-byline",
            "layout": "byline-layout"
        },
        {
            "role": "body",
            "text": "
If you, like me, are baffled that this contract stalemate is going strong less than a week before the season opener, prepare to be even more baffled by this report from The Athletic\u2019s Dianna Russini on her [Scoop City podcast](https://www.dmagazine.com/%22https://podcasts.apple.com/us/podcast/scoop-city-a-show-about-the-nfl/id1756145167/%22):

",
            "format": "html",
            "textStyle": "dropcapBodyStyle",
            "layout": "body-layout"
        },
        {
            "role": "tweet",
            "URL": "https://twitter.com/rjochoa/status/1830956464233464242",
            "layout": "tweet-layout"
        },
        {
            "role": "body",
            "text": "
For those not inclined to open the tweet, the TL;DR is that Prescott wants more time on a new deal while the Cowboys are pushing for less. That\u2019s the inverse of the reported stalemate on the term of CeeDee Lamb\u2019s now-completed extension\u2014Dallas [wanted more years](https://www.dmagazine.com/%22https://x.com/MySportsUpdate/status/1828131079091560932/%22) than Lamb preferred\u2014and even less sensical considering Prescott just turned 31 and is playing a position where teams are so starved for competence that Kirk Cousins landed a four-year deal as a 36-year-old fresh off a torn Achilles.

",
            "format": "html",
            "textStyle": "default-body",
            "layout": "body-layout"
        },
        {
            "role": "body",
            "text": "
Also fileable under \u201cstarved for competence\u201d: this franchise\u2019s front office. Last year\u2019s MVP runner-up needs a new deal, or he hits unrestricted free agency next year with no safety net or succession plan in place (unless you\u2019re still into [the Trey Lance experience](https://www.dmagazine.com/%22https://www.dmagazine.com/sports/2024/08/cowboys-bland-lance-nfl-preseason//%22)). Prescott holds the cards here, not the Cowboys. If an extra year or two is the holdup, the Joneses would do well to sign off instead of testing just how ugly the future could look should Prescott play his hand and skip town next spring.

",
            "format": "html",
            "textStyle": "default-body",
            "layout": "body-layout-last"
        }
    ],
    "componentTextStyles": {
        "dropcapBodyStyle": {
            "textAlignment": "left",
            "fontName": "FinancierText-Regular",
            "fontSize": 20,
            "tracking": 0,
            "lineHeight": 28,
            "textColor": "#1a1a1a",
            "linkStyle": {
                "textColor": "#ff291c"
            },
            "paragraphSpacingBefore": 18,
            "paragraphSpacingAfter": 18,
            "dropCapStyle": {
                "numberOfLines": 3,
                "numberOfCharacters": 1,
                "padding": 10,
                "fontName": "FinancierDisplay-Regular",
                "textColor": "#ffffff",
                "numberOfRaisedLines": 0,
                "backgroundColor": "#1a1a1a"
            },
            "conditional": [
                {
                    "dropCapStyle": {
                        "numberOfLines": 3,
                        "textColor": "#1a1a1a",
                        "backgroundColor": "#ffffff"
                    },
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "preferredColorScheme": "dark"
                    },
                    "textColor": "#ffffff",
                    "linkStyle": {
                        "textColor": "#ff291c"
                    }
                },
                {
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "horizontalSizeClass": "compact"
                    },
                    "dropCapStyle": {
                        "numberOfLines": 4,
                        "padding": 15
                    }
                }
            ]
        },
        "default-body": {
            "textAlignment": "left",
            "fontName": "FinancierText-Regular",
            "fontSize": 20,
            "tracking": 0,
            "lineHeight": 28,
            "textColor": "#1a1a1a",
            "linkStyle": {
                "textColor": "#ff291c"
            },
            "paragraphSpacingBefore": 18,
            "paragraphSpacingAfter": 18,
            "conditional": {
                "conditions": {
                    "minSpecVersion": "1.14",
                    "preferredColorScheme": "dark"
                },
                "textColor": "#ffffff",
                "linkStyle": {
                    "textColor": "#ff291c"
                }
            }
        },
        "default-title": {
            "fontName": "FinancierDisplay-Regular",
            "fontSize": 48,
            "lineHeight": 52,
            "tracking": 0,
            "textColor": "#1a1a1a",
            "textAlignment": "left",
            "conditional": {
                "textColor": "#ffffff",
                "conditions": {
                    "minSpecVersion": "1.14",
                    "preferredColorScheme": "dark"
                }
            }
        },
        "default-byline": {
            "textAlignment": "left",
            "fontName": "FoundersGroteskRegular",
            "fontSize": 16,
            "lineHeight": 22,
            "tracking": 0,
            "textColor": "#808080",
            "conditional": [
                {
                    "textColor": "#808080",
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "preferredColorScheme": "dark"
                    }
                },
                {
                    "linkStyle": {
                        "textColor": "#828282"
                    },
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "preferredColorScheme": "dark"
                    }
                }
            ],
            "linkStyle": {
                "textColor": "#828282"
            }
        },
        "kicker": {
            "textAlignment": "left",
            "fontName": "FoundersGroteskRegular",
            "fontSize": 16,
            "lineHeight": 22,
            "tracking": 0,
            "textColor": "#ff291c",
            "linkStyle": {
                "textColor": "#ff291c"
            }
        },
        "subhead": {
            "textAlignment": "left",
            "fontName": "FoundersGroteskRegular",
            "fontSize": 19,
            "lineHeight": 23,
            "tracking": 0,
            "textColor": "#808080",
            "conditional": [
                {
                    "textColor": "#808080",
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "preferredColorScheme": "dark"
                    }
                },
                {
                    "linkStyle": {
                        "textColor": "#828282"
                    },
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "preferredColorScheme": "dark"
                    }
                }
            ],
            "linkStyle": {
                "textColor": "#828282"
            }
        }
    },
    "textStyles": {
        "default-tag-cite": {
            "fontName": "FoundersGroteskRegular",
            "fontSize": 16,
            "tracking": 0,
            "lineHeight": 20,
            "textColor": "#808080",
            "conditional": {
                "textColor": "#808080",
                "conditions": {
                    "minSpecVersion": "1.14",
                    "preferredColorScheme": "dark"
                }
            }
        },
        "default-tag-code": {
            "fontName": "Menlo-Regular",
            "fontSize": 16,
            "tracking": 0,
            "lineHeight": 20,
            "textColor": "#4f4f4f"
        },
        "default-tag-pre": {
            "textAlignment": "left",
            "fontName": "Menlo-Regular",
            "fontSize": 16,
            "tracking": 0,
            "lineHeight": 20,
            "textColor": "#4f4f4f",
            "paragraphSpacingBefore": 18,
            "paragraphSpacingAfter": 18
        },
        "default-tag-samp": {
            "fontName": "Menlo-Regular",
            "fontSize": 16,
            "tracking": 0,
            "lineHeight": 20,
            "textColor": "#4f4f4f"
        }
    },
    "componentLayouts": {
        "body-layout": {
            "columnStart": 1,
            "columnSpan": 7,
            "margin": {
                "top": 12,
                "bottom": 12
            },
            "conditional": [
                {
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "platform": "ios"
                    },
                    "columnStart": 0,
                    "columnSpan": 9
                }
            ]
        },
        "body-layout-last": {
            "columnStart": 1,
            "columnSpan": 7,
            "margin": {
                "top": 12,
                "bottom": 30
            },
            "conditional": [
                {
                    "conditions": {
                        "minSpecVersion": "1.14",
                        "platform": "ios"
                    },
                    "columnStart": 0,
                    "columnSpan": 9
                }
            ]
        },
        "tweet-layout": {
            "margin": {
                "top": 30,
                "bottom": 30
            },
            "columnStart": 1,
            "columnSpan": 7
        },
        "title-layout": {
            "margin": {
                "top": 0,
                "bottom": 0
            }
        },
        "byline-layout": {
            "margin": {
                "top": 10,
                "bottom": 10
            },
            "columnStart": 0,
            "columnSpan": 9
        }
    },
    "metadata": {
        "authors": "1",
        "dateCreated": "2024-09-03T17:10:11+00:00",
        "dateModified": "2024-09-03T17:10:20+00:00",
        "datePublished": "2024-09-03T17:10:11+00:00",
        "canonicalURL": "https://www.dmagazine.com/micropost/heres-the-latest-vexing-dak-prescott-contract-update/",
        "generatorIdentifier": "publish-to-apple-news",
        "generatorName": "Publish to Apple News",
        "generatorVersion": "2.5.0"
    }
}
Bundles: []
Meta: {
    "data": {
        "links": {
            "sections": [
                "https://news-api.apple.com/sections/792d5abd-e3c0-42bb-b16f-dee3bb105f6d",
                "https://news-api.apple.com/sections/cdf3fd9e-e4b7-47fa-a4b8-96f171929cdd"
            ]
        }
    }
}

Thanks in advance.

Steps To Reproduce

  1. Create a new post type with the following config:
{
    "key": "post_type_660aff7410cec",
    "title": "Microposts",
    "menu_order": 0,
    "active": true,
    "post_type": "micropost",
    "advanced_configuration": true,
    "import_source": "",
    "import_date": "",
    "labels": {
        "name": "Microposts",
        "singular_name": "Micropost",
        "menu_name": "Microposts",
        "all_items": "All Microposts",
        "edit_item": "Edit Micropost",
        "view_item": "View Micropost",
        "view_items": "View Microposts",
        "add_new_item": "Add New Micropost",
        "add_new": "Add New Micropost",
        "new_item": "New Micropost",
        "parent_item_colon": "Parent Micropost:",
        "search_items": "Search Microposts",
        "not_found": "No microposts found",
        "not_found_in_trash": "No microposts found in Trash",
        "archives": "Micropost Archives",
        "attributes": "Micropost Attributes",
        "featured_image": "",
        "set_featured_image": "",
        "remove_featured_image": "",
        "use_featured_image": "",
        "insert_into_item": "Insert into micropost",
        "uploaded_to_this_item": "Uploaded to this micropost",
        "filter_items_list": "Filter microposts list",
        "filter_by_date": "Filter microposts by date",
        "items_list_navigation": "Microposts list navigation",
        "items_list": "Microposts list",
        "item_published": "Micropost published.",
        "item_published_privately": "Micropost published privately.",
        "item_reverted_to_draft": "Micropost reverted to draft.",
        "item_scheduled": "Micropost scheduled.",
        "item_updated": "Micropost updated.",
        "item_link": "Micropost Link",
        "item_link_description": "A link to a micropost."
    },
    "description": "",
    "public": true,
    "hierarchical": false,
    "exclude_from_search": false,
    "publicly_queryable": true,
    "show_ui": true,
    "show_in_menu": true,
    "admin_menu_parent": "",
    "show_in_admin_bar": true,
    "show_in_nav_menus": true,
    "show_in_rest": true,
    "rest_base": "",
    "rest_namespace": "wp\/v2",
    "rest_controller_class": "WP_REST_Posts_Controller",
    "menu_position": 5,
    "menu_icon": "",
    "rename_capabilities": false,
    "singular_capability_name": "post",
    "plural_capability_name": "posts",
    "supports": [
        "title",
        "author",
        "comments",
        "editor",
        "thumbnail"
    ],
    "taxonomies": [
        "section",
        "category",
        "post_tag"
    ],
    "has_archive": false,
    "has_archive_slug": "",
    "rewrite": {
        "permalink_rewrite": "post_type_key",
        "with_front": "1",
        "feeds": "0",
        "pages": "1"
    },
    "query_var": "post_type_key",
    "query_var_name": "",
    "can_export": true,
    "delete_with_user": false,
    "register_meta_box_cb": "",
    "enter_title_here": "",
    "modified": 1717521417
}
  1. Publish it and wait for Apple News to publish too.
  2. See the error.

Additional Information

When you try to manually "Publish" it, the same error occurs.

@fernandogarciarc fernandogarciarc added the bug Something isn't working label Sep 4, 2024
@kevinfodness
Copy link
Member

The issue is that metadata.authors equals "1" here instead of an array of author data, as would be expected. The plugin is only ever setting this value to an array, as seen here:

// Add authors.
$authors = array_values(
array_filter(
explode(
'APPLE_NEWS_DELIMITER',
Apple_News::get_authors( 'APPLE_NEWS_DELIMITER', 'APPLE_NEWS_DELIMITER' )
)
)
);
if ( ! empty( $authors ) ) {
$meta['authors'] = $authors;
}

I assume you're on the latest available version of the plugin (the 2.5 branch, so 2.5.0 or 2.5.1)? If so, the only explanation that makes sense is that another plugin, or your theme, or custom code you have running on your site, is filtering the output of either the Apple News metadata or the JSON for the entire article and is replacing this value with an invalid one.

@kevinfodness kevinfodness added help wanted and removed bug Something isn't working labels Sep 4, 2024
@fernandogarciarc
Copy link
Author

Thanks for your quick reply.

Yes, it's not Apple News per se, as I initially thought.
I'll try to identify now where this value changes. We have a bunch of different plugins that might be the cause. I'll drop the answer here, then.

@fernandogarciarc
Copy link
Author

fernandogarciarc commented Sep 5, 2024

Ok, I did a series of tests. Here's what I've found so far:

The code snipped you referenced is indeed returning an array. So I started checking layer by layer, and I ended up here, where I think everything starts:

public function get_json() {
$json = get_post_meta( $this->content_id, self::JSON_META_KEY, true );
if ( ! empty( $json ) ) {
$json = wp_json_encode( $json );
}
/**
* Similar to `apple_news_generate_json`, but modifies the JSON as it's
* retrieved from the workspace.
*
* @param string $json The JSON string, after it is retrieved from the workspace.
* @param int $post_id The post ID.
*/
return apply_filters( 'apple_news_get_json', $json, $this->content_id );
}

After debugging the variables, this is what I've got:

$this->content_id: 986124
self::JSON_META_KEY: "apple_news_api_json"
$json: [...]

{
  "authors":"1",
  "dateCreated":"2024-09-04T21:14:12+00:00",
  "dateModified":"2024-09-04T21:25:56+00:00",
  "datePublished":"2024-09-04T21:14:12+00:00",
  "canonicalURL":"MANUALLY_REMOVED_BY_ME_NOW",
  "generatorIdentifier":"publish-to-apple-news",
  "generatorName":"Publish to Apple News",
  "generatorVersion":"2.5.0"
}

[...]

So, I don't know, but this isn't being filtered after. This is being stored in database that way. Maybe this is being filtered before? Any ideas?

Well, I also found 3 different plugins that might be causing it: I looked for any plugins that uses the apply_filters for get_post_metadata and found:

  • Amazon S3 and Cloudflare Pro
  • Heartbeat Control
  • Wordfence

The first two, I don't think they're the cause because of the use case of the applied filters. BUT, the Wordfence plugin has an option enabled: "Prevent discovery of usernames through '/?author=N' scans, the oEmbed API, the WordPress REST API, and WordPress XML Sitemaps"

Is it possible that Wordfence is preventing Apple News to generate the JSON data? Do you know if it uses the REST API?

@kevinfodness
Copy link
Member

That's a good theory - if you're using the block editor (Gutenberg) to edit content, then Apple News does indeed use the REST API to get and set its own metadata when editing content. I'll have to dig into this further to figure out why this is an issue. As a test, could you disable WordFence and try on a new article and see if there's any change? That would at least tell you if that plugin is the source of the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants