-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-to-group.ts
60 lines (54 loc) · 1.33 KB
/
add-to-group.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
57
58
59
60
async function main() {
try {
// Fetch a group
const listGroupRequest = await fetch(
"https://api.pinata.cloud/v3/files/groups",
{
method: "GET",
headers: {
Authorization: `Bearer ${process.env.PINATA_JWT}`,
},
},
);
const listGroups = await listGroupRequest.json();
// Get group ID
const groupId = listGroups.data.groups[0].id;
// Fetch a file ID
const fileRequest = await fetch("https://api.pinata.cloud/v3/files", {
method: "GET",
headers: {
Authorization: `Bearer ${process.env.PINATA_JWT}`,
},
});
const files = await fileRequest.json();
// Get file ID
const fileId = files.data.files[0].id;
// Add file to group
const request = await fetch(
`https://api.pinata.cloud/v3/files/groups/${groupId}/ids/${fileId}`,
{
method: "PUT",
headers: {
Authorization: `Bearer ${process.env.PINATA_JWT}`,
},
},
);
const response = await request.json();
console.log(response);
// Fetch the same file to show its part of the group now
const fileInfoRequest = await fetch(
`https://api.pinata.cloud/v3/files/${fileId}`,
{
method: "GET",
headers: {
Authorization: `Bearer ${process.env.PINATA_JWT}`,
},
},
);
const fileInfo = await fileInfoRequest.json();
console.log(fileInfo);
} catch (error) {
console.log(error);
}
}
main();