github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationinvite.go (about)

     1  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
     2  
     3  package anthropic
     4  
     5  import (
     6  	"context"
     7  	"errors"
     8  	"fmt"
     9  	"net/http"
    10  	"net/url"
    11  	"slices"
    12  	"time"
    13  
    14  	"github.com/anthropics/anthropic-sdk-go/internal/apijson"
    15  	"github.com/anthropics/anthropic-sdk-go/internal/apiquery"
    16  	"github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
    17  	"github.com/anthropics/anthropic-sdk-go/option"
    18  	"github.com/anthropics/anthropic-sdk-go/packages/pagination"
    19  	"github.com/anthropics/anthropic-sdk-go/packages/param"
    20  	"github.com/anthropics/anthropic-sdk-go/packages/respjson"
    21  	"github.com/anthropics/anthropic-sdk-go/shared/constant"
    22  )
    23  
    24  // BetaOrganizationInviteService contains methods and other services that help with
    25  // interacting with the anthropic API.
    26  //
    27  // Note, unlike clients, this service does not read variables from the environment
    28  // automatically. You should not instantiate this service directly, and instead use
    29  // the [NewBetaOrganizationInviteService] method instead.
    30  type BetaOrganizationInviteService struct {
    31  	Options []option.RequestOption
    32  }
    33  
    34  // NewBetaOrganizationInviteService generates a new service that applies the given
    35  // options to each request. These options are applied after the parent client's
    36  // options (if there is one), and before any request-specific options.
    37  func NewBetaOrganizationInviteService(opts ...option.RequestOption) (r BetaOrganizationInviteService) {
    38  	r = BetaOrganizationInviteService{}
    39  	r.Options = opts
    40  	return
    41  }
    42  
    43  // Invite a user to join the organization by email.
    44  //
    45  // On plans that draw members from a finite pool of purchased seats, the invite
    46  // automatically consumes a seat from the lowest tier with availability; there is
    47  // no seat-tier parameter. When no seat is free the request fails with a 400 error
    48  // rather than purchasing a seat.
    49  func (r *BetaOrganizationInviteService) New(ctx context.Context, body BetaOrganizationInviteNewParams, opts ...option.RequestOption) (res *BetaOrganizationInvite, err error) {
    50  	opts = slices.Concat(r.Options, opts)
    51  	path := "v1/organizations/invites?beta=true"
    52  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
    53  	return res, err
    54  }
    55  
    56  // Retrieve an invite by ID.
    57  func (r *BetaOrganizationInviteService) Get(ctx context.Context, inviteID string, opts ...option.RequestOption) (res *BetaOrganizationInvite, err error) {
    58  	opts = slices.Concat(r.Options, opts)
    59  	if inviteID == "" {
    60  		err = errors.New("missing required invite_id parameter")
    61  		return nil, err
    62  	}
    63  	path := fmt.Sprintf("v1/organizations/invites/%s?beta=true", inviteID)
    64  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
    65  	return res, err
    66  }
    67  
    68  // List the organization's invites.
    69  func (r *BetaOrganizationInviteService) List(ctx context.Context, query BetaOrganizationInviteListParams, opts ...option.RequestOption) (res *pagination.Page[BetaOrganizationInvite], err error) {
    70  	var raw *http.Response
    71  	opts = slices.Concat(r.Options, opts)
    72  	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
    73  	path := "v1/organizations/invites?beta=true"
    74  	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
    75  	if err != nil {
    76  		return nil, err
    77  	}
    78  	err = cfg.Execute()
    79  	if err != nil {
    80  		return nil, err
    81  	}
    82  	res.SetPageConfig(cfg, raw)
    83  	return res, nil
    84  }
    85  
    86  // List the organization's invites.
    87  func (r *BetaOrganizationInviteService) ListAutoPaging(ctx context.Context, query BetaOrganizationInviteListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaOrganizationInvite] {
    88  	return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
    89  }
    90  
    91  // Delete a pending invite.
    92  func (r *BetaOrganizationInviteService) Delete(ctx context.Context, inviteID string, opts ...option.RequestOption) (res *BetaOrganizationInviteDeleteResponse, err error) {
    93  	opts = slices.Concat(r.Options, opts)
    94  	if inviteID == "" {
    95  		err = errors.New("missing required invite_id parameter")
    96  		return nil, err
    97  	}
    98  	path := fmt.Sprintf("v1/organizations/invites/%s?beta=true", inviteID)
    99  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
   100  	return res, err
   101  }
   102  
   103  type BetaOrganizationInvite struct {
   104  	// ID of the Invite.
   105  	ID string `json:"id" api:"required"`
   106  	// RFC 3339 datetime string indicating when the Invite was accepted, or null.
   107  	AcceptedAt time.Time `json:"accepted_at" api:"required" format:"date-time"`
   108  	// Email of the User being invited.
   109  	Email string `json:"email" api:"required"`
   110  	// RFC 3339 datetime string indicating when the Invite expires.
   111  	ExpiresAt time.Time `json:"expires_at" api:"required" format:"date-time"`
   112  	// RFC 3339 datetime string indicating when the Invite was created.
   113  	InvitedAt time.Time `json:"invited_at" api:"required" format:"date-time"`
   114  	// RBAC group IDs recorded on the Invite (Claude Enterprise organizations), to be
   115  	// assigned to the User when the Invite is accepted. `[]` when none.
   116  	RBACGroupIDs []string `json:"rbac_group_ids" api:"required"`
   117  	// Organization role of the User.
   118  	//
   119  	// Any of "admin", "billing", "claude_code_user", "developer", "managed",
   120  	// "membership_admin", "owner", "primary_owner", "user".
   121  	Role BetaOrganizationRole `json:"role" api:"required"`
   122  	// Status of the Invite.
   123  	//
   124  	// Any of "accepted", "deleted", "expired", "pending".
   125  	Status BetaOrganizationInviteStatus `json:"status" api:"required"`
   126  	// Object type.
   127  	//
   128  	// For Invites, this is always `"invite"`.
   129  	Type constant.Invite `json:"type" default:"invite"`
   130  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   131  	JSON struct {
   132  		ID           respjson.Field
   133  		AcceptedAt   respjson.Field
   134  		Email        respjson.Field
   135  		ExpiresAt    respjson.Field
   136  		InvitedAt    respjson.Field
   137  		RBACGroupIDs respjson.Field
   138  		Role         respjson.Field
   139  		Status       respjson.Field
   140  		Type         respjson.Field
   141  		ExtraFields  map[string]respjson.Field
   142  		raw          string
   143  	} `json:"-"`
   144  }
   145  
   146  // Returns the unmodified JSON received from the API
   147  func (r BetaOrganizationInvite) RawJSON() string { return r.JSON.raw }
   148  func (r *BetaOrganizationInvite) UnmarshalJSON(data []byte) error {
   149  	return apijson.UnmarshalRoot(data, r)
   150  }
   151  
   152  // Status of the Invite.
   153  type BetaOrganizationInviteStatus string
   154  
   155  const (
   156  	BetaOrganizationInviteStatusAccepted BetaOrganizationInviteStatus = "accepted"
   157  	BetaOrganizationInviteStatusDeleted  BetaOrganizationInviteStatus = "deleted"
   158  	BetaOrganizationInviteStatusExpired  BetaOrganizationInviteStatus = "expired"
   159  	BetaOrganizationInviteStatusPending  BetaOrganizationInviteStatus = "pending"
   160  )
   161  
   162  type BetaOrganizationInviteDeleteResponse struct {
   163  	// ID of the Invite.
   164  	ID string `json:"id" api:"required"`
   165  	// Deleted object type.
   166  	//
   167  	// For Invites, this is always `"invite_deleted"`.
   168  	Type constant.InviteDeleted `json:"type" default:"invite_deleted"`
   169  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   170  	JSON struct {
   171  		ID          respjson.Field
   172  		Type        respjson.Field
   173  		ExtraFields map[string]respjson.Field
   174  		raw         string
   175  	} `json:"-"`
   176  }
   177  
   178  // Returns the unmodified JSON received from the API
   179  func (r BetaOrganizationInviteDeleteResponse) RawJSON() string { return r.JSON.raw }
   180  func (r *BetaOrganizationInviteDeleteResponse) UnmarshalJSON(data []byte) error {
   181  	return apijson.UnmarshalRoot(data, r)
   182  }
   183  
   184  type BetaOrganizationInviteNewParams struct {
   185  	// Email of the User.
   186  	Email string `json:"email" api:"required" format:"email"`
   187  	// Role for the invited User.
   188  	//
   189  	// The accepted values depend on the organization type. Console and API
   190  	// organizations accept `user`, `developer`, `billing`, and `claude_code_user`;
   191  	// `admin` cannot be assigned through the API. Claude Enterprise organizations
   192  	// accept `user` and `managed`.
   193  	//
   194  	// Any of "billing", "claude_code_user", "developer", "managed", "user".
   195  	Role BetaOrganizationInviteNewParamsRole `json:"role,omitzero" api:"required"`
   196  	// RBAC group IDs to assign to the User when the Invite is accepted. A non-empty
   197  	// array is accepted only for a Claude Enterprise organization with RBAC groups,
   198  	// and requires the key to carry the `write:rbac_groups` scope.
   199  	RBACGroupIDs []string `json:"rbac_group_ids,omitzero"`
   200  	paramObj
   201  }
   202  
   203  func (r BetaOrganizationInviteNewParams) MarshalJSON() (data []byte, err error) {
   204  	type shadow BetaOrganizationInviteNewParams
   205  	return param.MarshalObject(r, (*shadow)(&r))
   206  }
   207  func (r *BetaOrganizationInviteNewParams) UnmarshalJSON(data []byte) error {
   208  	return apijson.UnmarshalRoot(data, r)
   209  }
   210  
   211  // Role for the invited User.
   212  //
   213  // The accepted values depend on the organization type. Console and API
   214  // organizations accept `user`, `developer`, `billing`, and `claude_code_user`;
   215  // `admin` cannot be assigned through the API. Claude Enterprise organizations
   216  // accept `user` and `managed`.
   217  type BetaOrganizationInviteNewParamsRole string
   218  
   219  const (
   220  	BetaOrganizationInviteNewParamsRoleBilling        BetaOrganizationInviteNewParamsRole = "billing"
   221  	BetaOrganizationInviteNewParamsRoleClaudeCodeUser BetaOrganizationInviteNewParamsRole = "claude_code_user"
   222  	BetaOrganizationInviteNewParamsRoleDeveloper      BetaOrganizationInviteNewParamsRole = "developer"
   223  	BetaOrganizationInviteNewParamsRoleManaged        BetaOrganizationInviteNewParamsRole = "managed"
   224  	BetaOrganizationInviteNewParamsRoleUser           BetaOrganizationInviteNewParamsRole = "user"
   225  )
   226  
   227  type BetaOrganizationInviteListParams struct {
   228  	// ID of the object to use as a cursor for pagination. When provided, returns the
   229  	// page of results immediately after this object.
   230  	AfterID param.Opt[string] `query:"after_id,omitzero" json:"-"`
   231  	// ID of the object to use as a cursor for pagination. When provided, returns the
   232  	// page of results immediately before this object.
   233  	BeforeID param.Opt[string] `query:"before_id,omitzero" json:"-"`
   234  	// Filter by the email address the Invite was sent to. Matches the same way as the
   235  	// Users list's `email` filter (normalized, case-insensitive).
   236  	Email param.Opt[string] `query:"email,omitzero" format:"email" json:"-"`
   237  	// Number of items to return per page.
   238  	//
   239  	// Defaults to `20`. Ranges from `1` to `1000`.
   240  	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
   241  	// Filter to items whose `role` equals one of the supplied values. Repeatable;
   242  	// values are OR'ed together.
   243  	//
   244  	// Accepted values depend on the organization type: Console and API organizations
   245  	// accept `user`, `developer`, `billing`, `admin`, and `claude_code_user`; Claude
   246  	// Enterprise organizations accept `user`, `owner`, `primary_owner`,
   247  	// `membership_admin`, and `managed`.
   248  	Roles []string `query:"roles,omitzero" json:"-"`
   249  	// Filter by Invite status. Repeatable; values are OR'ed together. Omit to return
   250  	// `pending`, `accepted`, and `expired` Invites alike.
   251  	//
   252  	// Any of "accepted", "expired", "pending".
   253  	Statuses []string `query:"statuses,omitzero" json:"-"`
   254  	paramObj
   255  }
   256  
   257  // URLQuery serializes [BetaOrganizationInviteListParams]'s query parameters as
   258  // `url.Values`.
   259  func (r BetaOrganizationInviteListParams) URLQuery() (v url.Values, err error) {
   260  	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
   261  		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
   262  		NestedFormat: apiquery.NestedQueryFormatBrackets,
   263  	})
   264  }