In this example, we will be updating the meta zip file for certain model
- fetch entity data
const myHeaders = new Headers();
myHeaders.append("x-token", token);
myHeaders.append("x-lang", "uk");
const requestOptions = {
method: "GET",
headers: myHeaders,
};
const {data: entityData} = await fetch("https://example.com/api/entities/3265", requestOptions)
.then((response) => response.json())
.catch((error) => console.error(error));
- upload file
const myHeaders2 = new Headers();
myHeaders2.append("x-token", token
const raw = JSON.stringify(entityData);
const formdata = new FormData();
formdata.append("file1", fileInput.files[0], "metafile.zip");
const requestOptions2 = {
method: "POST",
headers: myHeaders2,
body: formdata,
};
const {data: files} = await fetch("https://example.com/api/entities/3265", requestOptions2)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));
- update data
const myHeaders3 = new Headers();
myHeaders3.append("x-token", token);
myHeaders3.append("Content-Type", "application/json");
entityData.metaZip = files['file1'];
const raw = JSON.stringify(entityData);
const requestOptions3 = {
method: "PUT",
headers: myHeaders3,
body: raw,
};
fetch("https://example.com/api/entities/3265", requestOptions3)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.error(error));