Making an HTTP Request to the Apple News API

Create the URL, set the method, and send the request.


You make an HTTP request to send or receive data from a server. On this page, you'll make the HTTP request to the Apple News API to get details about the channel, including the name, corresponding website, and default section. See Read Channel Information.

On this page, you'll learn how to:

  • Create the URL{channel-id}.

  • Set the method to GET.

  • Send the request.

Copy This Code

Open any text editor to copy this code. Save the file as

import sys
import requests

class PublisherAPI:
    channel_id = ""
    current_action = ""
    url = ""

    def send_request(self, method, url):
        return requests.request(method, url)
    def read_channel(self):
        method = "GET"
        url = self.url + "%s" % self.channel_id
        return self.send_request(method, url)

    def main(self):
        if self.current_action == "readChannel":
            response = self.read_channel()
            response = {
                "status_code": 400,
                "response": "{\"errors\":[{\"code\":\"UNKNOWN_COMMAND\"}]}"
        return response

    if __name__ == '__main__':
    if not len(sys.argv) > 1:
        print('no arguments')

  publisherAPI = PublisherAPI()
  publisherAPI.url = sys.argv[1] + "/channels/"
  publisherAPI.channel_id = sys.argv[2]
  publisherAPI.current_action = "readChannel"

  response = publisherAPI.main()


Run the Script

Start the command prompt and change to the directory containing file. Run this script to make an HTTP request to the Apple News API. This script takes Channel ID as an argument.

$ python channel_id


The script returns this error:


The error indicates that the authorization header was not included in the request.

See Also

Apple News API Python Tutorial

Signing the HTTP Request

Sign the canonical request and send the custom authorization header to the Apple News API.

Publishing an Article

Build a URL and article body for the publish-article request.