Descopers with SDKs
You can use the Descope management SDK to create, update, delete, or load Descopers (Descope console users). The management SDK requires a management key, which can be generated here.
If you wish to learn more about Descopers in general, see the Company Settings page.
Descoper management using the management SDK
Backend SDK
Install SDK
npm i --save @descope/node-sdkpip3 install descopego get github.com/descope/go-sdk// Include the following in your `pom.xml` (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>gem install descopecomposer require descope/descope-phpdotnet add package DescopeImport 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)
}
from descope import (
REFRESH_SESSION_TOKEN_NAME,
SESSION_TOKEN_NAME,
AuthException,
DeliveryMethod,
DescopeClient,
AssociatedTenant,
RoleMapping,
AttributeMapping,
LoginOptions
)
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 custom domain within your Descope project."
descope_client = DescopeClient(project_id='__ProjectID__')
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"
// 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"
)
// 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__"})
if err != nil {
// handle the error
log.Println("failed to initialize: " + err.Error())
}import com.descope.client.Config;
import com.descope.client.DescopeClient;
var descopeClient = new DescopeClient(Config.builder().projectId("__ProjectID__").build());require 'descope'
@project_id = ENV['__ProjectID__']
@client = Descope::Client.new({ project_id: @project_id})require 'vendor/autoload.php';
use Descope\SDK\DescopeSDK;
$descopeSDK = new DescopeSDK([
'projectId' => $_ENV['__ProjectID__'],
]);using Descope;
// Configure the Descope client
var options = new DescopeClientOptions
{
ProjectId = "__ProjectID__", // Required
ManagementKey = "DESCOPE_MANAGEMENT_KEY", // Optional, for management APIs
BaseUrl = "__BaseURL__", // Optional, auto-detected from project ID, only set to override
JwksCacheDuration = TimeSpan.FromMinutes(5) // Optional, how long public signing keys are cached (default: 5 minutes)
};
// Option 1: Dependency Injection - best for ASP.NET Core apps; registers IDescopeClient so it can be injected into your services
builder.Services.AddDescopeClient(options);
// Then inject IDescopeClient wherever you need it
public class MyService
{
private readonly IDescopeClient descopeClient;
public MyService(IDescopeClient client)
{
descopeClient = client;
}
}
// Option 2: Factory (Create once and reuse this instance) - best for console apps, background workers, or when you need to manually control the client's lifetime
var descopeClient = DescopeManagementClientFactory.Create(options);Load All Descopers
Note
You can also use our List Descopers API to list all Descopers.
This operation lists all Descopers in your company and returns both the Descoper details and the total count.
const resp = await descopeClient.management.descoper.list();
if (!resp.ok) {
console.log("Failed to load descopers.")
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 loaded descopers.")
console.log("Total: " + resp.data.total)
console.log(resp.data.descopers)
}try:
resp = descope_client.mgmt.descoper.list()
print ("Successfully loaded descopers.")
print ("Total: " + str(resp["total"]))
print(json.dumps(resp["descopers"], indent=2))
except AuthException as error:
print ("Unable to load descopers.")
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()
// options (*descope.DescoperLoadOptions): Optional load options. Currently unused; nil is allowed.
var options *descope.DescoperLoadOptions = nil
descopers, total, err := descopeClient.Management.Descoper().List(ctx, options)
if (err != nil){
fmt.Println("Unable to load descopers: ", err)
} else {
fmt.Println("Successfully loaded descopers.")
fmt.Println("Total: ", total)
fmt.Println(descopers)
}Load Descoper by ID
Note
You can also use our Get Descoper API to load a specific Descoper.
This operation loads an existing Descoper by ID, including their attributes, status, and RBAC configuration.
// Args:
// id (str): The Descoper ID.
const id = "descoper-id";
const resp = await descopeClient.management.descoper.load(id);
if (!resp.ok) {
console.log("Failed to load descoper.")
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 loaded descoper.")
console.log(resp.data)
}# Args:
# id (str): The Descoper ID.
id = "descoper-id"
try:
resp = descope_client.mgmt.descoper.load(id)
print ("Successfully loaded descoper.")
print(json.dumps(resp, indent=2))
except AuthException as error:
print ("Unable to load descoper.")
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()
// id (string): The Descoper ID.
id := "descoper-id"
descoper, err := descopeClient.Management.Descoper().Get(ctx, id)
if (err != nil){
fmt.Println("Unable to load descoper: ", err)
} else {
fmt.Println("Successfully loaded descoper.")
fmt.Println(descoper)
}Create Descoper
Note
You can also use our Create Descopers API to create a Descoper.
This operation creates one or more Descopers within the company. Each Descoper requires a login ID. You can optionally set attributes (display name, email, phone), send an invitation email, and configure Descoper roles via RBAC — typically as company admin (isCompanyAdmin), or with granular access scoped to projects or tags.
// Args:
// descopers (List[DescoperCreate]): An array of Descoper creation objects. Each Descoper must have a loginId.
// loginId (str): The login ID for the Descoper.
// attributes (DescoperAttributes): Optional attributes (displayName, email, phone).
// sendInvite (bool): Optional. Set to true to send an invitation email.
// rbac (DescoperRBAC): Optional RBAC configuration. Typically use exactly one of isCompanyAdmin, projects, or tags.
const descopers = [
{
loginId: "user@example.com",
attributes: {
displayName: "Test User",
email: "user@example.com",
phone: "+1234567890",
},
sendInvite: true,
rbac: {
// exactly one of isCompanyAdmin, projects, or tags
projects: [
{
projectIds: ["project-id"],
role: "admin", // 'admin' | 'developer' | 'support'
},
],
},
},
];
const resp = await descopeClient.management.descoper.create(descopers);
if (!resp.ok) {
console.log("Failed to create descoper.")
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 created descoper.")
console.log("Total: " + resp.data.total)
console.log(resp.data.descopers)
}# Args:
# descopers (List[DescoperCreate]): A list of Descoper creation objects. Each Descoper must have a login_id.
# login_id (str): The login ID for the Descoper.
# attributes (DescoperAttributes): Optional attributes (display_name, email, phone).
# send_invite (bool): Optional. Set to True to send an invitation email.
# rbac (DescoperRBAC): Optional RBAC configuration. Typically use exactly one of is_company_admin, projects, or tags.
descopers = [
DescoperCreate(
login_id="user@example.com",
attributes=DescoperAttributes(
display_name="Test User",
email="user@example.com",
phone="+1234567890",
),
send_invite=True,
rbac=DescoperRBAC(
# exactly one of is_company_admin, projects, or tags
projects=[
DescoperProjectRole(
project_ids=["project-id"],
role=DescoperRole.ADMIN, # ADMIN | DEVELOPER | SUPPORT
)
],
),
)
]
try:
resp = descope_client.mgmt.descoper.create(descopers=descopers)
print ("Successfully created descoper.")
print ("Total: " + str(resp["total"]))
print(json.dumps(resp["descopers"], indent=2))
except AuthException as error:
print ("Unable to create descoper.")
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()
// descopers ([]*descope.DescoperCreate): A list of Descoper creation objects. Each Descoper must have a LoginID.
// LoginID (string): The login ID for the Descoper.
// Attributes (*descope.DescoperAttributes): Optional attributes (DisplayName, Email, Phone).
// SendInvite (bool): Optional. Set to true to send an invitation email.
// ReBac (*descope.DescoperRBAC): Optional RBAC configuration. Typically use exactly one of IsCompanyAdmin, Projects, or Tags.
descopers := []*descope.DescoperCreate{
{
LoginID: "user@example.com",
Attributes: &descope.DescoperAttributes{
DisplayName: "Test User",
Email: "user@example.com",
Phone: "+1234567890",
},
SendInvite: true,
ReBac: &descope.DescoperRBAC{
// exactly one of IsCompanyAdmin, Projects, or Tags
Projects: []*descope.DescoperProjectRole{
{
ProjectIDs: []string{"project-id"},
Role: descope.DescoperRoleAdmin, // Admin | Developer | Support
},
},
},
},
}
created, total, err := descopeClient.Management.Descoper().Create(ctx, descopers)
if (err != nil){
fmt.Println("Unable to create descoper: ", err)
} else {
fmt.Println("Successfully created descoper.")
fmt.Println("Total: ", total)
fmt.Println(created)
}Update Descoper
Note
You can also use our Update Descopers API to update a Descoper.
This operation updates an existing Descoper. You can update attributes (display name, email, phone) and/or RBAC configuration (company admin, or granular project/tag roles).
// Args:
// id (str): The Descoper ID.
const id = "descoper-id";
// attributes (DescoperAttributes): Optional attributes to update (displayName, email, phone).
const attributes = {
displayName: "Updated Name",
};
// rbac (DescoperRBAC): Optional RBAC configuration to update. Typically use exactly one of isCompanyAdmin, projects, or tags.
const rbac = {
isCompanyAdmin: true,
};
const resp = await descopeClient.management.descoper.update(id, attributes, rbac);
if (!resp.ok) {
console.log("Failed to update descoper.")
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 descoper.")
console.log(resp.data)
}# Args:
# id (str): The Descoper ID.
id = "descoper-id"
# attributes (DescoperAttributes): Optional attributes to update (display_name, email, phone).
attributes = DescoperAttributes(
display_name="Updated Name",
)
# rbac (DescoperRBAC): Optional RBAC configuration to update. Typically use exactly one of is_company_admin, projects, or tags.
rbac = DescoperRBAC(
is_company_admin=True,
)
try:
resp = descope_client.mgmt.descoper.update(id=id, attributes=attributes, rbac=rbac)
print ("Successfully updated descoper.")
print(json.dumps(resp, indent=2))
except AuthException as error:
print ("Unable to update descoper.")
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()
// id (string): The Descoper ID.
id := "descoper-id"
// attributes (*descope.DescoperAttributes): Optional attributes to update (DisplayName, Email, Phone).
attributes := &descope.DescoperAttributes{
DisplayName: "Updated Name",
}
// rbac (*descope.DescoperRBAC): Optional RBAC configuration to update. Typically use exactly one of IsCompanyAdmin, Projects, or Tags.
rbac := &descope.DescoperRBAC{
IsCompanyAdmin: true,
}
descoper, err := descopeClient.Management.Descoper().Update(ctx, id, attributes, rbac)
if (err != nil){
fmt.Println("Unable to update descoper: ", err)
} else {
fmt.Println("Successfully updated descoper.")
fmt.Println(descoper)
}Delete Descoper
Note
You can also use our Delete Descopers API to delete a Descoper.
This operation deletes an existing Descoper by ID. It is important to note that this operation is irreversible and the Descoper will be removed and will not be able to be added back without recreation.
// Args:
// id (str): The Descoper ID.
const id = "descoper-id";
const resp = await descopeClient.management.descoper.delete(id);
if (!resp.ok) {
console.log("Failed to delete descoper.")
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 deleted descoper.")
}# Args:
# id (str): The Descoper ID.
id = "descoper-id"
try:
descope_client.mgmt.descoper.delete(id)
print ("Successfully deleted descoper.")
except AuthException as error:
print ("Unable to delete descoper.")
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()
// id (string): The Descoper ID.
id := "descoper-id"
err := descopeClient.Management.Descoper().Delete(ctx, id)
if (err != nil){
fmt.Println("Unable to delete descoper: ", err)
} else {
fmt.Println("Successfully deleted descoper.")
}