tableapi

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 9 Imported by: 0

README

Table API

The Table API provides endpoints that allow you to perform create, read, update, and delete (CRUD) operations on existing tables.

[DELETE] /now/table/{tableName}/{sys_id}

Deletes the specified record from the specified table.

package main

import (
    tableapi "github.com/michaeldcanady/servicenow-sdk-go/table-api"
)

func main() {
    
    //Implement credential and client.
    pathParameters := {
        "baseurl":"https://www.{instance}.service-now.com/api/now",
        "table": "incident",
        "sysId": "INC00000000",
    }

    // Instantiate new TableItemRequestBuilder.
    requestBuilder := tableapi.NewTableItemRequestBuilder(client, pathParameters)

    // Call the delete method, with or without TableItemRequestBuilderDeleteQueryParameters.
    err := requestBuilder.Delete(nil)

    // Since there is no record, the delete method only returns an error.
    if err != nil {
        panic(err)
    }
}

[GET] /now/table/{tableName}

Retrieves multiple records for the specified table.

package main

import (
    tableapi "github.com/michaeldcanady/servicenow-sdk-go/table-api"
)

func main() {
    
    //Implement credential and client.
    pathParameters := {
        "baseurl":"https://www.{instance}.service-now.com/api/now",
        "table": "incident",
    }

    // Instantiate new TableItemRequestBuilder.
    requestBuilder := tableapi.NewTableRequestBuilder(client, pathParameters)

    // Call the get method, with or without TableRequestBuilderGetQueryParameters.
    // Response is a TableCollectionResponse.
    response, err := requestBuilder.Get(nil)

    // Test err, should be nil
    if err != nil {
        panic(err)
    }
}

[GET] /now/table/{tableName}/{sys_id}

Retrieves the record identified by the specified sys_id from the specified table.

package main

import (
    tableapi "github.com/michaeldcanady/servicenow-sdk-go/table-api"
)

func main() {
    
    //Implement credential and client.
    pathParameters := {
        "baseurl":"https://www.{instance}.service-now.com/api/now",
        "table": "incident",
        "sysId": "INC00000000",
    }

    // Instantiate new TableItemRequestBuilder.
    requestBuilder := tableapi.NewTableItemRequestBuilder(client, pathParameters)

    // Call the get method, with or without TableItemRequestBuilderGetQueryParameters.
    // record is of type TableItemResponse
    record, err := requestBuilder.Get(nil)

    // evaluate err, should be nil
    if err != nil {
        panic(err)
    }
}

[POST] /now/table/{tableName}

Inserts one record in the specified table. Multiple record insertion is not supported by this method.

package main

import (
    tableapi "github.com/michaeldcanady/servicenow-sdk-go/table-api"
)

func main() {
    
    //Implement credential and client.
    pathParameters := {
        "baseurl":"https://www.{instance}.service-now.com/api/now",
        "table": "incident",
    }

    // data map of information you want to use for the new record
    data := map[string]string{
        "short_description": "example incident",
        "description": "incident created by servicenow-sdk-go",
    }

    // Instantiate new TableItemRequestBuilder.
    requestBuilder := tableapi.NewTableRequestBuilder(client, pathParameters)

    // Call the get method, with or without TableRequestBuilderPostQueryParamters.
    // Make sure you include the data paramter
    // Response is a TableItemResponse.
    response, err := requestBuilder.Post(data, nil)

    // Test err, should be nil
    if err != nil {
        panic(err)
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNilClient         = errors.New("client can't be nil")
	ErrNilResponse       = errors.New("response can't be nil")
	ErrNilResult         = errors.New("result property missing in response object")
	ErrWrongResponseType = errors.New("incorrect Response Type")
)

Functions

This section is empty.

Types

type DisplayValue

type DisplayValue string
const (
	TRUE  DisplayValue = "true"
	FALSE DisplayValue = "false"
	ALL   DisplayValue = "all"
)

type Fragment added in v1.1.0

type Fragment struct {
	// Field represents the field on which the condition is applied.
	Field string
	// RelationalOperator represents the comparison operator for the condition.
	RelationalOperator RelationalOperator
	// Value represents the value to compare against.
	Value interface{}
	// LogicalOperator represents the operator connection to the next fragment
	LogicalOperator LogicalOperator
	// contains filtered or unexported fields
}

Fragment represents a query fragment with a field, operator, and value.

func NewFragment added in v1.1.0

func NewFragment(field string, operator RelationalOperator, value interface{}) *Fragment

NewFragment creates a new query fragment with the specified field, operator, and value.

func (*Fragment) Iterate added in v1.1.0

func (f *Fragment) Iterate(callback func(*Fragment) bool)

func (*Fragment) SetNext added in v1.1.0

func (f *Fragment) SetNext(fragment *Fragment, operator LogicalOperator)

SetNext sets the next and Logical Operator value

func (*Fragment) String added in v1.1.0

func (f *Fragment) String() string

String returns a string representation of the query fragment in the format "field operator value".

type LogicalOperator added in v1.1.0

type LogicalOperator string
const (
	And LogicalOperator = "^"
	Or  LogicalOperator = "^OR"
)

type OrderBy added in v1.1.0

type OrderBy struct {
	Direction OrderDirection
	Field     string
}

OrderBy represents an order-by clause.

func NewOrderBy added in v1.1.0

func NewOrderBy() *OrderBy

func (*OrderBy) String added in v1.1.0

func (oB *OrderBy) String() string

type OrderDirection added in v1.1.0

type OrderDirection string

OrderDirection represents the order direction for sorting.

const (
	Unset OrderDirection = ""
	Asc   OrderDirection = "^ORDERBY"
	Desc  OrderDirection = "^ORDERBYDESC"
)

type PageIterator

type PageIterator struct {
	// contains filtered or unexported fields
}

PageIterator represents an iterator for paginated results from a table.

func NewPageIterator

func NewPageIterator(currentPage interface{}, client core.Client) (*PageIterator, error)

NewPageIterator creates a new PageIterator instance.

func (*PageIterator) Iterate

func (p *PageIterator) Iterate(callback func(pageItem *TableEntry) bool) error

Iterate iterates through pages and invokes the provided callback for each page item.

type PageResult

type PageResult struct {
	Result           []*TableEntry
	NextPageLink     string
	PreviousPageLink string
	FirstPageLink    string
	LastPageLink     string
}

PageResult represents a single page of results from a table.

type Query added in v1.1.0

type Query struct {
	// contains filtered or unexported fields
}

Query represents a ServiceNow query and its conditions.

func NewQuery added in v1.1.0

func NewQuery() *Query

NewQuery returns a new Query with no conditions.

func (*Query) AddBetween added in v1.1.0

func (q *Query) AddBetween(field string, start, end interface{}) *Query

AddBetween adds a between condition to the query.

func (*Query) AddContains added in v1.1.0

func (q *Query) AddContains(field string, value interface{}) *Query

AddContains adds a contains condition to the query.

func (*Query) AddEndsWith added in v1.1.0

func (q *Query) AddEndsWith(field string, value interface{}) *Query

AddEndsWith adds an ends-with condition to the query.

func (*Query) AddEqual added in v1.1.0

func (q *Query) AddEqual(field string, value interface{}) *Query

AddEqual adds an equality condition to the query.

func (*Query) AddFragment added in v1.1.0

func (q *Query) AddFragment(fragment *Fragment, operator LogicalOperator) *Query

func (*Query) AddGreaterThan added in v1.1.0

func (q *Query) AddGreaterThan(field string, value interface{}) *Query

AddGreaterThan adds a greater-than condition to the query.

func (*Query) AddIsDifferent added in v1.1.0

func (q *Query) AddIsDifferent(startField, endField string) *Query

AddIsDifferent adds a condition to check if two fields are different.

func (*Query) AddIsSame added in v1.1.0

func (q *Query) AddIsSame(startField, endField string) *Query

AddIsSame adds a condition to check if two fields are the same.

func (*Query) AddLessThan added in v1.1.0

func (q *Query) AddLessThan(field string, value interface{}) *Query

AddLessThan adds a less-than condition to the query.

func (*Query) AddNotContains added in v1.1.0

func (q *Query) AddNotContains(field string, value interface{}) *Query

AddNotContains adds a not-contains condition to the query.

func (*Query) AddNotEqual added in v1.1.0

func (q *Query) AddNotEqual(field string, value interface{}) *Query

AddNotEqual adds a not-equal condition to the query.

func (*Query) AddOrContains added in v1.1.0

func (q *Query) AddOrContains(field string, value interface{}) *Query

AddOrContains adds an "OR" contains condition to the query.

func (*Query) AddOrEqual added in v1.1.0

func (q *Query) AddOrEqual(field string, value interface{}) *Query

AddOrEqual adds an "OR" equality condition to the query.

func (*Query) AddOrGreaterThan added in v1.1.0

func (q *Query) AddOrGreaterThan(field string, value interface{}) *Query

AddOrGreaterThan adds an "OR" greater-than condition to the query.

func (*Query) AddOrLessThan added in v1.1.0

func (q *Query) AddOrLessThan(field string, value interface{}) *Query

AddOrLessThan adds an "OR" less-than condition to the query.

func (*Query) AddOrNotContains added in v1.1.0

func (q *Query) AddOrNotContains(field string, value interface{}) *Query

AddOrNotContains adds an "OR" not-contains condition to the query.

func (*Query) AddOrNotEqual added in v1.1.0

func (q *Query) AddOrNotEqual(field string, value interface{}) *Query

AddOrNotEqual adds an "OR" not-equal condition to the query.

func (*Query) AddOrQuery added in v1.1.0

func (q *Query) AddOrQuery(field string, operator RelationalOperator, value interface{}) *Query

AddOrQuery adds an "OR" query condition to the query.

func (*Query) AddOrderBy added in v1.1.0

func (q *Query) AddOrderBy(field string) *Query

AddOrderBy sets the order-by field in ascending order.

func (*Query) AddOrderByDesc added in v1.1.0

func (q *Query) AddOrderByDesc(field string) *Query

AddOrderByDesc sets the order-by field in descending order.

func (*Query) AddQuery added in v1.1.0

func (q *Query) AddQuery(field string, operator RelationalOperator, value interface{}) *Query

AddQuery adds a query condition to the query.

func (*Query) AddStartsWith added in v1.1.0

func (q *Query) AddStartsWith(field string, value interface{}) *Query

AddStartsWith adds a starts-with condition to the query.

func (*Query) Encoded added in v1.1.0

func (q *Query) Encoded() string

Encoded returns the encoded query as a string.

func (*Query) IsEmpty added in v1.1.0

func (q *Query) IsEmpty(field string) *Query

IsEmpty adds an "is empty" condition to the query.

func (*Query) String added in v1.1.0

func (q *Query) String() string

String returns the query as a string.

type RelationalOperator added in v1.1.0

type RelationalOperator string
const (
	Null           RelationalOperator = ""
	Is             RelationalOperator = "="
	IsNot          RelationalOperator = "!="
	GreaterThan    RelationalOperator = ">"
	GreaterOrEqual RelationalOperator = ">="
	LessThan       RelationalOperator = "<"
	LessOrEqual    RelationalOperator = "<="
	Contains       RelationalOperator = "CONTAINS"
	NotContains    RelationalOperator = "!CONTAINS"
	StartsWith     RelationalOperator = "STARTSWITH"
	EndsWith       RelationalOperator = "ENDSWITH"
	Between        RelationalOperator = "BETWEEN"
	IsSame         RelationalOperator = "SAMEAS"
	IsDifferent    RelationalOperator = "NSAMEAS"
	IsEmpty        RelationalOperator = "ISEMPTY"
)

type TableCollectionResponse

type TableCollectionResponse struct {
	Result           []*TableEntry
	NextPageLink     string
	PreviousPageLink string
	FirstPageLink    string
	LastPageLink     string
}

func (*TableCollectionResponse) ParseHeaders added in v1.1.0

func (cR *TableCollectionResponse) ParseHeaders(headers http.Header)

type TableEntry

type TableEntry map[string]interface{}

func (TableEntry) Value

func (tE TableEntry) Value(key string) *TableValue

type TableItemRequestBuilder

type TableItemRequestBuilder struct {
	core.RequestBuilder
}

func NewTableItemRequestBuilder

func NewTableItemRequestBuilder(client core.Client, pathParameters map[string]string) *TableItemRequestBuilder

NewTableItemRequestBuilder creates a new instance of the TableItemRequestBuilder associated with the given URL and Client. It accepts the URL and Client as parameters and returns a pointer to the created TableItemRequestBuilder.

func (*TableItemRequestBuilder) Delete

Delete sends an HTTP DELETE request using the specified query parameters and returns an error if the request or response encounters any issues.

Parameters:

  • params: An instance of TableItemRequestBuilderDeleteQueryParameters to include in the DELETE request.

Returns:

  • error: An error if there was an issue with the request or response, or nil if the request was successful.

func (*TableItemRequestBuilder) Get

Get sends an HTTP GET request using the specified query parameters and returns a TableItemResponse.

Parameters:

  • params: An instance of TableItemRequestBuilderGetQueryParameters to include in the GET request.

Returns:

  • *TableItemResponse: The response data as a TableItemResponse.
  • error: An error if there was an issue with the request or response.

func (*TableItemRequestBuilder) Put

Put updates a table item using an HTTP PUT request. It takes a map of table entry data and optional query parameters to send in the request. The method returns a TableItemResponse representing the updated item or an error if the request fails.

Parameters:

  • tableEntry: A map containing the data to update the table item.
  • params: An optional pointer to TableItemRequestBuilderPutQueryParameters, which can be used to specify query parameters for the request.

Returns:

  • *TableItemResponse: A TableItemResponse containing the updated item data.
  • error: An error, if the request fails at any point, such as request information creation or JSON deserialization.

type TableItemRequestBuilderDeleteQueryParameters

type TableItemRequestBuilderDeleteQueryParameters struct {
	//Flag that indicates whether to restrict the record search to only the domains for which the logged in user is configured.
	//
	//Valid values:
	//
	//- false: Exclude the record if it is in a domain that the currently logged in user is not configured to access.
	//
	//- true: Include the record even if it is in a domain that the currently logged in user is not configured to access.
	QueryNoDomain bool `query:"sysparm_query_no_domain"`
}

type TableItemRequestBuilderGetQueryParameters

type TableItemRequestBuilderGetQueryParameters struct {
	//Determines the type of data returned, either the actual values from the database or the display values of the fields.
	//Display values are manipulated based on the actual value in the database and user or system settings and preferences.
	//If returning display values, the value that is returned is dependent on the field type.
	//- Choice fields: The database value may be a number, but the display value will be more descriptive.
	//
	//- Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
	//
	//- Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
	//
	//- Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
	DisplayValue DisplayValue `query:"sysparm_display_value"`
	//Flag that indicates whether to exclude Table API links for reference fields.
	//
	//Valid values:
	//
	//- true: Exclude Table API links for reference fields.
	//
	//- false: Include Table API links for reference fields.
	ExcludeReferenceLink bool `query:"sysparm_exclude_reference_link"`
	//list of fields to return in the response.
	Fields []string `query:"sysparm_fields"`
	//Flag that indicates whether to restrict the record search to only the domains for which the logged in user is configured.
	//
	//Valid values:
	//
	//- false: Exclude the record if it is in a domain that the currently logged in user is not configured to access.
	//
	//- true: Include the record even if it is in a domain that the currently logged in user is not configured to access.
	QueryNoDomain bool `query:"sysparm_query_no_domain"`
	//	UI view for which to render the data. Determines the fields returned in the response.
	//
	//Valid values:
	//
	//- desktop
	//- mobile
	//- both
	//If you also specify the sysparm_fields parameter, it takes precedent.
	View View `query:"sysparm_view"`
}

type TableItemRequestBuilderPutQueryParameters

type TableItemRequestBuilderPutQueryParameters struct {
	DisplayValue         DisplayValue `query:"sysparm_display_value"`
	ExcludeReferenceLink bool         `query:"sysparm_exclude_reference_link"`
	Fields               []string     `query:"sysparm_fields"`
	InputDisplayValue    bool         `query:"sysparm_input_display_value"`
	QueryNoDomain        bool         `query:"sysparm_query_no_domain"`
	View                 View         `query:"sysparm_view"`
}

type TableItemResponse

type TableItemResponse struct {
	Result *TableEntry
}

func (*TableItemResponse) ParseHeaders added in v1.1.0

func (iR *TableItemResponse) ParseHeaders(headers http.Header)

type TableRequestBuilder

type TableRequestBuilder struct {
	core.RequestBuilder
}

func NewTableRequestBuilder

func NewTableRequestBuilder(client core.Client, pathParameters map[string]string) *TableRequestBuilder

NewTableRequestBuilder creates a new instance of the TableRequestBuilder associated with the given URL and Client. It accepts the URL and Client as parameters and returns a pointer to the created TableRequestBuilder.

func (*TableRequestBuilder) ById

ById returns a TableItemRequestBuilder for a specific record in the table. It accepts the sysId of the record as a parameter and constructs the URL for the record. The returned TableItemRequestBuilder can be used to build and execute requests for the specific record.

func (*TableRequestBuilder) Count

func (T *TableRequestBuilder) Count() (int, error)

Count sends an HTTP HEAD request and retrieves the value of "X-Total-Count" from the response header, which represents the count of items.

Returns:

  • int: The count of items.
  • error: An error if there was an issue with the request or response.

func (*TableRequestBuilder) Get

Get sends an HTTP GET request using the specified query parameters and returns a TableCollectionResponse.

Parameters:

  • params: An instance of TableRequestBuilderGetQueryParameters to include in the GET request.

Returns:

  • *TableCollectionResponse: The response data as a TableCollectionResponse.
  • error: An error if there was an issue with the request or response.

func (*TableRequestBuilder) Post

Post sends an HTTP Post request with the provided data and query parameters and returns a TableResponse.

Parameters:

  • data: A map[string]string representing data to be included in the request body.
  • params: An instance of TableRequestBuilderPostQueryParamters for query parameters.

Returns:

  • *TableResponse: The response data as a TableResponse.
  • error: An error if there was an issue with the request or response.

type TableRequestBuilderGetQueryParameters

type TableRequestBuilderGetQueryParameters struct {
	//Determines the type of data returned, either the actual values from the database or the display values of the fields.
	//Display values are manipulated based on the actual value in the database and user or system settings and preferences.
	//If returning display values, the value that is returned is dependent on the field type.
	//- Choice fields: The database value may be a number, but the display value will be more descriptive.
	//
	//- Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
	//
	//- Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
	//
	//- Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
	DisplayValue DisplayValue `query:"sysparm_display_value"`
	//Flag that indicates whether to exclude Table API links for reference fields.
	//
	//Valid values:
	//
	//- true: Exclude Table API links for reference fields.
	//
	//- false: Include Table API links for reference fields.
	ExcludeReferenceLink bool `query:"sysparm_exclude_reference_link"`
	//list of fields to return in the response.
	Fields []string `query:"sysparm_fields"`
	//Flag that indicates whether to restrict the record search to only the domains for which the logged in user is configured.
	//
	//Valid values:
	//
	//- false: Exclude the record if it is in a domain that the currently logged in user is not configured to access.
	//
	//- true: Include the record even if it is in a domain that the currently logged in user is not configured to access.
	QueryNoDomain bool `query:"sysparm_query_no_domain"`
	//	UI view for which to render the data. Determines the fields returned in the response.
	//
	//Valid values:
	//
	//- desktop
	//- mobile
	//- both
	//If you also specify the sysparm_fields parameter, it takes precedent.
	View                     View   `query:"sysparm_view"`
	Limit                    int    `query:"sysparm_limit"`
	NoCount                  bool   `query:"sysparm_no_count"`
	Offset                   int    `query:"sysparm_offset"`
	Query                    string `query:"sysparm_query"`
	QueryCategory            string `query:"sysparm_query_category"`
	SuppressPaginationHeader bool   `uriparameter:"sysparm_suppress_pagination_header"`
}

type TableRequestBuilderPostQueryParamters

type TableRequestBuilderPostQueryParamters struct {
	//Determines the type of data returned, either the actual values from the database or the display values of the fields.
	//Display values are manipulated based on the actual value in the database and user or system settings and preferences.
	//If returning display values, the value that is returned is dependent on the field type.
	//- Choice fields: The database value may be a number, but the display value will be more descriptive.
	//
	//- Date fields: The database value is in UTC format, while the display value is based on the user's time zone.
	//
	//- Encrypted text: The database value is encrypted, while the displayed value is unencrypted based on the user's encryption context.
	//
	//- Reference fields: The database value is sys_id, but the display value is a display field of the referenced record.
	DisplayValue DisplayValue `query:"sysparm_display_value"`
	//Flag that indicates whether to exclude Table API links for reference fields.
	//
	//Valid values:
	//
	//- true: Exclude Table API links for reference fields.
	//
	//- false: Include Table API links for reference fields.
	ExcludeReferenceLink bool `query:"sysparm_exclude_reference_link"`
	//list of fields to return in the response.
	Fields            []string `query:"sysparm_fields"`
	InputDisplayValue bool     `query:"sysparm_input_display_value"`
	//	UI view for which to render the data. Determines the fields returned in the response.
	//
	//Valid values:
	//
	//- desktop
	//- mobile
	//- both
	//If you also specify the sysparm_fields parameter, it takes precedent.
	View View `query:"sysparm_view"`
}

type TableResponse

type TableResponse struct {
	Result TableEntry
}

type TableValue

type TableValue struct {
	// contains filtered or unexported fields
}

func (*TableValue) GetType

func (tV *TableValue) GetType() reflect.Type

func (*TableValue) ToBool

func (tV *TableValue) ToBool() (bool, error)

func (*TableValue) ToFloat64

func (tV *TableValue) ToFloat64() (float64, error)

func (*TableValue) ToInt64

func (tV *TableValue) ToInt64() (int64, error)

func (*TableValue) ToString

func (tV *TableValue) ToString() (string, error)

type View

type View string
const (
	DESKTOP View = "desktop"
	MOBILE  View = "mobile"
	BOTH    View = "both"
)

Jump to

Keyboard shortcuts

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