Skip to main content
Solved

How to use AssystRest to insert a batch of events?


lucascaetano
Do Gooder
Forum|alt.badge.img

How to use AssystRest to insert a batch of events?

Best answer by Alan Macfarlane

Hi

There’s no distinct API for a batch of events, each event would need its own request*. An example to do this might look like:

 

Content-Type: application/json

POST https://{server}:{port}/assystRest/v2/events

BODY
{

   “eventType”: 1,

   “affectedUserName”: “Bob User”,

   “affectedUserEmail”: “bob@company.com”

   // etc.

 

There are some examples here.

 

(*there is a feature called “Object Graph” in REST  which allows the submission of multiple objects via one request however there is no support for it with the /events resource yet - if its is of use to you I would suggest registering the request via our Ideas forum)   

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+6

Hi

There’s no distinct API for a batch of events, each event would need its own request*. An example to do this might look like:

 

Content-Type: application/json

POST https://{server}:{port}/assystRest/v2/events

BODY
{

   “eventType”: 1,

   “affectedUserName”: “Bob User”,

   “affectedUserEmail”: “bob@company.com”

   // etc.

 

There are some examples here.

 

(*there is a feature called “Object Graph” in REST  which allows the submission of multiple objects via one request however there is no support for it with the /events resource yet - if its is of use to you I would suggest registering the request via our Ideas forum)   


Forum|alt.badge.img+12
  • Hero (Customer)
  • 141 replies
  • March 30, 2023

We have use API to generate tasks in a couple of processes. I have adapted my code to include a foreach element that cycles through events in an object. You might event be able to populate the object array from a .csv or .xlsx file using Get-Content. It might do what you want it to...

Function Set-JsonBody($eventType,$description,$importProfile,$affectedUser,$itemA,$category){
    $myJsonConstruct = @"
{
    "eventTypeEnum": "$eventType",
        "remarks": "$description",
        "importProfileId": $importProfile,
        "affectedUser": {
            "resolvingParameters": [
                {
                    "parameterName": "shortCode",
                    "parameterValue": "$affectedUser"
                },
                {
                    "parameterName": "CSGId",
                    "parameterValue": "0"
                }
            ]
        },
        "itemA": {
            "resolvingParameters": [
                {
                    "parameterName": "shortCode",
                    "parameterValue": "$itemA"
                }
            ]
        },
        "category": {
            "resolvingParameters": [
                {
                    "parameterName": "shortCode",
                    "parameterValue": "$category"
                }
            ]
        }
    }
"@
    return $myJsonConstruct
}

$username = ""
$pass = ""
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$Uri = "https://{server}:{port}/assystRest/v2/events"

$eventArr = @(
    @{
        eventType = "INCIDENT"
        description = "This is the first event"
        importProfile = 12
        affectedUser = "BOB@COMPANY.COM"
        itemA = "EXAMPLE_ITEM"
        category = "EXAMPLE_CATEGORY"
    }
    @{
        eventType = "INCIDENT"
        description = "This is the NEXT event"
        importProfile = 12
        affectedUser = "ROB@COMPANY.COM"
        itemA = "EXAMPLE_ITEM"
        category = "EXAMPLE_CATEGORY"
    }
)

foreach($event in $eventArr){
    $Body = Set-JsonBody -eventType $event.eventType `
        -description $event.description `
        -importProfile $event.importProfile `
        -affectedUser $event.affectedUser `
        -itemA $event.itemA `
        -category $event.category

    $Params = @{ 
        "URI" = 	$Uri
        "Method" = 	'POST'
        "Credential" = $Credential
        "ContentType" = 'application/json'
        "Body" = $myJsonConstruct
    }

    Invoke-RestMethod @Params -UseBasicParsing ##Required for running from the Action Processor unsupervised. You might not need it the basic parsing parameter.
}

 

Alternatively, you could use the assystETM to import batches of events from a spreadsheet. We did this when migrating tickets from another system.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings