Skip to content

Commit 3072bfd

Browse files
authored
Update json-endpoint.mdx (#24587)
* Update json-endpoint.mdx fix typescript example * Update json-endpoint.mdx update `json_schema` to `schema` * Update content-endpoint.mdx fix /content endpoint typescript example * Update screenshot-endpoint.mdx fix /screenshot typescript example * Update content-endpoint.mdx * Update pdf-endpoint.mdx fix /pdf endpoint typescript example * Update snapshot.mdx fix /snapshot endpoint typescript example * Update scrape-endpoint.mdx fix /scrape typescript example. + curl * Update scrape-endpoint.mdx * Update links-endpoint.mdx fix /links endpoint typescript example * Update markdown-endpoint.mdx fix /markdown typescript example
1 parent 7e03e68 commit 3072bfd

File tree

8 files changed

+69
-32
lines changed

8 files changed

+69
-32
lines changed

src/content/docs/browser-rendering/rest-api/content-endpoint.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ The `/content` endpoint instructs the browser to navigate to a website and captu
1313

1414
<Tabs syncKey="workersExamples"> <TabItem label="curl">
1515

16-
Go to `https://example.com` and return the rendered HTML.
16+
Go to `https://developers.cloudflare.com/` and return the rendered HTML.
1717

1818
```bash
1919
curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-rendering/content' \
2020
-H 'Content-Type: application/json' \
2121
-H 'Authorization: Bearer <apiToken>' \
22-
-d '{"url": "https://example.com"}'
22+
-d '{"url": "https://developers.cloudflare.com/"}'
2323
```
2424

2525
</TabItem> <TabItem label="TypeScript SDK">
@@ -28,12 +28,12 @@ curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browse
2828
import Cloudflare from "cloudflare";
2929

3030
const client = new Cloudflare({
31-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
32-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
31+
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
3332
});
3433

3534
const content = await client.browserRendering.content.create({
36-
account_id: "account_id",
35+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
36+
url: "https://developers.cloudflare.com/",
3737
});
3838

3939
console.log(content);

src/content/docs/browser-rendering/rest-api/json-endpoint.mdx

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID
3434
"prompt": "Get me the list of AI products",
3535
"response_format": {
3636
"type": "json_schema",
37-
"json_schema": {
37+
"schema": {
3838
"type": "object",
3939
"properties": {
4040
"products": {
@@ -130,7 +130,7 @@ curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID
130130
--header 'content-type: application/json' \
131131
--data '"response_format": {
132132
"type": "json_schema",
133-
"json_schema": {
133+
"schema": {
134134
"type": "object",
135135
"properties": {
136136
"products": {
@@ -233,14 +233,40 @@ Below is an example using the TypeScript SDK:
233233
import Cloudflare from "cloudflare";
234234

235235
const client = new Cloudflare({
236-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
237-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
236+
apiToken: process.env["CLOUDFLARE_API_TOKEN"], // This is the default and can be omitted
238237
});
239238

240239
const json = await client.browserRendering.json.create({
241-
account_id: "account_id",
242-
});
243-
240+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
241+
url: "https://developers.cloudflare.com/",
242+
prompt: "Get me the list of AI products",
243+
response_format: {
244+
type: "json_schema",
245+
schema: {
246+
type: "object",
247+
properties: {
248+
products: {
249+
type: "array",
250+
items: {
251+
type: "object",
252+
properties: {
253+
name: {
254+
type: "string"
255+
},
256+
link: {
257+
type: "string"
258+
}
259+
},
260+
required: [
261+
"name"
262+
]
263+
}
264+
}
265+
}
266+
}
267+
}
268+
}
269+
);
244270
console.log(json);
245271
```
246272

@@ -267,7 +293,7 @@ curl --request POST \
267293
"prompt": "Get the heading from the page in the form of an object like h1, h2. If there are many headings of the same kind then grab the first one.",
268294
"response_format": {
269295
"type": "json_schema",
270-
"json_schema": {
296+
"schema": {
271297
"type": "object",
272298
"properties": {
273299
"h1": {

src/content/docs/browser-rendering/rest-api/links-endpoint.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
109109
import Cloudflare from "cloudflare";
110110

111111
const client = new Cloudflare({
112-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
113-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
112+
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
114113
});
115114

116115
const links = await client.browserRendering.links.create({
117-
account_id: "account_id",
116+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
117+
url: "https://developers.cloudflare.com/",
118118
});
119119

120120
console.log(links);

src/content/docs/browser-rendering/rest-api/markdown-endpoint.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ curl -X 'POST' 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browse
3939
import Cloudflare from "cloudflare";
4040

4141
const client = new Cloudflare({
42-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
43-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
42+
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
4443
});
4544

4645
const markdown = await client.browserRendering.markdown.create({
47-
account_id: "account_id",
46+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
47+
url: "https://developers.cloudflare.com/",
4848
});
4949

5050
console.log(markdown);

src/content/docs/browser-rendering/rest-api/pdf-endpoint.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
5252
import Cloudflare from "cloudflare";
5353

5454
const client = new Cloudflare({
55-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
56-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
55+
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
5756
});
5857

5958
const pdf = await client.browserRendering.pdf.create({
60-
account_id: "account_id",
59+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
60+
url: "https://example.com/",
61+
addStyleTag: [
62+
{ content: "body { font-family: Arial; }" }
63+
]
6164
});
6265

6366
console.log(pdf);

src/content/docs/browser-rendering/rest-api/scrape-endpoint.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
7474
import Cloudflare from "cloudflare";
7575

7676
const client = new Cloudflare({
77-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
78-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
77+
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
7978
});
8079

8180
const scrapes = await client.browserRendering.scrape.create({
82-
account_id: "account_id",
83-
elements: [{ selector: "selector" }],
81+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
82+
elements: [
83+
{ selector: "h1" },
84+
{ selector: "a" }
85+
]
8486
});
8587

8688
console.log(scrapes);

src/content/docs/browser-rendering/rest-api/screenshot-endpoint.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
3636
import Cloudflare from "cloudflare";
3737

3838
const client = new Cloudflare({
39-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
40-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
39+
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
4140
});
4241

4342
const screenshot = await client.browserRendering.screenshot.create({
44-
account_id: "account_id",
43+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
44+
html: "Hello World!",
45+
screenshotOptions: {
46+
omitBackground: true,
47+
}
4548
});
4649

4750
console.log(screenshot.status);

src/content/docs/browser-rendering/rest-api/snapshot.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,15 @@ curl -X POST 'https://api.cloudflare.com/client/v4/accounts/<accountId>/browser-
4646
import Cloudflare from "cloudflare";
4747

4848
const client = new Cloudflare({
49-
apiEmail: process.env["CLOUDFLARE_EMAIL"], // This is the default and can be omitted
50-
apiKey: process.env["CLOUDFLARE_API_KEY"], // This is the default and can be omitted
49+
apiToken: process.env["CLOUDFLARE_API_TOKEN"],
5150
});
5251

5352
const snapshot = await client.browserRendering.snapshot.create({
54-
account_id: "account_id",
53+
account_id: process.env["CLOUDFLARE_ACCOUNT_ID"],
54+
url: "https://example.com/",
55+
addScriptTag: [
56+
{ content: "document.body.innerHTML = \"Snapshot Page\";" }
57+
]
5558
});
5659

5760
console.log(snapshot.content);

0 commit comments

Comments
 (0)