Management Flows with SDKs
You can use the Descope management SDK to run Management Flows and retrieve their outputs. The management SDK requires a management key, which can be generated here.
For an overview of Management Flows, see Management Flows.
Backend SDK
Install SDK
npm i --save @descope/node-sdkImport and initialize SDK
import DescopeClient from '@descope/node-sdk';
try{
// baseUrl="<URL>" // When initializing the Descope client, you can also configure the baseUrl ex: https://auth.company.com - this is useful when you utilize a custom domain within your Descope project.
const descopeClient = DescopeClient({ projectId: '__ProjectID__' });
} catch (error) {
// handle the error
console.log("failed to initialize: " + error)
}
Run Management Flow
Note
You can also use our Run Management Flow API to run a Management Flow.
This operation runs a Management Flow by its flow ID. Outputs configured on the flow End action are returned in the response.
The flow must be a Management Flow, not an interactive flow.
// Args:
// flowId (str): The Management Flow ID to run.
const flowId = "my-management-flow";
// options (object): Optional run options.
// input (object): Optional key/value input available in the flow as client.<key>.
const options = {
input: {
email: "user@example.com",
},
};
const resp = await descopeClient.management.flow.run(flowId, options);
if (!resp.ok) {
console.log("Failed to run management flow.")
console.log("Status Code: " + resp.code)
console.log("Error Code: " + resp.error.errorCode)
console.log("Error Description: " + resp.error.errorDescription)
console.log("Error Message: " + resp.error.errorMessage)
}
else {
console.log("Successfully ran management flow.")
console.log(resp.data)
}Run Management Flow Asynchronously
Note
You can also use our Run Management Flow Async API to run a Management Flow asynchronously.
For long-running Management Flows, start an asynchronous run to receive an execution ID immediately. Use Get Management Flow Async Result with that ID to retrieve the output when the flow completes.
# Args:
# flow_id (str): The Management Flow ID to run.
# options (FlowRunOptions | dict): Optional run options.
# input (dict): Optional key/value input available in the flow as client.<key>.
from descope import FlowRunOptions
try:
# Returns immediately with an execution ID
async_result = descope_client.mgmt.flow.run_flow_async(
flow_id="my-management-flow",
options=FlowRunOptions(
input={"email": "user@example.com"},
),
)
execution_id = async_result["executionId"]
print("Successfully started async management flow.")
print(execution_id)
except AuthException as error:
print("Failed to run management flow asynchronously.")
print("Status Code: " + str(error.status_code))
print("Error: " + str(error.error_message))Get Management Flow Async Result
Note
You can also use our Get Management Flow Async Result API to get the result of an asynchronous Management Flow.
This operation fetches the result of an asynchronous Management Flow run using the execution ID returned by Run Management Flow Asynchronously. Poll this endpoint until the flow completes.
# Args:
# execution_id (str): The execution ID returned by run_flow_async.
try:
resp = descope_client.mgmt.flow.get_flow_async_result(
execution_id="execution-id-from-async-run",
)
print("Successfully retrieved async management flow result.")
print(resp)
except AuthException as error:
print("Failed to get async management flow result.")
print("Status Code: " + str(error.status_code))
print("Error: " + str(error.error_message))