UserInvitation
UserInvitation
UserInvitation names one user and the roles to give that user. The methods that take it read different properties.
When to Use This Class: Use this class to share a stack, change the roles of stack users, or invite users to an organization.
Conceptual Role: Acts as one item of the list that Stack.Share, Stack.UpdateUserRole, and Organization.AddUser take. The SDK builds each request body from the properties, so the class has no JSON key names of its own.
Returns: UserInvitation. One user and the roles to give that user.
Class-Level Notes
Each method reads different properties.
- The Share method of Stack reads Email and Roles, and ignores Uid.
- The UpdateUserRole method of Stack reads Uid and Roles, and ignores Email.
- The AddUser method of Organization reads Email and Roles.
The SDK needs every property it reads.
- A null value in a property that a method reads makes that method throw while it builds the request body. A missing Email or Uid throws ArgumentNullException, and a missing Roles list throws NullReferenceException.
- Share and UpdateUserRole key the request body by Email or Uid. Two items with the same key make them throw ArgumentException.
Properties
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| string? | No | null | Email address of the user. Read by Share and AddUser. | |
| Uid | string? | No | null | UID of an existing user. Read by UpdateUserRole. |
| Roles | List<string>? | No | null | UIDs of the roles to give the user. |
Method Index
UserInvitation has no methods. Set its properties and pass it to the methods named above.
Class-Level Snippet
The snippet below shares a stack with a new user and then changes the roles of an existing user.
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
Stack stack = client.Stack("<API_KEY>");
List<UserInvitation> invitations = new List<UserInvitation>()
{
new UserInvitation() { Email = "<EMAIL>", Roles = new List<string>() { "<ROLE_UID>" } }
};
List<UserInvitation> usersRole = new List<UserInvitation>()
{
new UserInvitation() { Uid = "<USER_UID>", Roles = new List<string>() { "<ROLE_UID>" } }
};
try
{
ContentstackResponse shared = stack.Share(invitations);
Console.WriteLine(shared.OpenJsonObjectResponse().ToJsonString());
ContentstackResponse updated = stack.UpdateUserRole(usersRole);
Console.WriteLine(updated.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}