I have written this AppFunction to toggle the monitoring state of a host, and I have given it all the required
scope, but I am still getting this error below. Any idea? I am planning to develop this further to be able to use in a workflow.
Any feedback is much appreciated.
------------------------
Given this permission:
-----------------------
Scopes: app-settings:objects:read, app-settings:objects:write, settings:objects:read, settings:objects:write, settings:schemas:read, app-engine:functions:run, app-engine:apps:run
The Function:
import { settingsObjectsClient } from “@dynatrace-sdk/client-classic-environment-v2”;
export default async function () : Promise<{ statusCode: number; message: string }>{ const hostId = “HOST-F6DC785465402DD8”; // Replace with your actual host ID try { const response = await settingsObjectsClient.postSettingsObjects({ body: [ { schemaId: “builtin:host.monitoring”, scope: hostId, value: { monitoringEnabled: false, }, }, ], }); return { statusCode: 200, message: “{hostId} - Monitoring state updated successfully.” };
} catch (error: unknown) { let errorDetails = “”; if (error instanceof Error) { errorDetails = `Error name: ${error.name}\n` + `Error message: ${error.message}\n` + (error.stack ? `Stack trace: ${error.stack}` : “No stack trace available.”); } else { errorDetails = `Unknown error object: ${JSON.stringify(error, null, 2)}`; } return { statusCode: 500, message: `${hostId} - Failed to update monitoring state.\nDebug info:\n${errorDetails}`, }; }}-----------------I get this Error:----------------
{"statusCode":500,"message":"HOST-F6DC785465402DD8 - Failed to update monitoring state.\nDebug info:\nError name: 403\nError message: OAuth token is missing required scope. Use one of: [settings:objects:write]\nStack trace: 403: OAuth token is missing required scope. Use one of: [settings:objects:write]\n at se.postSettingsObjects (<a target="_blank" rel="noopener">file:///invoker.js:5:19821)\n</a> at eventLoopTick (ext:core/01_core.js:177:7)\n at async Ds (<a target="_blank" rel="noopener">file:///invoker.js:5:47784</a>)"}<br><br><br>