type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Import DNS Records
* You can upload your [BIND config](https://en.wikipedia.org/wiki/Zone_file "Zone file") through this endpoint. It assumes that cURL is called from a location with bind_config.txt (valid BIND config) present.
See [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/import-and-export/ "Import and export records") for more information.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: { file: string; proxied?: string; [k: string]: unknown }
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/dns_records/import`
);
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== "") {
formData.append(k, String(v));
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: formData,
});
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;
};
/**
* Import DNS Records
* You can upload your [BIND config](https://en.wikipedia.org/wiki/Zone_file "Zone file") through this endpoint. It assumes that cURL is called from a location with bind_config.txt (valid BIND config) present.
See [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/import-and-export/ "Import and export records") for more information.
*/
export async function main(
auth: Cloudflare,
zone_identifier: string,
body: { file: string; proxied?: string; [k: string]: unknown }
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/dns_records/import`
);
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined && v !== "") {
formData.append(k, String(v));
}
}
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: formData,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 810 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* Import DNS Records
* You can upload your [BIND config](https://en.wikipedia.org/wiki/Zone_file "Zone file") through this endpoint. It assumes that cURL is called from a location with bind_config.txt (valid BIND config) present.
See [the documentation](https://developers.cloudflare.com/dns/manage-dns-records/how-to/import-and-export/ "Import and export records") for more information.
*/
export async function main(auth: Cloudflare, zone_identifier: string) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_identifier}/dns_records/import`
);
const response = await fetch(url, {
method: "POST",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago