github.com/anthropics/anthropic-sdk-go@v1.70.1/betaorganizationuser.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  // BetaOrganizationUserService 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 [NewBetaOrganizationUserService] method instead.
    30  type BetaOrganizationUserService struct {
    31  	Options []option.RequestOption
    32  }
    33  
    34  // NewBetaOrganizationUserService 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 NewBetaOrganizationUserService(opts ...option.RequestOption) (r BetaOrganizationUserService) {
    38  	r = BetaOrganizationUserService{}
    39  	r.Options = opts
    40  	return
    41  }
    42  
    43  // Retrieve a member of the organization by user ID.
    44  func (r *BetaOrganizationUserService) Get(ctx context.Context, userID string, opts ...option.RequestOption) (res *BetaOrganizationUser, err error) {
    45  	opts = slices.Concat(r.Options, opts)
    46  	if userID == "" {
    47  		err = errors.New("missing required user_id parameter")
    48  		return nil, err
    49  	}
    50  	path := fmt.Sprintf("v1/organizations/users/%s?beta=true", userID)
    51  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
    52  	return res, err
    53  }
    54  
    55  // Update a member's organization role.
    56  func (r *BetaOrganizationUserService) Update(ctx context.Context, userID string, body BetaOrganizationUserUpdateParams, opts ...option.RequestOption) (res *BetaOrganizationUser, err error) {
    57  	opts = slices.Concat(r.Options, opts)
    58  	if userID == "" {
    59  		err = errors.New("missing required user_id parameter")
    60  		return nil, err
    61  	}
    62  	path := fmt.Sprintf("v1/organizations/users/%s?beta=true", userID)
    63  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
    64  	return res, err
    65  }
    66  
    67  // List the organization's members.
    68  func (r *BetaOrganizationUserService) List(ctx context.Context, query BetaOrganizationUserListParams, opts ...option.RequestOption) (res *pagination.Page[BetaOrganizationUser], err error) {
    69  	var raw *http.Response
    70  	opts = slices.Concat(r.Options, opts)
    71  	opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
    72  	path := "v1/organizations/users?beta=true"
    73  	cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
    74  	if err != nil {
    75  		return nil, err
    76  	}
    77  	err = cfg.Execute()
    78  	if err != nil {
    79  		return nil, err
    80  	}
    81  	res.SetPageConfig(cfg, raw)
    82  	return res, nil
    83  }
    84  
    85  // List the organization's members.
    86  func (r *BetaOrganizationUserService) ListAutoPaging(ctx context.Context, query BetaOrganizationUserListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaOrganizationUser] {
    87  	return pagination.NewPageAutoPager(r.List(ctx, query, opts...))
    88  }
    89  
    90  // Remove a member from the organization.
    91  func (r *BetaOrganizationUserService) Remove(ctx context.Context, userID string, opts ...option.RequestOption) (res *BetaOrganizationUserRemoveResponse, err error) {
    92  	opts = slices.Concat(r.Options, opts)
    93  	if userID == "" {
    94  		err = errors.New("missing required user_id parameter")
    95  		return nil, err
    96  	}
    97  	path := fmt.Sprintf("v1/organizations/users/%s?beta=true", userID)
    98  	err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
    99  	return res, err
   100  }
   101  
   102  type BetaOrganizationUser struct {
   103  	// ID of the User.
   104  	ID string `json:"id" api:"required"`
   105  	// RFC 3339 datetime string indicating when the User joined the Organization.
   106  	AddedAt time.Time `json:"added_at" api:"required" format:"date-time"`
   107  	// Email of the User.
   108  	Email string `json:"email" api:"required"`
   109  	// Name of the User.
   110  	Name string `json:"name" api:"required"`
   111  	// Organization role of the User.
   112  	//
   113  	// Any of "admin", "billing", "claude_code_user", "developer", "managed",
   114  	// "membership_admin", "owner", "primary_owner", "user".
   115  	Role BetaOrganizationRole `json:"role" api:"required"`
   116  	// Object type.
   117  	//
   118  	// For Users, this is always `"user"`.
   119  	Type constant.User `json:"type" default:"user"`
   120  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   121  	JSON struct {
   122  		ID          respjson.Field
   123  		AddedAt     respjson.Field
   124  		Email       respjson.Field
   125  		Name        respjson.Field
   126  		Role        respjson.Field
   127  		Type        respjson.Field
   128  		ExtraFields map[string]respjson.Field
   129  		raw         string
   130  	} `json:"-"`
   131  }
   132  
   133  // Returns the unmodified JSON received from the API
   134  func (r BetaOrganizationUser) RawJSON() string { return r.JSON.raw }
   135  func (r *BetaOrganizationUser) UnmarshalJSON(data []byte) error {
   136  	return apijson.UnmarshalRoot(data, r)
   137  }
   138  
   139  type BetaOrganizationUserRemoveResponse struct {
   140  	// ID of the User.
   141  	ID string `json:"id" api:"required"`
   142  	// Deleted object type.
   143  	//
   144  	// For Users, this is always `"user_deleted"`.
   145  	Type constant.UserDeleted `json:"type" default:"user_deleted"`
   146  	// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
   147  	JSON struct {
   148  		ID          respjson.Field
   149  		Type        respjson.Field
   150  		ExtraFields map[string]respjson.Field
   151  		raw         string
   152  	} `json:"-"`
   153  }
   154  
   155  // Returns the unmodified JSON received from the API
   156  func (r BetaOrganizationUserRemoveResponse) RawJSON() string { return r.JSON.raw }
   157  func (r *BetaOrganizationUserRemoveResponse) UnmarshalJSON(data []byte) error {
   158  	return apijson.UnmarshalRoot(data, r)
   159  }
   160  
   161  type BetaOrganizationUserUpdateParams struct {
   162  	// New role for the User.
   163  	//
   164  	// The accepted values depend on the organization type. Console and API
   165  	// organizations accept `user`, `developer`, `billing`, and `claude_code_user`;
   166  	// `admin` cannot be assigned through the API. Claude Enterprise organizations
   167  	// accept `user` and `managed`.
   168  	//
   169  	// Any of "billing", "claude_code_user", "developer", "managed", "user".
   170  	Role BetaOrganizationUserUpdateParamsRole `json:"role,omitzero" api:"required"`
   171  	paramObj
   172  }
   173  
   174  func (r BetaOrganizationUserUpdateParams) MarshalJSON() (data []byte, err error) {
   175  	type shadow BetaOrganizationUserUpdateParams
   176  	return param.MarshalObject(r, (*shadow)(&r))
   177  }
   178  func (r *BetaOrganizationUserUpdateParams) UnmarshalJSON(data []byte) error {
   179  	return apijson.UnmarshalRoot(data, r)
   180  }
   181  
   182  // New role for the User.
   183  //
   184  // The accepted values depend on the organization type. Console and API
   185  // organizations accept `user`, `developer`, `billing`, and `claude_code_user`;
   186  // `admin` cannot be assigned through the API. Claude Enterprise organizations
   187  // accept `user` and `managed`.
   188  type BetaOrganizationUserUpdateParamsRole string
   189  
   190  const (
   191  	BetaOrganizationUserUpdateParamsRoleBilling        BetaOrganizationUserUpdateParamsRole = "billing"
   192  	BetaOrganizationUserUpdateParamsRoleClaudeCodeUser BetaOrganizationUserUpdateParamsRole = "claude_code_user"
   193  	BetaOrganizationUserUpdateParamsRoleDeveloper      BetaOrganizationUserUpdateParamsRole = "developer"
   194  	BetaOrganizationUserUpdateParamsRoleManaged        BetaOrganizationUserUpdateParamsRole = "managed"
   195  	BetaOrganizationUserUpdateParamsRoleUser           BetaOrganizationUserUpdateParamsRole = "user"
   196  )
   197  
   198  type BetaOrganizationUserListParams struct {
   199  	// ID of the object to use as a cursor for pagination. When provided, returns the
   200  	// page of results immediately after this object.
   201  	AfterID param.Opt[string] `query:"after_id,omitzero" json:"-"`
   202  	// ID of the object to use as a cursor for pagination. When provided, returns the
   203  	// page of results immediately before this object.
   204  	BeforeID param.Opt[string] `query:"before_id,omitzero" json:"-"`
   205  	// Filter by user email.
   206  	Email param.Opt[string] `query:"email,omitzero" format:"email" json:"-"`
   207  	// Number of items to return per page.
   208  	//
   209  	// Defaults to `20`. Ranges from `1` to `1000`.
   210  	Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
   211  	// Filter to items whose `role` equals one of the supplied values. Repeatable;
   212  	// values are OR'ed together.
   213  	//
   214  	// Accepted values depend on the organization type: Console and API organizations
   215  	// accept `user`, `developer`, `billing`, `admin`, and `claude_code_user`; Claude
   216  	// Enterprise organizations accept `user`, `owner`, `primary_owner`,
   217  	// `membership_admin`, and `managed`.
   218  	Roles []string `query:"roles,omitzero" json:"-"`
   219  	paramObj
   220  }
   221  
   222  // URLQuery serializes [BetaOrganizationUserListParams]'s query parameters as
   223  // `url.Values`.
   224  func (r BetaOrganizationUserListParams) URLQuery() (v url.Values, err error) {
   225  	return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
   226  		ArrayFormat:  apiquery.ArrayQueryFormatBrackets,
   227  		NestedFormat: apiquery.NestedQueryFormatBrackets,
   228  	})
   229  }