I am using the Get Customization REST API (Endpoint: /k/v1/app/customize
).
This is returning correctly.
However, when I try to use the returned fileKey
s, I get an error saying, The specified file (id: XXXXXXXX) not found.
.
I am trying to use the Get Customization API’s response to upload a new file.
The file that I upload via the Upload File API works without problem.
Goal
My goal is to add a customization file, however with out the other file keys for the current customization is overwrites the current files that are attached to the app.
Script
#save() {
// Upload file
this.#upload().then(data => {
// Attach file to app
this.#attachFile(data.fileKey).then(resp => {
console.log(resp)
}).catch(err => {
console.error(err)
})
}).catch(err => {
console.error(err)
})
}
#getCustomizations() {
return new Promise((resolve, reject) => {
kintone.api(
kintone.api.url('/k/v1/app/customize'),
'GET',
{ app: this.#appID },
resp => resolve(resp),
err => reject(err)
)
})
}
#createBlob() {
// Create file
const CONTENT = "const TEST_VAR = true;"
return new Blob([CONTENT], {
type: "text/javascript"
})
}
#upload() {
return new Promise((resolve, reject) => {
const FORM_DATA = new FormData()
FORM_DATA.append('__REQUEST_TOKEN__', this.#requestToken);
FORM_DATA.append("file", this.#createBlob(), "CustomizationConfigLib_Configs.js")
var url = `https://${location.host}/k/v1/file.json`;
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onload = function () {
if (xhr.status === 200) {
resolve(JSON.parse(xhr.responseText));
} else {
reject(JSON.parse(xhr.responseText));
}
};
xhr.send(FORM_DATA);
})
}
async #attachFile(fileKey) {
const BODY = await this.#getCustomizations()
BODY.app = this.#appID
BODY.desktop.js.push({
type: "FILE",
file: { fileKey }
})
console.log(BODY)
return new Promise((resolve, reject) => {
kintone.api(
kintone.api.url('/k/v1/preview/app/customize'),
'PUT',
BODY,
resp => resolve({ resp, revision: BODY.revision }),
err => reject(err)
);
})
}
Problem
Everything works, except I get the error for the fileKey
not found.
I have checked and know that the fileKey
in question is referencing the already attached customization file.