-
Notifications
You must be signed in to change notification settings - Fork 1
/
hidePages.ts
56 lines (50 loc) · 1.39 KB
/
hidePages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const axios = require('axios');
// --------------------- CHANGE THIS VARIABLE TO FALSE IF YOU WANT TO HIDE THE PAGES IN THE ARRAY -----------------------
const SHOW_IN_SIDE_BAR = true;
// Define an array of pages titles to match
const titlesToMatch = [
'Page1',
'Page2',
'Page3'
// Define the base URL for the API
const API_BASE_URL = 'https://api.getport.io/';
// Define the route for fetching pages
const PAGES_ROUTE = '/v1/pages';
// Define the authorization bearer token
const AUTH_TOKEN = 'YOUR BEARER TOKEN HERE';
axios
.get(`${API_BASE_URL}${PAGES_ROUTE}?compact=false`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${AUTH_TOKEN}`,
},
})
.then((response) => {
response.data.pages.forEach((page) => {
if (titlesToMatch.includes(page.title)) {
axios
.put(
`${API_BASE_URL}${PAGES_ROUTE}/${page.identifier}`,
JSON.stringify({
...page,
showInSidebar: SHOW_IN_SIDE_BAR,
}),
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${AUTH_TOKEN}`,
},
},
)
.then(() => {
console.log(`Page ${page.identifier} updated successfully`);
})
.catch((error) => {
console.error(`Error updating page ${page.identifier}: ${error.message}`);
});
}
});
})
.catch((error) => {
console.error(`Error fetching pages: ${error.message}`);
});