Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS-908: Document part 1 of the cloud app API and move robot API #1706

Merged
merged 21 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
398 changes: 7 additions & 391 deletions docs/program/apis/_index.md

Large diffs are not rendered by default.

206 changes: 206 additions & 0 deletions docs/program/apis/cloud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
---
title: "Managing Your Fleet with Viam's Cloud API"
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
linkTitle: "Cloud Management"
weight: 20
type: "docs"
description: "How to use the cloud API with Viam's client SDKs."
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
tags: ["cloud", "sdk", "viam-server", "networking", "apis", "robot api", "cloud management"]
---

The cloud app API allows you to [manage your robot fleet](/manage/fleet/) with code instead of through the [Viam app](https://app.viam.com/).
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
Functionality includes:
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

- create and manage organizations, locations, and individual robots
- manage permissions and authorization
- create and manage fragments

{{% alert title="Support Notice" color="note" %}}

As of August 24, 2023, cloud app API methods are only available in the Python SDK.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

{{% /alert %}}

## API

{{% alert title="Tip" color="tip" %}}
Copy link
Contributor

@andf-viam andf-viam Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if this is required for every usage of the Cloud API, I would recommend making this a prerequisite step of some kind, rather than a skippable Tip.

The copy "To use ..." is perfect though, that's an ideal intro.

The outro text "Then, run methods on..." could then be something like:

Once you have instantiated an AppClient, you can run Cloud API methods against the cloud object according to the code examples for each method below.

Or similar. Not sure how to introduce cloud here, though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Maybe I should make it a section analogous to the "Control your ___ with..." section on component pages like https://docs.viam.com/components/base/#control-your-base-with-viams-client-sdk-libraries?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! That looks like just what we need here!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd done it as a tip initially because it is different so didn't want it to look as though it wasn't different, but I think it'll work! will do

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh also I may have looked and seen this as a tip: https://docs.viam.com/services/vision/#api

Copy link
Contributor

@andf-viam andf-viam Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh I could see that tip having a similar problem there as well: seemingly-skippable, yet required! Anyways, definitely out of scope for this PR!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, and on many other service pages as well! Though personally I think the tips are so colorful and eye-catching that it might be ok esp if we changed them to important or something. But indeed a problem for another PR!


To use the Viam cloud app API, you need to instantiate a [`ViamClient`](https://python.viam.dev/autoapi/viam/app/viam_client/index.html#viam.app.viam_client.ViamClient) and then instantiate an [`AppClient`](https://python.viam.dev/autoapi/viam/app/app_client/index.html#viam.app.app_client.AppClient):

```python {class="line-numbers linkable-line-numbers"}
from viam.rpc.dial import DialOptions, Credentials
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
from viam.app.viam_client import ViamClient

async def connect() -> ViamClient:
dial_options = DialOptions(
auth_entity='mrroboto.this_is_just_an_example.viam.cloud', # The URL of your robot.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
credentials=Credentials(
type='robot-location-secret',
payload='YOUR ROBOT LOCATION SECRET' # The location secret of your robot
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
)
)
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 the cloud app API methods on
cloud = await viam_client.app_client()
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
```

Then, run methods on the `AppClient` according to the code examples for each method below.

{{% /alert %}}

The cloud API supports the following methods:
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

{{< readfile "/static/include/services/apis/cloud.md" >}}

### ListOrganizations

List the organizations the user is an authorized user of.

{{< tabs >}}
{{% tab name="Python" %}}

**Parameters:**

- None

**Returns:**

- [(List[viam.proto.app.Organization])](https://python.viam.dev/autoapi/viam/proto/app/index.html#viam.proto.app.Organization): A list of the organization or organizations of which the user is an authorized owner.

```python {class="line-numbers linkable-line-numbers"}
org_list = await cloud.list_organizations()
```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/app/app_client/index.html#viam.app.app_client.AppClient.list_organizations).

{{% /tab %}}
{{< /tabs >}}

### ListOrganizationMembers

List the members and invites of the currently authenticated-to organization.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

{{< tabs >}}
{{% tab name="Python" %}}

**Parameters:**

- None

**Returns:**

- [(Tuple[List[viam.proto.app.OrganizationMember]])](https://python.viam.dev/autoapi/viam/proto/app/index.html#viam.proto.app.OrganizationMember): A tuple containing to lists:
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
- The first (`[0]`) is a list of organization members.
- The second (`[1]`) is a list of organization invites.

```python {class="line-numbers linkable-line-numbers"}
member_list = await cloud.list_organization_members()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest breaking up the return here to (member_list, invite_list) or something like that.

JessamyT marked this conversation as resolved.
Show resolved Hide resolved
```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/app/app_client/index.html#viam.app.app_client.AppClient.list_organization_members).

{{% /tab %}}
{{< /tabs >}}

### GetOrganizationNamespaceAvailability

Check the availability of an organization namespace.

{{< tabs >}}
{{% tab name="Python" %}}

**Parameters:**

- `public_namespace` [(string)](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str): The organization namespace to check.
Namespaces can only contain lowercase alphanumeric and dash characters.

**Raises:**

- GRPCError: An error is raised if an invalid namespace (for example, `""`) is provided.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

**Returns:**

- [(bool)](https://docs.python.org/3/library/stdtypes.html#bltin-boolean-values): `True` if the provided namespace is available.

```python {class="line-numbers linkable-line-numbers"}
available = await cloud.get_organization_namespace_availability(public_namespace="my-cool-organization")
```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/app/app_client/index.html#viam.app.app_client.AppClient.get_organization_namespace_availability).

{{% /tab %}}
{{< /tabs >}}

### UpdateOrganizationInviteAuthorizations

Update the authorizations attached to an organization invite that has already been created.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

{{< tabs >}}
{{% tab name="Python" %}}

**Parameters:**

- `email` [(string)](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str): Email of the user the invite was sent to.
- `add_authorization` [(Optional[List[viam.proto.app.Authorization]])](https://python.viam.dev/autoapi/viam/proto/app/index.html#viam.proto.app.Authorization): Optional list of authorizations to add to the invite.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
- `remove_authorization` [(Optional[List[viam.proto.app.Authorization]])](https://python.viam.dev/autoapi/viam/proto/app/index.html#viam.proto.app.Authorization): Optional list of authorizations to remove from the invite.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

**Raises:**

- GRPCError: An error is raised if no authorizations are passed or if an invalid combination of authorizations is passed (for example, an authorization to remove when the invite only contains one authorization).
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

**Returns:**

- [(OrganizationInvite)](https://python.viam.dev/autoapi/viam/proto/app/index.html#viam.proto.app.OrganizationInvite): The updated invitation.

```python {class="line-numbers linkable-line-numbers"}
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
update_invite = await cloud.update_organization_invite_authorizations(
email="[email protected]",
remove_authorization=[
authorization_type="some type of auth",
authorization_id="identifier",
resource_type="abc",
resource_id="resource-identifier123",
identity_id="id12345",
organization_id="org_id_123"
]
)
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/app/app_client/index.html#viam.app.app_client.AppClient.update_organization_invite_authorizations).

{{% /tab %}}
{{< /tabs >}}

### NewRobot

Create a new robot.

{{< tabs >}}
{{% tab name="Python" %}}

**Parameters:**

- `name` [(string)](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str): Name of the new robot.
- `location_id` [(Optional[string])](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str): ID of the location under which to create the new robot.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved
Defaults to the current authorized location.

**Raises:**

- GRPCError: An error is raised if an invalid location ID is passed or one isn't passed and no location ID was provided at `AppClient` instantiation.
JessamyT marked this conversation as resolved.
Show resolved Hide resolved

**Returns:**

- [(string)](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str): The new robot's ID.

```python {class="line-numbers linkable-line-numbers"}
new_robot_id = await cloud.new_robot(name="beepboop")
```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/app/app_client/index.html#viam.app.app_client.AppClient.get_organization_namespace_availability).

{{% /tab %}}
{{< /tabs >}}
Loading