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
Terminal
pip3 install descope
Terminal
go get github.com/descope/go-sdk
// Include the following in your `pom.xml` (for Maven)
<dependency>
    <artifactId>java-sdk</artifactId>
    <groupId>com.descope</groupId>
    <version>sdk-version</version> // Check https://github.com/descope/descope-java/releases for the latest versions
</dependency>
Terminal
gem install descope

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)
}
from descope import (
    REFRESH_SESSION_TOKEN_NAME,
    SESSION_TOKEN_NAME,
    AuthException,
    DeliveryMethod,
    DescopeClient,
    AssociatedTenant,
    RoleMapping,
    AttributeMapping
)

management_key = "xxxx"

try:
    # You can configure the baseURL by setting the env variable Ex: export DESCOPE_BASE_URI="https://auth.company.com  - this is useful when you utilize a custom domain within your Descope project."
    descope_client = DescopeClient(project_id='__ProjectID__', management_key=management_key)
except Exception as error:
    # handle the error
    print ("failed to initialize. Error:")
    print (error)
import "github.com/descope/go-sdk/descope"
import "github.com/descope/go-sdk/descope/client"
import "fmt"

// Utilizing the context package allows for the transmission of context capabilities like cancellation
//      signals during the function call. In cases where context is absent, the context.Background()
//      function serves as a viable alternative.
//      Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
import (
	"context"
)

managementKey = "xxxx"

// DescopeBaseURL // within the client.Config, you can also configure the baseUrl ex: https://auth.company.com  - this is useful when you utilize a custom domain within your Descope project.
descopeClient, err := client.NewWithConfig(&client.Config{ProjectID:"__ProjectID__", managementKey:managementKey})
if err != nil {
    // handle the error
    log.Println("failed to initialize: " + err.Error())
}
import com.descope.client;

// Initialized after setting the DESCOPE_PROJECT_ID env var (and optionally DESCOPE_MANAGEMENT_KEY)
var descopeClient = new DescopeClient();

// ** Or directly **
var descopeClient = new DescopeClient(Config.builder()
        .projectId("__ProjectID__")
        .managementKey("management-key")
        .build());
require 'descope'

descope_client = Descope::Client.new(
  {
    project_id: '__ProjectID__',
    management_key: 'management_key'
  }
)

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.")
}
# Args
#   name (str): The new name for the project.
name = "New Project Name"

try:
  resp = descope_client.mgmt.project.update_name(name=name)
  print ("Successfully updated project name.")
except AuthException as error:
  print ("Failed to update project name.")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
// Args
//   ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//   name (str): The new name for the project.
name := "New Project Name"

err := descopeClient.Management.Project().UpdateName(name, nil)
if err != nil {
  fmt.Print("Failed to update project name.", err)
} else {
  fmt.Println("Successfully updated project name.")
}
ProjectService ps = descopeClient.getManagementServices().getProjectService();

try {
    ps.updateName("New Project Name");
} catch (DescopeException de) {
    // Handle the error
}

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)
}
# Args
#   None

try:
  resp = descope_client.mgmt.project.export_project()
  print ("Successfully exported project")
  print (resp)
except AuthException as error:
  print ("Failed to export project")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
// Args
//   ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()

res, err := descopeClient.Management.Project().Export(ctx)
if err != nil {
  fmt.Print("Failed to export project", err)
} else {
  fmt.Println("Successfully exported project", res)
}
ProjectService ps = descopeClient.getManagementServices().getProjectService();

try {
    ExportProjectResponse resp = ps.exportProject();
} catch (DescopeException de) {
    // Handle the error
}

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.")
}
# Args
#   files (dict): The raw JSON dictionary of files, in the same format as the one returned by calls to export.
files = {
	"files": {
		...
	}
}

try:
  resp = descope_client.mgmt.project.import_project(name=name)
  print ("Successfully imported project")
except AuthException as error:
  print ("Failed to import project")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
// Args
//   ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//   req (ImportProjectRequest): The raw JSON dictionary of files, in the same format as the one returned by calls to export.
req = := &descope.ImportProjectRequest{}
req.Files map[string]any{
	"files": {
		...
	}
}

err := descopeClient.Management.Project().Import(req)
if err != nil {
  fmt.Print("Failed to import project", err)
} else {
  fmt.Println("Successfully imported project")
}
ProjectService ps = descopeClient.getManagementServices().getProjectService();

try {
    ps.importProject({
          "files": {
        ...
        }
      });
} catch (DescopeException de) {
    // Handle the error
}

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)
}
# Args
#   name (str): The new name for the project.
name = "New Project"
#   tag(str): Optional tag for the project. Currently, only the "production" tag is supported.

try:
  resp = descope_client.mgmt.project.clone(name=name)
  print ("Successfully cloned project")
  print (resp)
except AuthException as error:
  print ("Failed to clone project")
  print ("Status Code: " + str(error.status_code))
  print ("Error: " + str(error.error_message))
// Args
//   ctx: context.Context - Application context for the transmission of context capabilities like
//        cancellation signals during the function call. In cases where context is absent, the context.Background()
//        function serves as a viable alternative.
//        Utilizing context within the Descope GO SDK is supported within versions 1.6.0 and higher.
ctx := context.Background()
//   name (str): The new name for the project.
name := "New Project"
//   tag(str): Optional tag for the project. Currently, only the "production" tag is supported.

res, err := descopeClient.Management.Project().Clone(ctx, name, nil)
if err != nil {
  fmt.Print("Failed to clone project", err)
} else {
  fmt.Println("Successfully cloned project", res)
}
ProjectService ps = descopeClient.getManagementServices().getProjectService();

// Clone the current project to a new one
// Note that this action is supported only with a pro license or above.
try {
    NewProjectResponse resp = ps.clone("New Project Name", ProjectTag.None);
} catch (DescopeException de) {
    // Handle the error
}
Was this helpful?

On this page