Categorygithub.com/badarsebard/xsoar-sdk-go/openapi
package
0.2.30
Repository: https://github.com/badarsebard/xsoar-sdk-go.git
Documentation: pkg.go.dev

# README

Go API client for openapi

This is the public REST API to integrate with the Cortex XSOAR server. HTTP request can be sent using any HTTP-client.

For an example dedicated client take a look at: https://github.com/demisto/demisto-py.

Requests must include API-key that can be generated in the Cortex XSOAR web client under 'Settings' -> 'Integrations' -> 'API keys'

Optimistic Locking and Versioning\:

When using Cortex XSOAR REST API, you will need to make sure to work on the latest version of the item (incident, entry, etc.), otherwise, you will get a DB version error (which not allow you to override a newer item). In addition, you can pass 'version\: -1' to force data override (make sure that other users data might be lost).

Assume that Alice and Bob both read the same data from Cortex XSOAR server, then they both changed the data, and then both tried to write the new versions back to the server. Whose changes should be saved? Alice’s? Bob’s? To solve this, each data item in Cortex XSOAR has a numeric incremental version. If Alice saved an item with version 4 and Bob trying to save the same item with version 3, Cortex XSOAR will rollback Bob request and returns a DB version conflict error. Bob will need to get the latest item and work on it so Alice work will not get lost.

Example request using 'curl'\:

curl 'https://hostname:443/incidents/search' -H 'content-type: application/json' -H 'accept: application/json' -H 'Authorization: <API Key goes here>' --data-binary '{\"filter\":{\"query\":\"-status:closed -category:job\",\"period\":{\"by\":\"day\",\"fromValue\":7}}}' --compressed

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 2.0.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import sw "./openapi"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value sw.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), sw.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value sw.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), sw.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identifield by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using sw.ContextOperationServerIndices and sw.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), sw.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), sw.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to https://hostname:443

ClassMethodHTTP requestDescription
DefaultApiAddAdHocTaskPost /inv-playbook/task/add/{investigationId}Add ad-hoc task
DefaultApiCloseIncidentsBatchPost /incident/batchCloseBatch close incidents
DefaultApiCompleteTaskPost /inv-playbook/task/complete[Deprecated] Complete a task
DefaultApiCompleteTaskV2Post /v2/inv-playbook/task/completeComplete a task
DefaultApiCopyScriptPost /automation/copyCopy automation
DefaultApiCreateAccountPost /accountCreate an account
DefaultApiCreateDockerImagePost /settings/docker-imagesCreate Image
DefaultApiCreateFeedIndicatorsJsonPost /indicators/feed/jsonCreate feed indicators from JSON
DefaultApiCreateHAGroupPost /ha-group/create
DefaultApiCreateHAInstallerPost /host/build/{id}
DefaultApiCreateHostInstallerPost /host/build
DefaultApiCreateIncidentPost /incidentCreate single incident
DefaultApiCreateIncidentJsonPost /incident/jsonCreate incident from JSON
DefaultApiCreateIncidentsBatchPost /incident/batchBatch create incidents
DefaultApiCreateOrUpdateIncidentTypePost /incidenttypeCreate new Incident Type
DefaultApiCreateOrUpdateWhitelistedPost /indicators/whitelist/updateCreate whitelisted
DefaultApiCreateUpdateClassifierPost /classifierCreate or update a classifier
DefaultApiCreateUpdateClassifierAccountPost /{acc}/classifierCreate or update a classifier
DefaultApiCreateUpdateIntegrationInstancePut /settings/integrationCreate/update an integration instance
DefaultApiCreateUpdateIntegrationInstanceAccountPut /{acc}/settings/integrationCreate/update an integration instance
DefaultApiDeleteAccountDelete /account/purge/{accountname}
DefaultApiDeleteAdHocTaskPost /inv-playbook/task/delete/{investigationId}/{invPBTaskId}Delete ad-hoc task
DefaultApiDeleteAutomationScriptPost /automation/deleteDelete existing automation
DefaultApiDeleteClassifierDelete /classifier/{id}Delete a classifier
DefaultApiDeleteClassifierAccountDelete /{acc}/classifier/{id}Delete a classifier for account
DefaultApiDeleteEvidenceOpPost /evidence/deletedelete evidence
DefaultApiDeleteHAGroupDelete /ha-group/{id}
DefaultApiDeleteHostDelete /host/{id}
DefaultApiDeleteIncidentsBatchPost /incident/batchDeleteBatch delete incidents
DefaultApiDeleteIndicatorsBatchPost /indicators/batchDeleteBatch whitelist or delete indicators
DefaultApiDeleteIntegrationInstanceDelete /settings/integration/{id}Delete integration instance
DefaultApiDeleteIntegrationInstanceAccountDelete /{acc}/settings/integration/{id}Delete integration instance
DefaultApiDeleteWidgetDelete /widgets/{id}Remove existing widget
DefaultApiDownloadFileGet /entry/download/{entryid}Download file
DefaultApiDownloadLatestReportGet /report/{id}/latestGet latest report by ID
DefaultApiEditAdHocTaskPost /inv-playbook/task/edit/{investigationId}Edit ad-hoc task
DefaultApiEntryExportArtifactPost /entry/exportArtifactExport Artifact
DefaultApiExecuteReportPost /report/{id}/{requestId}/executeExecute report
DefaultApiExportIncidentsToCsvBatchPost /incident/batch/exportToCsvBatch export incidents to csv
DefaultApiExportIndicatorsToCsvBatchPost /indicators/batch/exportToCsvBatch export indicators to csv
DefaultApiExportIndicatorsToStixBatchPost /indicators/batch/export/stixBatch export indicators to STIX
DefaultApiGetAllReportsGet /reportsGet all reports
DefaultApiGetAllWidgetsGet /widgets
DefaultApiGetAuditsPost /settings/auditsGet Audits
DefaultApiGetAutomationScriptsPost /automation/searchSearch Automation (aka scripts)
DefaultApiGetContainersGet /health/containersGet health containers
DefaultApiGetDockerImagesGet /settings/docker-imagesGet Docker Images
DefaultApiGetHAGroupGet /ha-group/{id}
DefaultApiGetHAInstallerGet /host/download/{id}
DefaultApiGetHostInstallerGet /host/download
DefaultApiGetIncidentAsCsvGet /incident/csv/{id}Get incident as CSV
DefaultApiGetIncidentsFieldsByIncidentTypeGet /incidentfields/associatedTypes/{type}Get all incident fields associated with incident type
DefaultApiGetIndicatorsAsCsvGet /indicators/csv/{id}Get indicators as CSV
DefaultApiGetIndicatorsAsSTIXGet /indicators/stix/v2/{id}Get indicators as STIX V2
DefaultApiGetReportByIDGet /reports/{id}Get report by ID
DefaultApiGetStatsForDashboardPost /v2/statistics/dashboards/queryGet Dashboard Statistics
DefaultApiGetStatsForDashboardOldFormatPost /statistics/dashboards/query[Deprecated] Get Dashboard Statistics
DefaultApiGetStatsForWidgetPost /v2/statistics/widgets/queryGet Widget Statistics
DefaultApiGetStatsForWidgetOldFormatPost /statistics/widgets/query[Deprecated] Get Widget Statistics
DefaultApiGetWidgetGet /widgets/{id}Get widget by ID
DefaultApiHealthHandlerGet /healthCheck if Cortex XSOAR server is available
DefaultApiImportClassifierPost /classifier/importImport a classifier
DefaultApiImportDashboardPost /dashboards/importImport a dashboard
DefaultApiImportIncidentFieldsPost /incidentfields/importImport an incident field
DefaultApiImportIncidentTypesHandlerPost /incidenttypes/importImport an incident type
DefaultApiImportScriptPost /automation/importImport an automation
DefaultApiImportWidgetPost /widgets/importImport a widget
DefaultApiIncidentFileUploadPost /incident/upload/{id}
DefaultApiIndicatorWhitelistPost /indicator/whitelistWhitelists or deletes Indicator
DefaultApiIndicatorsCreatePost /indicator/createCreate Indicator
DefaultApiIndicatorsCreateBatchPost /indicators/uploadCreate indicators
DefaultApiIndicatorsEditPost /indicator/editEdit Indicator
DefaultApiIndicatorsSearchPost /indicators/searchSearch indicators
DefaultApiIndicatorsTimelineDeletePost /indicators/timeline/deleteDelete indicators timeline
DefaultApiIntegrationUploadPost /settings/integration-conf/uploadUpload an integration
DefaultApiInvestigationAddEntriesSyncPost /entry/execute/syncCreate new entry in existing investigation
DefaultApiInvestigationAddEntryHandlerPost /entryCreate new entry in existing investigation
DefaultApiInvestigationAddFormattedEntryHandlerPost /entry/formattedCreate new formatted entry in existing investigation
DefaultApiListAccountsGet /accountsList accounts
DefaultApiListAccountsDetailsGet /accounts/dataDetailed accounts
DefaultApiListClassifiersPost /classifier/searchsearch classifiers
DefaultApiListClassifiersAccountPost /{acc}/classifier/searchsearch classifiers
DefaultApiListHAGroupsGet /ha-groups
DefaultApiListHostsGet /hosts
DefaultApiListIntegrationsPost /settings/integration/searchList integrations
DefaultApiListIntegrationsAccountPost /{acc}/settings/integration/searchList integrations
DefaultApiListMainHostsGet /health/appserversList the main hosts
DefaultApiLogoutEveryoneHandlerPost /logout/everyoneSign out all open users sessions
DefaultApiLogoutMyselfHandlerPost /logout/myselfSign out all my open sessions
DefaultApiLogoutMyselfOtherSessionsHandlerPost /logout/myself/otherSign out all my other open sessions
DefaultApiLogoutUserSessionsHandlerPost /logout/user/{username}Sign out all sessions of the provided username
DefaultApiOverridePlaybookYamlPost /playbook/save/yamlImport and override playbook
DefaultApiResetROIWidgetDelete /statistics/application/roiReset ROI widget
DefaultApiRevokeUserAPIKeyPost /apikeys/revoke/user/{username}
DefaultApiSaveEvidencePost /evidenceSave evidence
DefaultApiSaveOrUpdateScriptPost /automationCreate or update automation
DefaultApiSaveWidgetPost /widgetsAdd or update a widget
DefaultApiSearchEvidencePost /evidence/searchSearch evidence
DefaultApiSearchIncidentsPost /incidents/searchSearch incidents by filter
DefaultApiSearchInvestigationsPost /investigations/searchSearch investigations by filter
DefaultApiSetTagsFieldPost /incidentfield/tags/reset/{id}Set tags field
DefaultApiSimpleCompleteTaskPost /inv-playbook/task/complete/simpleComplete task simple (no file)
DefaultApiStartAccountsPost /accounts/startStart accounts
DefaultApiStopAccountsPost /accounts/stopStop accounts
DefaultApiSubmitTaskFormPost /v2/inv-playbook/task/form/submitComplete a task
DefaultApiTaskAddCommentPost /inv-playbook/task/note/addTask add comment
DefaultApiTaskAssignPost /inv-playbook/task/assignAssign task
DefaultApiTaskSetDuePost /inv-playbook/task/dueSet task due date
DefaultApiTaskUnCompletePost /inv-playbook/task/uncompleteUn complete a task
DefaultApiUpdateAccountPost /account/update/{accountname}
DefaultApiUpdateAccountHostPost /host/move/{accountname}/{hostgroupid}
DefaultApiUpdateEntryNotePost /entry/noteMark entry as note
DefaultApiUpdateEntryTagsOpPost /entry/tagsSet entry tags
DefaultApiWorkersStatusHandlerGet /workers/statusGet workers status

Documentation For Models

Documentation For Authorization

api_key

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Note, each API key must be added to a map of map[string]APIKey where the key is: Authorization and passed in as the auth context for each request.

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author