type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Create Subscription
* Creates an account subscription.
*/
export async function main(
auth: Cloudflare,
account_identifier: string,
body: {
app?: { install_id?: string; [k: string]: unknown };
component_values?: {
default?: number;
name?: string;
price?: number;
value?: number;
[k: string]: unknown;
}[];
currency?: string;
current_period_end?: string;
current_period_start?: string;
frequency?: "weekly" | "monthly" | "quarterly" | "yearly";
id?: string;
price?: number;
rate_plan?: {
currency?: string;
externally_managed?: boolean;
id?: { [k: string]: unknown };
is_contract?: boolean;
public_name?: string;
scope?: string;
sets?: string[];
[k: string]: unknown;
};
state?:
| "Trial"
| "Provisioned"
| "Paid"
| "AwaitingPayment"
| "Cancelled"
| "Failed"
| "Expired";
zone?: { id?: string; name?: string; [k: string]: unknown };
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/subscriptions`
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Create Subscription
* Creates an account subscription.
*/
export async function main(
auth: Cloudflare,
account_identifier: string,
body: {
app?: { install_id?: string; [k: string]: unknown };
component_values?: {
default?: number;
name?: string;
price?: number;
value?: number;
[k: string]: unknown;
}[];
currency?: string;
current_period_end?: string;
current_period_start?: string;
frequency?: "weekly" | "monthly" | "quarterly" | "yearly";
id?: string;
price?: number;
rate_plan?: {
currency?: string;
externally_managed?: boolean;
id?: { [k: string]: unknown };
is_contract?: boolean;
public_name?: string;
scope?: string;
sets?: string[];
[k: string]: unknown;
};
state?:
| "Trial"
| "Provisioned"
| "Paid"
| "AwaitingPayment"
| "Cancelled"
| "Failed"
| "Expired";
zone?: { id?: string; name?: string; [k: string]: unknown };
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/accounts/${account_identifier}/subscriptions`
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago