Build a URL and article body for the publish-article request.
Apple News Format
Apple News API
To publish an article to your channel, you make a multipart POST request consisting of at least one MIME part named article.json. You provide additional parts for each resource that uses a URL in the format bundle:// URL. See Create an Article.
On this page, you'll learn how to:
Build a publish-article URL.
Build the article body.
(Optional) Include a metadata.json file.
Send the publish-article request.
Copy This Code
Open any text editor to copy this code. Save the file as create_article.py.
Create the Metadata File
This step is optional. You might want to include a metadata file to provide additional data about the article.
To create the metadata file, open any text editor and include optional metadata fields. Save the file as metadata.json. For information about supported metadata fields, see Create Article Metadata Fields.
This is an example metadata.json file.
Run the Script
Start the command prompt and change to the directory containing create_article.py. Run this script to make a Create an Article request to the Apple News API. This script takes five arguments: API URL (https://news-api.apple.com), Channel ID, Key ID, Secret, and the path to the article directory.
The ArticleResponse object is returned. For more information, see Article, ArticleLinks, and Meta.
How it Works
To publish an article, the publish-article URL is built using the POST method.
Next, the request body is built and the content type is set. The body contains one or more parts based on the number of files in your article and the content type, as shown here:
Next, a boundary is created to separate the request parts, as shown here. This is a unique string.
Next, the content type is declared along with the boundary, as shown here:
The content type looks like this:
Next, the MIME parts are built for each file in the article you want to publish.
Once the file type is determined, each part is constructed from Content-Type, Content-Disposition, and the file data, as shown here. If you include the metadata.json file, the Content-Disposition header adds name=metadata to ensure that the system recognizes the metadata for the article.
A part looks like this:
Next, the parts are joined together and the end of the multipart form data is denoted by the boundary, preceded by two dashes (--).
Finally, the canonical request is combined with the request body and the request is made.