servicenow

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseURL          = "https://%s.service-now.com/api"
	TableAPIBaseURL  = BaseURL + "/now/table"
	GlobalApiBaseURL = BaseURL + "/global"

	UsersBaseUrl = TableAPIBaseURL + "/sys_user"
	UserBaseUrl  = UsersBaseUrl + "/%s"

	GroupsBaseUrl = TableAPIBaseURL + "/sys_user_group"
	GroupBaseUrl  = GroupsBaseUrl + "/%s"

	GroupMembersBaseUrl      = TableAPIBaseURL + "/sys_user_grmember"
	GroupMemberDetailBaseUrl = GroupMembersBaseUrl + "/%s"

	RolesBaseUrl           = TableAPIBaseURL + "/sys_user_role"
	UserRolesBaseUrl       = TableAPIBaseURL + "/sys_user_has_role"
	UserRoleDetailBaseUrl  = UserRolesBaseUrl + "/%s"
	GroupRolesBaseUrl      = TableAPIBaseURL + "/sys_group_has_role"
	GroupRoleDetailBaseUrl = GroupRolesBaseUrl + "/%s"

	UserRoleInheritanceBaseUrl = GlobalApiBaseURL + "/user_role_inheritance"

	// Service Catalogs.
	ServiceCatalogRequestedItemBaseUrl        = TableAPIBaseURL + "/sc_req_item"
	ServiceCatalogRequestedItemDetailsBaseUrl = ServiceCatalogRequestedItemBaseUrl + "/%s"

	ServiceCatalogRequestBaseUrl        = TableAPIBaseURL + "/sc_request"
	ServiceCatalogRequestDetailsBaseUrl = ServiceCatalogRequestBaseUrl + "/%s"

	ServiceCatalogBaseUrl         = BaseURL + "/sn_sc/servicecatalog"
	ServiceCatalogListCatalogsUrl = ServiceCatalogBaseUrl + "/catalogs"
	ServiceCatalogGetCatalogUrl   = ServiceCatalogListCatalogsUrl + "/%s"

	ServiceCatalogCategoryBaseUrl       = ServiceCatalogGetCatalogUrl + "/categories"
	ServiceCatalogCategoryDetailBaseUrl = ServiceCatalogCategoryBaseUrl + "/%s"

	ServiceCatalogItemBaseUrl      = ServiceCatalogBaseUrl + "/items"
	ServiceCatalogItemGetUrl       = ServiceCatalogItemBaseUrl + "/%s"
	ServiceCatalogItemVariablesUrl = ServiceCatalogItemGetUrl + "/variables"

	ServiceCatalogOrderItemUrl = ServiceCatalogItemGetUrl + "/order_now"

	LabelBaseUrl      = TableAPIBaseURL + "/label"
	LabelEntryBaseUrl = TableAPIBaseURL + "/label_entry"

	// To get possible states for service catalog requested item.
	ChoiceBaseUrl = TableAPIBaseURL + "/sys_choice"

	InstanceURLTemplate = `{{.Deployment}}.service-now.com`
)
View Source
const SystemAdminUserId = "6816f79cc0a8016401c5a33be04be441"

Variables

View Source
var (
	UserFields  = []string{"sys_id", "name", "roles", "user_name", "email", "first_name", "last_name", "active"}
	RoleFields  = []string{"sys_id", "grantable", "name"}
	GroupFields = []string{"sys_id", "description", "name"}
)
View Source
var LabelNotFoundErr = errors.New("label not found")

Functions

func ConvertPageToken added in v0.0.7

func ConvertPageToken(token string) (int, error)

func ConvertVariableToSchemaCustomField added in v0.0.4

func ConvertVariableToSchemaCustomField(ctx context.Context, variable *CatalogItemVariable) *v2.TicketCustomField

TODO(lauren) add validation?

func GenerateURL added in v0.0.4

func GenerateURL(baseURL string, params URLParams) (string, error)

Types

type BaseResource

type BaseResource struct {
	Id string `json:"sys_id"`
}

type Catalog added in v0.0.4

type Catalog struct {
	BaseResource
	Title         string `json:"title"`
	HasCategories bool   `json:"has_categories,omitempty"`
	HasItems      bool   `json:"has_items,omitempty"`
	Description   string `json:"description,omitempty"`
}

type CatalogItem added in v0.0.4

type CatalogItem struct {
	BaseResource
	Catalogs         []Catalog             `json:"catalogs"`
	Category         Category              `json:"category,omitempty"`
	Description      string                `json:"description"`
	Name             string                `json:"name"`
	ShortDescription string                `json:"short_description"`
	SysClassName     string                `json:"sys_class_name"`
	Type             string                `json:"type"`
	Variables        []CatalogItemVariable `json:"variables,omitempty"`
}

type CatalogItemResponse added in v0.0.4

type CatalogItemResponse = SingleResponse[CatalogItem]

type CatalogItemVariable added in v0.0.4

type CatalogItemVariable struct {
	Active                  bool            `json:"active"`
	Label                   string          `json:"label"`
	DynamicValueField       string          `json:"dynamic_value_field"`
	Type                    VariableTypeNew `json:"type"`
	Mandatory               bool            `json:"mandatory"`
	DisplayValue            string          `json:"displayvalue"`
	FriendlyType            string          `json:"friendly_type"`
	DisplayType             string          `json:"display_type"`
	RenderLabel             bool            `json:"render_label"`
	ReadOnly                bool            `json:"read_only"`
	Name                    string          `json:"name"`
	Attributes              string          `json:"attributes"`
	ID                      string          `json:"id"`
	Choices                 []Choice        `json:"choices"`
	Value                   string          `json:"value"`
	DynamicValueDotWalkPath string          `json:"dynamic_value_dot_walk_path"`
	HelpText                string          `json:"help_text"`
	Order                   int             `json:"order"`
	Reference               string          `json:"reference"`
	RefQualifier            string          `json:"ref_qualifier"`
}

type CatalogItemVariablesResponse added in v0.0.4

type CatalogItemVariablesResponse = ListResponse[CatalogItemVariable]

type CatalogItemsResponse added in v0.0.4

type CatalogItemsResponse = ListResponse[CatalogItem]

type CatalogsResponse added in v0.0.4

type CatalogsResponse = ListResponse[Catalog]

type CategoriesResponse added in v0.0.4

type CategoriesResponse = ListResponse[Category]

type Category added in v0.0.4

type Category struct {
	BaseResource
	Title           string        `json:"title"`
	Description     string        `json:"description,omitempty"`
	FullDescription string        `json:"full_description,omitempty"`
	ItemCount       int           `json:"count,omitempty"`
	Subcategories   []SubCategory `json:"subcategories,omitempty"`
}

type Choice added in v0.0.4

type Choice struct {
	Index int    `json:"index"`
	Label string `json:"label"`
	Value string `json:"value"`
}

type Client

type Client struct {
	TicketSchemaFilters map[string]string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(httpClient *http.Client, auth string, deployment string, ticketSchemaFilters map[string]string) (*Client, error)

func (*Client) AddLabelToRequest added in v0.0.4

func (c *Client) AddLabelToRequest(ctx context.Context, requestedItemId string, label string) (*BaseResource, error)

func (*Client) AddLabelsToRequest added in v0.0.4

func (c *Client) AddLabelsToRequest(ctx context.Context, requestedItemId string, labels []string) error

func (*Client) AddUserToGroup

func (c *Client) AddUserToGroup(ctx context.Context, record GroupMemberPayload) error

func (*Client) CreateLabel added in v0.0.4

func (c *Client) CreateLabel(ctx context.Context, label string) (*Label, error)

Create label will return an error if it already exists. First fetch the label to check if it already exists.

func (*Client) CreateServiceCatalogRequest added in v0.0.4

func (c *Client) CreateServiceCatalogRequest(ctx context.Context, catalogItemId string, payload *OrderItemPayload) (*RequestedItem, error)

Creating a service catalog request requires: 1. Add catalog item to cart (with all required variables). 2. Submit cart order.

func (*Client) GetBaseURL added in v0.0.4

func (c *Client) GetBaseURL() string

func (*Client) GetCatalogItem added in v0.0.4

func (c *Client) GetCatalogItem(ctx context.Context, catalogItemId string) (*CatalogItem, error)

func (*Client) GetCatalogItemVariables added in v0.0.4

func (c *Client) GetCatalogItemVariables(ctx context.Context, catalogItemId string) ([]CatalogItemVariable, error)

func (*Client) GetCatalogItems added in v0.0.4

func (c *Client) GetCatalogItems(ctx context.Context, paginationVars *PaginationVars) ([]CatalogItem, string, error)

func (*Client) GetCatalogs added in v0.0.4

func (c *Client) GetCatalogs(ctx context.Context, paginationVars PaginationVars) ([]Catalog, string, error)

Unused.

func (*Client) GetGroup

func (c *Client) GetGroup(ctx context.Context, groupId string) (*Group, error)

func (*Client) GetGroupToRole

func (c *Client) GetGroupToRole(ctx context.Context, groupId string, roleId string, paginationVars PaginationVars) ([]GroupToRole, string, error)

Table `sys_group_has_role` (Group to Role).

func (*Client) GetGroups

func (c *Client) GetGroups(ctx context.Context, paginationVars PaginationVars, groupIDs []string) ([]Group, string, error)

Table `sys_user_group` (Groups).

func (*Client) GetLabel added in v0.0.4

func (c *Client) GetLabel(ctx context.Context, label string) (*Label, error)

func (*Client) GetLabelsForRequestedItem added in v0.0.4

func (c *Client) GetLabelsForRequestedItem(ctx context.Context, requestedItemId string) ([]string, error)

func (*Client) GetRoles

func (c *Client) GetRoles(ctx context.Context, paginationVars PaginationVars) ([]Role, string, error)

Table `sys_user_role` (Roles).

func (*Client) GetServiceCatalogRequest added in v0.0.4

func (c *Client) GetServiceCatalogRequest(ctx context.Context, requestId string) (*ServiceCatalogRequest, error)

func (*Client) GetServiceCatalogRequestItem added in v0.0.4

func (c *Client) GetServiceCatalogRequestItem(ctx context.Context, requestItemId string) (*RequestedItem, error)

func (*Client) GetServiceCatalogRequestItems added in v0.0.4

func (c *Client) GetServiceCatalogRequestItems(ctx context.Context, reqOptions ...ReqOpt) ([]RequestedItem, string, error)

func (*Client) GetServiceCatalogRequestedItemForRequest added in v0.0.4

func (c *Client) GetServiceCatalogRequestedItemForRequest(ctx context.Context, serviceCatalogRequestId string) (*RequestedItem, error)

func (*Client) GetServiceCatalogRequestedItemStates added in v0.0.4

func (c *Client) GetServiceCatalogRequestedItemStates(ctx context.Context) ([]RequestItemState, error)

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, userId string) (*User, error)

func (*Client) GetUserToGroup

func (c *Client) GetUserToGroup(ctx context.Context, userId string, groupId string, paginationVars PaginationVars) ([]GroupMember, string, error)

Table `sys_user_grmember` (Group Members).

func (*Client) GetUserToRole

func (c *Client) GetUserToRole(ctx context.Context, userId string, roleId string, paginationVars PaginationVars) ([]UserToRole, string, error)

Table `sys_user_has_role` (User to Role).

func (*Client) GetUsers

func (c *Client) GetUsers(ctx context.Context, paginationVars PaginationVars, userIDs []string) ([]User, string, error)

Table `sys_user` (Users).

func (*Client) GrantRoleToGroup

func (c *Client) GrantRoleToGroup(ctx context.Context, record GroupToRolePayload) error

func (*Client) GrantRoleToUser

func (c *Client) GrantRoleToUser(ctx context.Context, record UserToRolePayload) error

func (*Client) OrderItemNow added in v0.0.4

func (c *Client) OrderItemNow(ctx context.Context, catalogItemId string, payload *OrderItemPayload) (*RequestInfo, error)

func (*Client) RemoveUserFromGroup

func (c *Client) RemoveUserFromGroup(ctx context.Context, id string) error

func (*Client) RevokeRoleFromGroup

func (c *Client) RevokeRoleFromGroup(ctx context.Context, id string) error

func (*Client) RevokeRoleFromUser

func (c *Client) RevokeRoleFromUser(ctx context.Context, id string) error

func (*Client) UpdateServiceCatalogRequestItem added in v0.0.5

func (c *Client) UpdateServiceCatalogRequestItem(ctx context.Context, requestItemId string, payload *RequestedItemUpdatePayload) (*RequestedItem, error)

type FieldOption added in v0.0.4

type FieldOption func(catalogItemRequestPayload *OrderItemPayload)

func WithCustomField added in v0.0.4

func WithCustomField(id string, value interface{}) FieldOption

type FilterVars

type FilterVars struct {
	Fields []string
	Query  string
	UserId string
}

type Group

type Group struct {
	BaseResource
	Name        string `json:"name"`
	Description string `json:"description"`
	Roles       string `json:"roles"`
}

type GroupMember

type GroupMember struct {
	BaseResource
	User  string `json:"user"`
	Group string `json:"group"`
}

type GroupMemberPayload

type GroupMemberPayload struct {
	User  string `json:"user"`
	Group string `json:"group"`
}

type GroupMembersResponse

type GroupMembersResponse = ListResponse[GroupMember]

type GroupResponse

type GroupResponse = SingleResponse[Group]

type GroupToRole

type GroupToRole struct {
	BaseResource
	Inherits string `json:"inherits"`
	Group    string `json:"group"`
	Role     string `json:"role"`
}

type GroupToRolePayload

type GroupToRolePayload struct {
	Group string `json:"group"`
	Role  string `json:"role"`
}

type GroupToRoleResponse

type GroupToRoleResponse ListResponse[GroupToRole]

type GroupsResponse

type GroupsResponse = ListResponse[Group]

type IDResponse added in v0.0.4

type IDResponse = SingleResponse[BaseResource]

type Label added in v0.0.4

type Label struct {
	Id         string `json:"sys_id,omitempty"`
	Name       string `json:"name"`
	ViewableBy string `json:"viewable_by"`
}

type LabelEntriesLabelNameResponse added in v0.0.4

type LabelEntriesLabelNameResponse = ListResponse[LabelEntryName]

type LabelEntryName added in v0.0.4

type LabelEntryName struct {
	LabelName string `json:"label.name"`
}

type LabelEntryPayload added in v0.0.4

type LabelEntryPayload struct {
	Table    string `json:"table"`
	Label    string `json:"label"`
	TableKey string `json:"table_key"`
}

type LabelResponse added in v0.0.4

type LabelResponse = SingleResponse[Label]

type LabelsResponse added in v0.0.4

type LabelsResponse = ListResponse[Label]

type ListResponse

type ListResponse[T any] struct {
	Result []T `json:"result"`
}

type OrderCatalogItemResponse added in v0.0.4

type OrderCatalogItemResponse = SingleResponse[RequestInfo]

type OrderItemPayload added in v0.0.4

type OrderItemPayload struct {
	Quantity     int                    `json:"sysparm_quantity"`
	RequestedFor string                 `json:"sysparm_requested_for"`
	Variables    map[string]interface{} `json:"variables"`
}

type PaginationVars

type PaginationVars struct {
	Limit  int
	Offset int
}

type ReqOpt added in v0.0.4

type ReqOpt func(req *http.Request)

func WithFields added in v0.0.4

func WithFields(fields ...string) ReqOpt

func WithHeader added in v0.0.4

func WithHeader(key string, val string) ReqOpt
func WithIncludeExternalRefLink() ReqOpt

func WithIncludeResponseBody added in v0.0.4

func WithIncludeResponseBody() ReqOpt

func WithOffset added in v0.0.4

func WithOffset(offset int) ReqOpt

func WithPageLimit added in v0.0.4

func WithPageLimit(pageLimit int) ReqOpt

func WithQuery added in v0.0.4

func WithQuery(query string) ReqOpt

func WithQueryParam added in v0.0.4

func WithQueryParam(key string, value string) ReqOpt

type RequestInfo added in v0.0.4

type RequestInfo struct {
	RequestNumber string `json:"request_number"`
	RequestID     string `json:"request_id"`
}

type RequestItemResponse added in v0.0.4

type RequestItemResponse = SingleResponse[RequestedItem]

type RequestItemState added in v0.0.4

type RequestItemState struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

type RequestItemsResponse added in v0.0.4

type RequestItemsResponse = ListResponse[RequestedItem]

type RequestedItem added in v0.0.4

type RequestedItem struct {
	BaseResource

	State               string `json:"state"`
	Description         string `json:"description"`
	Number              string `json:"number"`
	TaskEffectiveNumber string `json:"task_effective_number"`

	Request  ResourceRefLink `json:"request"`
	CatItem  ResourceRefLink `json:"cat_item"`
	Catalogs []Catalog       `json:"catalogs,omitempty"`
	Category Category        `json:"category,omitempty"`

	ScCatalog        string `json:"sc_catalog,omitempty"`
	SysUpdatedOn     string `json:"sys_updated_on"`
	SysUpdatedBy     string `json:"sys_updated_by"`
	ClosedAt         string `json:"closed_at"`
	SysCreatedOn     string `json:"sys_created_on"`
	SysCreatedBy     string `json:"sys_created_by"`
	Active           string `json:"active"`
	OpenedAt         string `json:"opened_at"`
	ShortDescription string `json:"short_description"`
	Approval         string `json:"approval"`
}

type RequestedItemStateResponse added in v0.0.4

type RequestedItemStateResponse = ListResponse[RequestItemState]

type RequestedItemUpdatePayload added in v0.0.5

type RequestedItemUpdatePayload struct {
	Description string `json:"description"`
}
type ResourceRefLink struct {
	Link  string `json:"link"`
	Value string `json:"value"`
}

TODO(lauren) remove unecessary fields. Service Catalog request models.

type Role

type Role struct {
	BaseResource
	Name      string `json:"name"`
	Grantable string `json:"grantable"`
}

type RolesResponse

type RolesResponse = ListResponse[Role]

type ServiceCatalogRequest added in v0.0.4

type ServiceCatalogRequest struct {
	BaseResource

	Parent string `json:"parent"`

	State               string           `json:"state"`
	RequestState        string           `json:"request_state"`
	Number              string           `json:"number"`
	TaskEffectiveNumber string           `json:"task_effective_number"`
	UponReject          string           `json:"upon_reject"`
	OpenedBy            *ResourceRefLink `json:"opened_by,omitempty"`
	RequestedFor        *ResourceRefLink `json:"requested_for,omitempty"`
	SysCreatedOn        string           `json:"sys_created_on"`
	SysUpdatedOn        string           `json:"sys_updated_on"`
	OpenedAt            string           `json:"opened_at"`
	ClosedAt            string           `json:"closed_at"`
	ApprovalSet         string           `json:"approval_set"`
	SysUpdatedBy        string           `json:"sys_updated_by"`
	SysCreatedBy        string           `json:"sys_created_by"`
	Approval            string           `json:"approval"`

	ShortDescription     string `json:"short_description"`
	Description          string `json:"description"`
	CloseNotes           string `json:"close_notes"`
	AssignedTo           string `json:"assigned_to"`
	Comments             string `json:"comments"`
	CommentsAndWorkNotes string `json:"comments_and_work_notes"`
	UponApproval         string `json:"upon_approval"`
}

type ServiceCatalogRequestResponse added in v0.0.4

type ServiceCatalogRequestResponse = SingleResponse[ServiceCatalogRequest]

type SingleResponse

type SingleResponse[T any] struct {
	Result T `json:"result"`
}

type SubCategory added in v0.0.4

type SubCategory struct {
	SysID string `json:"sys_id"`
	Title string `json:"title"`
}

type URLParams added in v0.0.4

type URLParams map[string]string

type User

type User struct {
	BaseResource
	Email     string `json:"email"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	UserName  string `json:"user_name"`
	Roles     string `json:"roles"`
}

type UserResponse

type UserResponse = SingleResponse[User]

type UserRoles

type UserRoles struct {
	UserName  string   `json:"user_name"`
	FromRole  []string `json:"from_role"`
	FromGroup []string `json:"from_group"`
}

type UserRolesResponse

type UserRolesResponse = SingleResponse[UserRoles]

type UserToRole

type UserToRole struct {
	BaseResource
	Inherited string `json:"inherited"`
	User      string `json:"user"`
	Role      string `json:"role"`
}

type UserToRolePayload

type UserToRolePayload struct {
	User string `json:"user"`
	Role string `json:"role"`
}

type UserToRoleResponse

type UserToRoleResponse ListResponse[UserToRole]

type UsersResponse

type UsersResponse = ListResponse[User]

type VariableType added in v0.0.4

type VariableType int
const (
	TypeUnspecified VariableType = iota
	TypeYesNo
	TypeMultiLineText
	TypeMultipleChoice
	TypeNumericScale // TODO(lauren) add baton custom field type for number
	TypeSelectBox
	TypeSingleLineText
	TypeCheckBox
	TypeReference
	TypeDate
	TypeDateTime
	TypeLabel
	TypeBreak

	TypeMacro  // skip
	TypeUIPage // skip
	TypeWideSingleLineText
	TypeMacroWithLabel // skip
	TypeLookupSelectBox
	TypeContainerStart
	TypeContainerEnd
	TypeListCollector
	TypeLookupMultipleChoice
	TypeHTML
	TypeSplit
	TypeMasked
	TypeEmail
	TypeURL
	TypeIPAddress
	TypeDuration

	TypeRequestedFor
	TypeRichTextLabel
	TypeAttachment
)

TODO(lauren) not sure how to handle all of these These correspond to variable type id.

type VariableTypeNew added in v0.0.4

type VariableTypeNew interface{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL