Hello everyone,
I want to read and modify a .docx
file that is in a Attachment field in another App.
I know it is saved as a file.json
, and I got fileKey of this file.
But I cannot access the file.json
of another App as it results in a 403 error.
To solve this, I gave full permission like this:
App Permissions:
Failed attempt to get the file.json file:
Resulting 403 Forbidden Error
This is my code:
Note url
variable is hardcoded with {subdomain}
& AppID
(function () {
'use strict';
var mergeDocumentEvents = ['app.record.edit.submit', 'app.record.create.submit'];
kintone.events.on(mergeDocumentEvents, function (event) {
var lookupID = kintone.app.getLookupTargetAppId('Doc_lookup');
var recordID = event.record['Doc_lookup'].value;
// console.log("Template App ID:",text,"Lookup code",event.record['Doc_lookup']);
var docBody = {
'app': lookupID,
'id': recordID
}
console.log("currentLookupId", lookupID, "currentRecordId", recordID);
kintone.api(kintone.api.url('/k/v1/record', true), 'GET', docBody, function (resp) {
var fileKey = resp.record.Attachment.value[0].fileKey;
var url = 'https://{subdomain}.kintone.com/k/12/file.json?fileKey=' + fileKey;
console.log("fileurl", url);
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.responseType = 'blob';
xhr.onload = function () {
if (xhr.status === 200) {
// success
var blob = new Blob([xhr.response]);
var windowUrl = window.URL || window.webkitURL;
var blobUrl = windowUrl.createObjectURL(blob);
console.log("bloburl-----", blobUrl);
} else {
// error
console.log(xhr.responseText);
}
};
xhr.send();
}, function (error) {
// error
console.log(error);
});
});
})();
Please help me.