Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I'm facing a weird behavior when using the endpoint : "/v1/apps/{appId}/objects/{objectId}/actions/change-owner" [POST]. When I use it in JavaScript with the classic fetch
fonction, I consistently get a 403 error. However, when I run the same request in Postman, it works fine. By 'same,' I mean the same API token, object, application, content-type and ownerId.
/v1/apps
to fetch all applications, it works fine. fetch("https://<tenant>/api/v1/apps/<app_id>/objects/<sheet_id>/actions/change-owner", {
method: "POST",
body: JSON.stringify({
"ownerId": "<ID>"
}),
headers: {
"Content-Type": "application/json",
"Authorization":"Bearer <token>"
},
})
.then((res) => res.json())
.then((data) => {
console.log(data);
})
.catch((error) => console.error("Error:", error));
If you're doing this in the browser context, you'll need to send the csrf token with the request, e.g.
fetch("https://<tenant>/api/v1/apps/<app_id>/objects/<sheet_id>/actions/change-owner", {
method: "POST",
body: JSON.stringify({
"ownerId": "<ID>"
}),
headers: {
"Content-Type": "application/json",
"Authorization":"Bearer <token>",
"qlik-csrf-token": "<csrf-token>"
},
})
.then((res) => res.json())
.then((data) => {
console.log(data);
})
.catch((error) => console.error("Error:", error));
The CSRF token can be retrieved from https://qlik.dev/apis/rest/csrf-token/#get-v1-csrf-token
If you're doing this as a helper in a window that's already auth'd (i.e. you have the cookie), I guess you could do it without the Auth header too (depends on your implementation).
If you're doing this in the browser context, you'll need to send the csrf token with the request, e.g.
fetch("https://<tenant>/api/v1/apps/<app_id>/objects/<sheet_id>/actions/change-owner", {
method: "POST",
body: JSON.stringify({
"ownerId": "<ID>"
}),
headers: {
"Content-Type": "application/json",
"Authorization":"Bearer <token>",
"qlik-csrf-token": "<csrf-token>"
},
})
.then((res) => res.json())
.then((data) => {
console.log(data);
})
.catch((error) => console.error("Error:", error));
The CSRF token can be retrieved from https://qlik.dev/apis/rest/csrf-token/#get-v1-csrf-token
If you're doing this as a helper in a window that's already auth'd (i.e. you have the cookie), I guess you could do it without the Auth header too (depends on your implementation).
Thank you for your help. It is now working after adding the "qlik-csrf-token" to the header. You might consider adding this to the documentation.
https://qlik.dev/apis/rest/apps/#post-v1-apps-appId-objects-objectId-actions-change-owner
I'll add a task to document CRSF requirements in general when making browser requests vs external client requests.