Previous
ML training client
The fleet management API allows you to manage your machine fleet with code instead of with the graphical interface of the Viam app. With it you can
The fleet management API supports the following methods:
Method Name | Description |
---|---|
GetUserIDByEmail | Get the ID of a user by email. |
CreateOrganization | Create an organization. |
ListOrganizations | List the organizations the user is an authorized user of. |
GetOrganizationsWithAccessToLocation | Get all organizations that have access to a location. |
ListOrganizationsByUser | List the organizations a user belongs to. |
GetOrganization | Retrieve the organization object for the requested organization containing the organization’s ID, name, public namespace, and more. |
GetOrganizationNamespaceAvailability | Check the availability of an organization namespace. |
UpdateOrganization | Updates organization details. |
DeleteOrganization | Delete an organization. |
ListOrganizationMembers | List the members and invites of the organization that you are currently authenticated to. |
CreateOrganizationInvite | Create an organization invite and send it by email. |
UpdateOrganizationInviteAuthorizations | Update (add or remove) the authorizations attached to an organization invite that has already been created. |
DeleteOrganizationMember | Remove a member from the organization you are currently authenticated to. |
DeleteOrganizationInvite | Delete a pending organization invite to the organization you are currently authenticated to. |
ResendOrganizationInvite | Resend a pending organization invite email. |
GetOrganizationMetadata | Gets the user-defined metadata for an organization. |
UpdateOrganizationMetadata | Updates the user-defined metadata for an organization. |
CreateLocation | Create and name a location under the organization you are currently authenticated to. |
GetLocation | Get a location by its location ID. |
UpdateLocation | Change the name of a location and/or assign a parent location to a location. |
DeleteLocation | Delete a location. |
ListLocations | Get a list of all locations under the organization you are currently authenticated to. |
ShareLocation | Share a location with an organization. |
UnshareLocation | Stop sharing a location with an organization. |
LocationAuth | Get a location’s LocationAuth (location secret or secrets). |
CreateLocationSecret | Create a new location secret. |
DeleteLocationSecret | Delete a location secret. |
GetLocationMetadata | Get the user-defined metadata for a location. |
UpdateLocationMetadata | Update the user-defined metadata for a location. |
GetRobot | Get a machine by its ID. |
GetRobotAPIKeys | Gets the API keys for the machine. |
GetRobotParts | Get a list of all the parts under a specific machine. |
GetRobotPart | Get a specific machine part. |
GetRobotPartLogs | Get the logs associated with a specific machine part. |
TailRobotPartLogs | Get an asynchronous iterator that receives live machine part logs. |
GetRobotPartHistory | Get a list containing the history of a machine part. |
UpdateRobotPart | Change the name of and assign an optional new configuration to a machine part. |
NewRobotPart | Create a new machine part. |
DeleteRobotPart | Delete the specified machine part. |
MarkPartAsMain | Mark a machine part as the main part of a machine. |
MarkPartForRestart | Mark a specified machine part for restart. |
CreateRobotPartSecret | Create a machine part secret. |
DeleteRobotPartSecret | Delete a machine part secret. |
ListRobots | Get a list of all machines in a specified location. |
NewRobot | Create a new machine. |
UpdateRobot | Change the name of an existing machine. |
DeleteRobot | Delete a specified machine. |
GetRobotMetadata | Gets the user-defined metadata for a machine. |
GetRobotPartMetadata | Gets the user-defined metadata for a machine part. |
UpdateRobotMetadata | Updates the user-defined metadata for a machine. |
UpdateRobotPartMetadata | Updates the user-defined metadata for a machine part. |
ListFragments | Get a list of fragments in the organization you are currently authenticated to. |
ListMachineFragments | Get a list of top level and nested fragments for a machine, as well as additionally specified fragment IDs. |
GetFragment | Get a fragment by ID. |
CreateFragment | Create a new private fragment. |
UpdateFragment | Update a fragment name and its config and/or visibility. |
DeleteFragment | Delete a fragment. |
GetFragmentHistory | Get fragment history. |
AddRole | Add a role under the organization you are currently authenticated to. |
RemoveRole | Remove a role under the organization you are currently authenticated to. |
ChangeRole | Changes an existing role to a new role. |
ListAuthorizations | List all authorizations (owners and operators) of a specific resource (or resources) within the organization you are currently authenticated to. |
CheckPermissions | Check if the organization, location, or robot your ViamClient is authenticated to is permitted to perform some action or set of actions on the resource you pass to the method. |
GetRegistryItem | Get registry item by ID. |
CreateRegistryItem | Create a registry item. |
UpdateRegistryItem | Update a registry item. |
ListRegistryItems | List the registry items in an organization. |
DeleteRegistryItem | Delete a registry item. |
CreateModule | Create a module under the organization you are currently authenticated to. |
UpdateModule | Update the documentation URL, description, models, entrypoint, and/or the visibility of a module. |
UploadModuleFile | Upload a module file. |
GetModule | Get a module by its ID. |
ListModules | List the modules under the organization you are currently authenticated to. |
CreateKey | Create a new API key. |
DeleteKey | Delete an API key. |
RotateKey | Rotate an API key. |
ListKeys | List all keys for the organization that you are currently authenticated to. |
CreateKeyFromExistingKeyAuthorizations | Create a new API key with an existing key’s authorizations. |
GetAppContent | Retrieve the app content for an organization. |
To use the Viam fleet management API, you first need to instantiate a ViamClient
and then instantiate an AppClient
.
You will also need an API key and API key ID to authenticate your session. To get an API key (and corresponding ID), you have two options:
The following example instantiates a ViamClient
, authenticating with an API key, and then instantiates an AppClient
:
import asyncio
from viam.rpc.dial import DialOptions, Credentials
from viam.app.viam_client import ViamClient
async def connect() -> ViamClient:
dial_options = DialOptions(
credentials=Credentials(
type="api-key",
# Replace "<API-KEY>" (including brackets) with your API key
payload='<API-KEY>',
),
# Replace "<API-KEY-ID>" (including brackets) with your API key
# ID
auth_entity='<API-KEY-ID>'
)
return await ViamClient.create_from_dial_options(dial_options)
async def main():
# Make a ViamClient
viam_client = await connect()
# Instantiate an AppClient called "cloud"
# to run fleet management API methods on
cloud = viam_client.app_client
viam_client.close()
if __name__ == '__main__':
asyncio.run(main())
package main
import (
"context"
"log"
"go.viam.com/rdk/app"
"go.viam.com/rdk/logging"
"go.viam.com/utils"
)
func main() {
logger := logging.NewLogger("fleet-management")
// Replace "<API-KEY-ID>" (including brackets) with your API key ID
apiKeyID := "<API-KEY-ID>"
// Replace "<API-KEY>" (including brackets) with your API key
apiKey := "<API-KEY>"
client, err := app.NewAppClient(context.Background(), app.Config{
BaseURL: "https://app.viam.com:443",
Auth: utils.Credentials{
Type: utils.CredentialsTypeAPIKey,
Payload: apiKey,
},
AuthEntity: &apiKeyID,
Logger: logger,
})
if err != nil {
log.Fatalf("Failed to create app client: %v", err)
}
defer client.Close()
// Use the client to make fleet management API calls
// Example: List organizations
ctx := context.Background()
orgs, err := client.ListOrganizations(ctx)
if err != nil {
log.Fatalf("Failed to list organizations: %v", err)
}
for _, org := range orgs {
log.Printf("Organization: %s (ID: %s)", org.Name, org.Id)
}
}
async function connect(): Promise<VIAM.ViamClient> {
// Replace "<API-KEY-ID>" (including brackets) with your machine's
const API_KEY_ID = "<API-KEY-ID>";
// Replace "<API-KEY>" (including brackets) with your machine's API key
const API_KEY = "<API-KEY>";
const opts: VIAM.ViamClientOptions = {
serviceHost: "https://app.viam.com:443",
credentials: {
type: "api-key",
authEntity: API_KEY_ID,
payload: API_KEY,
},
};
const client = await VIAM.createViamClient(opts);
return client;
}
const viamClient = await connect();
const appClient = appClient.appClient;
Once you have instantiated an AppClient
, you can run the following API methods against the AppClient
object (named fleet
in the examples).
Get the ID of a user by email.
Parameters:
email
(str) (required): The email of the user.Returns:
Example:
id = await cloud.get_user_id_by_email("youremail@email.com")
For more information, see the Python SDK Docs.
Parameters:
email
(string) (required): The email of the user.Returns:
Example:
userID, err := client.GetUserIDByEmail(ctx, "youremail@email.com")
if err != nil {
log.Fatalf("Failed to get user ID: %v", err)
}
fmt.Printf("User ID: %s\n", userID)
For more information, see the Go SDK Docs.
Parameters:
email
(string) (required): The email address of the user.Returns:
Example:
// This method is used internally only. To obtain a user's ID, use the listOrganizationsByUser method.
const members = await appClient.listOrganizationMembers(
'<YOUR-ORGANIZATION-ID>'
);
For more information, see the TypeScript SDK Docs.
Create an organization.
Parameters:
name
(str) (required): The name of the organization.Returns:
Example:
organization = await cloud.create_organization("name")
For more information, see the Python SDK Docs.
Parameters:
name
(string) (required): The name of the organization.Returns:
Example:
organization, err := client.CreateOrganization(ctx, "name")
if err != nil {
log.Fatalf("Failed to create organization: %v", err)
}
fmt.Printf("Created organization: %s\n", organization.Name)
For more information, see the Go SDK Docs.
Parameters:
name
(string) (required): The name of the new organization.Returns:
For more information, see the TypeScript SDK Docs.
List the organizations the user is an authorized user of.
Parameters:
Returns:
Example:
org_list = await cloud.list_organizations()
For more information, see the Python SDK Docs.
Parameters:
Returns:
Example:
orgList, err := client.ListOrganizations(ctx)
if err != nil {
log.Fatalf("Failed to list organizations: %v", err)
}
for _, org := range orgList {
fmt.Printf("Organization: %s (ID: %s)\n", org.Name, org.Id)
}
For more information, see the Go SDK Docs.
Parameters:
Returns:
Example:
const organizations = await appClient.listOrganizations();
For more information, see the TypeScript SDK Docs.
Get all organizations that have access to a location.
Parameters:
location_id
(str) (required): The ID of the location.Returns:
Example:
org_list = await cloud.get_organizations_with_access_to_location("location-id")
For more information, see the Python SDK Docs.
Parameters:
locationID
(string) (required): The ID of the location.Returns:
Example:
orgList, err := client.GetOrganizationsWithAccessToLocation(ctx, "location-id")
if err != nil {
log.Fatalf("Failed to get organizations with access to location: %v", err)
}
for _, org := range orgList {
fmt.Printf("Organization: %s\n", org.Name)
}
For more information, see the Go SDK Docs.
Parameters:
locationId
(string) (required): The ID of the location to query.Returns:
Example:
const organizations =
await appClient.getOrganizationsWithAccessToLocation(
'<YOUR-LOCATION-ID>'
);
For more information, see the TypeScript SDK Docs.
List the organizations a user belongs to.
Parameters:
user_id
(str) (required): The ID of the user. You can retrieve this with the get_user_id_by_email() method.Returns:
Example:
org_list = await cloud.list_organizations_by_user("<YOUR-USER-ID>")
For more information, see the Python SDK Docs.
Parameters:
userID
(string) (required): The ID of the user. You can retrieve this with the GetUserIDByEmail() method.Returns:
Example:
orgList, err := client.ListOrganizationsByUser(ctx, "<YOUR-USER-ID>")
if err != nil {
log.Fatalf("Failed to list organizations by user: %v", err)
}
for _, org := range orgList {
fmt.Printf("Organization: %s\n", org.OrgName)
}
For more information, see the Go SDK Docs.
Parameters:
userId
(string) (required): The ID of the user to query.Returns:
For more information, see the TypeScript SDK Docs.
Retrieve the organization object for the requested organization containing the organization’s ID, name, public namespace, and more.
Parameters:
org_id
(str) (required): The ID of the organization to query. You can retrieve this from the organization settings page.Returns:
Raises:
Example:
org = await cloud.get_organization("<YOUR-ORG-ID>")
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization to query. You can retrieve this from the organization settings page.Returns:
Example:
org, err := client.GetOrganization(ctx, "<YOUR-ORG-ID>")
if err != nil {
log.Fatalf("Failed to get organization: %v", err)
}
fmt.Printf("Organization: %s\n", org.Name)
For more information, see the Go SDK Docs.
Parameters:
organizationId
(string) (required): The ID of the organization.Returns:
Example:
const organization = await appClient.getOrganization(
'<YOUR-ORGANIZATION-ID>'
);
For more information, see the TypeScript SDK Docs.
Check the availability of an organization namespace.
Parameters:
public_namespace
(str) (required): Organization namespace to check. Namespaces can only contain lowercase alphanumeric and dash characters.Returns:
Raises:
Example:
available = await cloud.get_organization_namespace_availability(
public_namespace="my-cool-organization")
For more information, see the Python SDK Docs.
Parameters:
publicNamespace
(string) (required): Organization namespace to check. Namespaces can only contain lowercase alphanumeric and dash characters.Returns:
Example:
available, err := client.GetOrganizationNamespaceAvailability(ctx, "my-cool-organization")
if err != nil {
log.Fatalf("Failed to check namespace availability: %v", err)
}
fmt.Printf("Namespace available: %t\n", available)
For more information, see the Go SDK Docs.
Parameters:
namespace
(string) (required): The namespace to query for availability.Returns:
Example:
const isAvailable =
await appClient.getOrganizationNamespaceAvailability('name');
For more information, see the TypeScript SDK Docs.
Updates organization details.
Parameters:
org_id
(str) (required): The ID of the organization to update.name
(str) (optional): If provided, updates the org’s name.public_namespace
(str) (optional): If provided, sets the org’s namespace if it hasn’t already been set.region
(str) (optional): If provided, updates the org’s region.cid
(str) (optional): If provided, update’s the org’s CRM ID.Returns:
Raises:
Example:
organization = await cloud.update_organization(
org_id="<YOUR-ORG-ID>",
name="Artoo's Org",
public_namespace="artoo"
)
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization to update.name
(*string) (optional): If provided, updates the org’s name.publicNamespace
(*string) (optional): If provided, sets the org’s namespace if it hasn’t already been set.region
(*string) (optional): If provided, updates the org’s region.cid
(*string) (optional): If provided, updates the org’s CRM ID.Returns:
Example:
name := "Artoo's Org"
publicNamespace := "artoo"
organization, err := client.UpdateOrganization(ctx, "<YOUR-ORG-ID>", &name, &publicNamespace, nil, nil)
if err != nil {
log.Fatalf("Failed to update organization: %v", err)
}
fmt.Printf("Updated organization: %s\n", organization.Name)
For more information, see the Go SDK Docs.
Parameters:
organizationId
(string) (required): The id of the organization to update.name
(string) (optional): Optional name to update the organization with.publicNamespace
(string) (optional): Optional namespace to update the organization with.region
(string) (optional): Optional region to update the organization with.cid
(string) (optional): Optional CRM ID to update the organization with.Returns:
Example:
const organization = await appClient.updateOrganization(
'<YOUR-ORGANIZATION-ID>',
'newName'
);
For more information, see the TypeScript SDK Docs.
Delete an organization.
Parameters:
org_id
(str) (required): The ID of the organization. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
await cloud.delete_organization("<YOUR-ORG-ID>")
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
err := client.DeleteOrganization(ctx, "<YOUR-ORG-ID>")
if err != nil {
log.Fatalf("Failed to delete organization: %v", err)
}
For more information, see the Go SDK Docs.
Parameters:
organizationId
(string) (required): The id of the organization to delete.Returns:
Example:
await appClient.deleteOrganization('<YOUR-ORGANIZATION-ID>');
For more information, see the TypeScript SDK Docs.
List the members and invites of the organization that you are currently authenticated to.
Parameters:
org_id
(str) (required): The ID of the organization to list members of. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
member_list, invite_list = await cloud.list_organization_members("<YOUR-ORG-ID>")
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization to list members of. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
memberList, inviteList, err := client.ListOrganizationMembers(ctx, "<YOUR-ORG-ID>")
if err != nil {
log.Fatalf("Failed to list organization members: %v", err)
}
fmt.Printf("Found %d members and %d invites\n", len(memberList), len(inviteList))
For more information, see the Go SDK Docs.
Parameters:
organizationId
(string) (required): The id of the organization to query.Returns:
Example:
const members = await appClient.listOrganizationMembers(
'<YOUR-ORGANIZATION-ID>'
);
For more information, see the TypeScript SDK Docs.
Create an organization invite and send it by email.
Parameters:
org_id
(str) (required): The ID of the organization to create an invite for. You can obtain your organization ID from the Viam app’s organization settings page.email
(str) (required): The email address to send the invite to.authorizations
(List[viam.proto.app.Authorization]) (optional): Specifications of the authorizations to include in the invite. If not provided, full owner permissions will be granted.send_email_invite
(bool) (required): Whether or not an email should be sent to the recipient of an invite. The user must accept the email to be added to the associated authorizations. When set to false, the user automatically receives the associated authorization on the next login of the user with the associated email address.Returns:
Raises:
Example:
await cloud.create_organization_invite("<YOUR-ORG-ID>", "youremail@email.com")
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization to create an invite for. You can obtain your organization ID from the Viam app’s organization settings page.email
(string) (required): The email address to send the invite to.authorizations
([]*app.Authorization) (optional): Specifications of the authorizations to include in the invite. If not provided, full owner permissions will be granted.sendEmailInvite
(*bool) (optional): Whether or not an email should be sent to the recipient of an invite. Defaults to true.Returns:
Example:
invite, err := client.CreateOrganizationInvite(ctx, "<YOUR-ORG-ID>", "youremail@email.com", nil, nil)
if err != nil {
log.Fatalf("Failed to create organization invite: %v", err)
}
fmt.Printf("Created invite for: %s\n", invite.Email)
For more information, see the Go SDK Docs.
Parameters:
organizationId
(string) (required): The id of the organization to create the invite for.email
(string) (required): The email address of the user to generate an invite for.authorizations
(Authorization) (required): The authorizations to associate with the new invite.sendEmailInvite
(boolean) (optional): Bool of whether to send an email invite (true) or
automatically add a user. Defaults to true.Returns:
Example:
const auth = new VIAM.appApi.Authorization({
authorizationType: 'role',
authorizationId: 'organization_operator',
organizationId: '<YOUR-ORGANIZATION-ID>',
resourceId: '<YOUR-RESOURCE-ID>', // The resource to grant access to
resourceType: 'organization', // The type of resource to grant access to
identityId: '<YOUR-USER-ID>', // The user id of the user to grant access to (optional)
roleId: 'owner', // The role to grant access to
identityType: 'user',
});
const invite = await appClient.createOrganizationInvite(
'<YOUR-ORGANIZATION-ID>',
'youremail@email.com',
[auth]
);
For more information, see the TypeScript SDK Docs.
Get a list of all machines in a specified location.
Parameters:
location_id
(str) (optional): ID of the location to retrieve the machines from. Defaults to the location ID provided at AppClient instantiation.Returns:
Raises:
Example:
list_of_machines = await cloud.list_robots(location_id="123ab12345")
For more information, see the Python SDK Docs.
Parameters:
locationID
(string) (required): ID of the location to retrieve the machines from.Returns:
Example:
listOfMachines, err := client.ListRobots(ctx, "123ab12345")
if err != nil {
log.Fatalf("Failed to list robots: %v", err)
}
for _, robot := range listOfMachines {
fmt.Printf("Robot: %s (ID: %s)\n", robot.Name, robot.Id)
}
For more information, see the Go SDK Docs.
Parameters:
locId
(string) (required): The ID of the location to list robots for.Returns:
Example:
const robots = await appClient.listRobots('<YOUR-LOCATION-ID>');
For more information, see the TypeScript SDK Docs.
Create a new machine.
Parameters:
name
(str) (required): Name of the new machine.location_id
(str) (optional): ID of the location under which to create the machine. Defaults to the current authorized location.Returns:
Raises:
Example:
new_machine_id = await cloud.new_robot(name="beepboop", location_id="my-location-id")
For more information, see the Python SDK Docs.
Parameters:
name
(string) (required): Name of the new machine.locationID
(string) (required): ID of the location under which to create the machine.Returns:
Example:
newMachineID, err := client.NewRobot(ctx, "beepboop", "my-location-id")
if err != nil {
log.Fatalf("Failed to create new robot: %v", err)
}
fmt.Printf("Created new robot with ID: %s\n", newMachineID)
For more information, see the Go SDK Docs.
Parameters:
locId
(string) (required): The ID of the location to create the robot in.name
(string) (required): The name of the new robot.Returns:
Example:
const robotId = await appClient.newRobot(
'<YOUR-LOCATION-ID>',
'newRobot'
);
For more information, see the TypeScript SDK Docs.
Get a machine by its ID.
Parameters:
robot_id
(str) (required): ID of the machine to get. You can copy this value from the URL of the machine’s page.Returns:
Raises:
Example:
machine = await cloud.get_robot(robot_id="1a123456-x1yz-0ab0-a12xyzabc")
For more information, see the Python SDK Docs.
Parameters:
robotID
(string) (required): ID of the machine to get. You can copy this value from the URL of the machine’s page.Returns:
Example:
machine, err := client.GetRobot(ctx, "1a123456-x1yz-0ab0-a12xyzabc")
if err != nil {
log.Fatalf("Failed to get robot: %v", err)
}
fmt.Printf("Robot: %s\n", machine.Name)
For more information, see the Go SDK Docs.
Parameters:
id
(string) (required): The ID of the robot.Returns:
Example:
const robot = await appClient.getRobot('<YOUR-ROBOT-ID>');
For more information, see the TypeScript SDK Docs.
Create and name a location under the organization you are currently authenticated to. Optionally, put the new location under a specified parent location.
Parameters:
org_id
(str) (required): The ID of the organization to create the location under. You can obtain your organization ID from the Viam app’s organization settings page.name
(str) (required): Name of the location.parent_location_id
(str) (optional): Optional parent location to put the location under. Defaults to a root-level location if no location ID is provided.Returns:
Raises:
Example:
my_new_location = await cloud.create_location(org_id="<YOUR-ORG-ID>", name="Robotville", parent_location_id="111ab12345")
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization to create the location under. You can obtain your organization ID from the Viam app’s organization settings page.name
(string) (required): Name of the location.parentLocationID
(*string) (optional): Optional parent location to put the location under. Defaults to a root-level location if no location ID is provided.Returns:
Example:
parentLocationID := "111ab12345"
myNewLocation, err := client.CreateLocation(ctx, "<YOUR-ORG-ID>", "Robotville", &parentLocationID)
if err != nil {
log.Fatalf("Failed to create location: %v", err)
}
fmt.Printf("Created location: %s\n", myNewLocation.Name)
For more information, see the Go SDK Docs.
Parameters:
organizationId
(string) (required): The ID of the organization to create the location
under.name
(string) (required): The name of the location to create.parentLocationId
(string) (optional): Optional name of a parent location to create the
new location under.Returns:
Example:
const location = await appClient.createLocation(
'<YOUR-ORGANIZATION-ID>',
'name'
);
For more information, see the TypeScript SDK Docs.
Get a list of all locations under the organization you are currently authenticated to.
Parameters:
org_id
(str) (required): The ID of the org to list locations for. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
locations = await cloud.list_locations("<YOUR-ORG-ID>")
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the org to list locations for. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
locations, err := client.ListLocations(ctx, "<YOUR-ORG-ID>")
if err != nil {
log.Fatalf("Failed to list locations: %v", err)
}
for _, location := range locations {
fmt.Printf("Location: %s (ID: %s)\n", location.Name, location.Id)
});
For more information, see the Go SDK Docs.
Parameters:
organizationId
(string) (required): The ID of the organization to query.Returns:
Example:
const locations = await appClient.listLocations(
'<YOUR-ORGANIZATION-ID>'
For more information, see the TypeScript SDK Docs.
Create a new API key.
Parameters:
org_id
(str) (required): The ID of the organization to create the key for. You can obtain your organization ID from the Viam app’s organization settings page.authorizations
(List[APIKeyAuthorization]) (required): A list of authorizations to associate with the key.name
(str) (optional): A name for the key. If None, defaults to the current timestamp.Returns:
Raises:
Example:
from viam.app.app_client import APIKeyAuthorization
auth = APIKeyAuthorization(
role="owner",
resource_type="robot",
resource_id="your-machine-id123"
)
api_key, api_key_id = cloud.create_key(
org_id="<YOUR-ORG-ID>",
authorizations=[auth],
name="my_key"
)
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization to create the key for. You can obtain your organization ID from the Viam app’s organization settings page.authorizations
([]*app.Authorization) (required): A list of authorizations to associate with the key.name
(string) (optional): A name for the key. If empty, defaults to the current timestamp.Returns:
Example:
auth := &app.Authorization{
AuthorizationType: "role",
AuthorizationId: "owner",
ResourceType: "robot",
ResourceId: "your-machine-id123",
}
apiKey, apiKeyID, err := client.CreateKey(ctx, "<YOUR-ORG-ID>", []*app.Authorization{auth}, "my_key")
if err != nil {
log.Fatalf("Failed to create key: %v", err)
}
fmt.Printf("Created API key: %s (ID: %s)\n", apiKey, apiKeyID)
For more information, see the Go SDK Docs.
Parameters:
authorizations
(Authorization) (required): The list of authorizations to provide for the API key.name
(string) (optional): An optional name for the key. If none is passed, defaults to
present timestamp.Returns:
For more information, see the TypeScript SDK Docs.
List all keys for the organization that you are currently authenticated to.
Parameters:
org_id
(str) (required): The ID of the organization to list API keys for. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
keys = await cloud.list_keys(org_id="<YOUR-ORG-ID>")
For more information, see the Python SDK Docs.
Parameters:
orgID
(string) (required): The ID of the organization to list API keys for. You can obtain your organization ID from the Viam app’s organization settings page.Returns:
Example:
keys, err := client.ListKeys(ctx, "<YOUR-ORG-ID>")
if err != nil {
log.Fatalf("Failed to list keys: %v", err)
}
for _, key := range keys {
fmt.Printf("API Key: %s\n", key.ApiKey.Name)
}
For more information, see the Go SDK Docs.
Parameters:
orgId
(string) (required): The ID of the organization to query.Returns:
Example:
const keys = await appClient.listKeys('<YOUR-ORGANIZATION-ID>');
For more information, see the TypeScript SDK Docs.
Delete an API key.
Parameters:
id
(str) (required): The ID of the API key.Returns:
Example:
await cloud.delete_key("key-id")
For more information, see the Python SDK Docs.
Parameters:
id
(string) (required): The ID of the API key.Returns:
Example:
err := client.DeleteKey(ctx, "key-id")
if err != nil {
log.Fatalf("Failed to delete key: %v", err)
}
For more information, see the Go SDK Docs.
Parameters:
id
(string) (required): The ID of the key to delete.Returns:
Example:
await appClient.deleteKey('<YOUR-KEY-ID>');
For more information, see the TypeScript SDK Docs.
Rotate an API key.
Parameters:
id
(str) (required): The ID of the key to be rotated.Returns:
Example:
id, key = await cloud.rotate_key("key-id")
For more information, see the Python SDK Docs.
Parameters:
id
(string) (required): The ID of the key to be rotated.Returns:
Example:
keyID, key, err := client.RotateKey(ctx, "key-id")
if err != nil {
log.Fatalf("Failed to rotate key: %v", err)
}
fmt.Printf("Rotated key: %s (ID: %s)\n", key, keyID)
For more information, see the Go SDK Docs.
Parameters:
id
(string) (required): The ID of the key to rotate.Returns:
Example:
const key = await appClient.rotateKey('<YOUR-KEY-ID>');
For more information, see the TypeScript SDK Docs.
To copy the ID of your machine part, select the part status dropdown to the right of your machine’s location and name on the top of its page and click the copy icon next to Part ID:
To copy the ID of your machine, click the … (Actions) button in the upper-right corner of your machine’s page, then click Copy machine ID:
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!