Projects with SDKs

You can use the Descope management SDK for common project management operations like cloning project, exporting project, importing project, etc. The management SDK requires a management key, which can be generated here.

Install SDK

Terminal
npm i --save @descope/node-sdk

Import and initialize Management SDK

import DescopeClient from '@descope/node-sdk';

const managementKey = "xxxx"

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__', managementKey: managementKey });
} catch (error) {
    // handle the error
    console.log("failed to initialize: " + error)
}

Update Project Name

This endpoint allows you to update the current project's name.

// Args
//   name (str): The new name for the project.
const name = "New Project Name"

const resp = await descopeClient.management.project.updateName(name)

if (!resp.ok) {
  console.log(resp)
  console.log("Failed to update project name.")
  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 updated project name.")
}

Update Project Tags

This endpoint allows you to update the tags associated with the current project. Tags are free-text labels you can use to categorize projects (e.g. production, team-a).

# Args
#   tags (List[str]): Array of free-text tags to set on the project.
tags = ["production", "team-a"]

try:
  descope_client.mgmt.project.update_tags(tags=tags)
  print ("Successfully updated project tags.")
except AuthException as error:
  print ("Failed to update project tags.")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))

Note

The Python SDK also supports renaming a project with update_name (see Update Project Name) and duplicating a project with clone (see Clone Project):

# Rename the current project
descope_client.mgmt.project.update_name(name="new-project-name")

# Clone the current project (Pro license required; users/tenants/access keys are not cloned)
clone_resp = descope_client.mgmt.project.clone(name="cloned-project-name")

Export Project

This endpoint allows you to export the current project.

// Args
//   None

const resp = await descopeClient.management.project.export()

if (!resp.ok) {
  console.log(resp)
  console.log("Failed to export project.")
  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 exported project.")
  console.log(resp.data)
}

Import Project

This endpoint allows you to import all settings and configurations into the current project. Use with caution, this endpoint overrides any current configuration.

// Args
//   files (<Record<string, any>): The raw JSON dictionary of files, in the same format as the one returned by calls to export.
const files = {
	"files": {
		//exportRes.data.files
		...
	}
}

const resp = await descopeClient.management.project.import(files)
if (!resp.ok) {
  console.log(resp)
  console.log("Failed to import project.")
  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 imported project.")
}

Clone Project

This function allows you to clone the current project, including its settings and configurations.

Note

Users, tenants and access keys are not cloned.

// Args
//   name (str): The new name for the project.
const name = "New Project"
//   tag(str): Optional tag for the project. Currently, only the "production" tag is supported.

const resp = await descopeClient.management.project.clone(name, null)
if (!resp.ok) {
  console.log(resp)
  console.log("Failed to clone project.")
  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 cloned project.")
  console.log(resp.data)
}
Was this helpful?

On this page