Get Automatic Platform Optimization for WordPress setting

[Automatic Platform Optimization for WordPress](https://developers.cloudflare.com/automatic-platform-optimization/) serves your WordPress site from Cloudflare's edge network and caches third-party fonts.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get Automatic Platform Optimization for WordPress setting
8
 * [Automatic Platform Optimization for WordPress](https://developers.cloudflare.com/automatic-platform-optimization/)
9
serves your WordPress site from Cloudflare's edge network and caches
10
third-party fonts.
11

12
 */
13
export async function main(auth: Cloudflare, zone_identifier: string) {
14
  const url = new URL(
15
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/settings/automatic_platform_optimization`
16
  );
17

18
  const response = await fetch(url, {
19
    method: "GET",
20
    headers: {
21
      "X-AUTH-EMAIL": auth.email,
22
      "X-AUTH-KEY": auth.key,
23
      Authorization: "Bearer " + auth.token,
24
    },
25
    body: undefined,
26
  });
27
  if (!response.ok) {
28
    const text = await response.text();
29
    throw new Error(`${response.status} ${text}`);
30
  }
31
  return await response.json();
32
}
33