Jump to content

Auto logging requests with API


Dan Munns

Recommended Posts

Hi, 

I need to log a request with a specific service and CI that has two questions (which will be answered in the scheduler app .json hopefully) so that the request will be created, log the start and end times on the change calendar and then close. 

This job will (hopefully) be run once at the beginning of the year, create 24 requests, add them to the calendar and then close. 

Any ideas / insights? 

First time trying something like this with APIs so total novice, but hey, every days a school day right? 

Link to comment
Share on other sites

Hi @Dan Munns,

The logChangeRequest API is the one you need to use, if you're looking to add a change to the calendar. The questions and answers can be added as a JSON array of objects to the questionFieldMap input parameter (with the string escaped, as you're inserting a JSON formatted string into your JSON config). So for example, the following config would log one Change Request at midnight on 1st January every year:

{
  "APIKey": "yourapikey",
  "InstanceID": "yourinstanceid",
  "Schedule": [{
    "Enabled": true,
    "CronSchedule": "0 0 0 1 1 *",
    "ScheduleFrom": "",
    "ScheduleTo": "",
    "Service": "apps/com.hornbill.servicemanager/ChangeRequests",
    "API": "logChangeRequest",
    "APIParams": {
      "0": {
        "Type": "Content",
        "Parameter": "summary",
        "Content": "Annual call log - Service Desk"
      },
      "1": {
        "Type": "Content",
        "Parameter": "description",
        "Content": "Annual call log description - Service Desk"
      },
      "2": {
        "Type": "Content",
        "Parameter": "status",
        "Content": "status.open"
      },
      "3": {
        "Type": "Content",
        "Parameter": "serviceId",
        "Content": "119"
      },
      "4": {
        "Type": "Content",
        "Parameter": "catalogId",
        "Content": "679"
      },
      "5": {
        "Type": "Content",
        "Parameter": "catalogName",
        "Content": "Annual Call Log"
      },
      "6": {
        "Type": "Content",
        "Parameter": "bpmName",
        "Content": "Annual Call Log"
      },
      "7": {
        "Type": "Content",
        "Parameter":"questionFieldMap",
        "Content":"[{\"question\":\"What is your name?\",\"answer\":\"Steve\",\"field_type\":\"textarea\",\"entity_type\":\"request\"},{\"question\":\"Role?\",\"answer\":\"Developer\",\"field_type\":\"text\",\"entity_type\":\"request\"}]"
      }
    }
  }]
}

There's no way for the scheduler tool to do anything with the calls once they have been logged, so the adding to the calendar and closing of the change will need to be done by the BPM workflow set against the new requests.

If you want to log more than one request, you just need to add additional objects to the Schedule array in the config.

I hope this helps, let me know if you need any more information.

Cheers,
Steve

Link to comment
Share on other sites

@Steve G thanks for this.

I am having trouble getting the BPM to kick off. All the other variables are showing correctly on the logged request and the service and catalog ids are populated but the BPM doesnt start.

Any ideas what that could be? 

"Enabled":true,
      "CronSchedule":"0 59 11 18 02 *",
      "ScheduleFrom":"2019-01-01T00:00:00.000Z",
      "ScheduleTo":"2020-01-01T00:00:00.000Z",
      "Service":"apps/com.hornbill.servicemanager/Requests",
      "API":"logRequest",
      "APIParams":{
        "0":
        {
          "Type":"Content",
          "Parameter":"summary",
          "Content":"UAT Patching - March"
        },
        "1":
        {
          "Type":"Content",
          "Parameter":"description",
          "Content":"Server patching will take place between the hours of 12:00 – 15:00."
        },
        "2":
        {
          "Type":"Content",
          "Parameter":"requestType",
          "Content":"Change Request"
        },
        "3":
        {
          "Type":"Content",
          "Parameter":"status",
          "Content":"status.new"
        },
        "4":
        {
          "Type":"Content",
          "Parameter":"categoryName",
          "Content":"IT Security->Patching"
        },
        "5":
        {
          "Type":"Content",
          "Parameter":"serviceId",
          "Content":"36"
        },
        "6":
        {
          "Type":"Content",
          "Parameter":"catalogId",
          "Content":"361"
        }

 

Link to comment
Share on other sites

@Steve G ahh ok. I am using the logRequest api and specifying the request type using the requestType parameter. 

Could this be why the BPM isnt triggered. Will I need to change it to the logChangeRequest api? Or is bpmName a valid parameter in logRequest as well? (if so it isn't on the table) 

image.png.c27cbacc8cc9d86244bf906d04b0d1ee.png

Link to comment
Share on other sites

@Steve G so adding bpmname to logRequest fails as the parameter is not recognised. 

Changing the api to logChangeRequest produces the below error: 

image.png.168940c41551d868e72af3ac3f9424d7.png

Below is the .json text:

"Enabled":true,
      "CronSchedule":"0 58 14 18 02 *",
      "ScheduleFrom":"2018-11-12T00:00:00.000Z",
      "ScheduleTo":"2020-01-01T00:00:00.000Z",
      "Service":"apps/com.hornbill.servicemanager/Requests",
      "API":"logChangeRequest",
      "APIParams":{
        "0":
        {
          "Type":"Content",
          "Parameter":"summary",
          "Content":"UAT Patching - March"
        },
        "1":
        {
          "Type":"Content",
          "Parameter":"description",
          "Content":"UAT patching will take place between the hours of 12:00 – 15:00."
        },
        "2":
        {
          "Type":"Content",
          "Parameter":"status",
          "Content":"status.new"
        },
        "3":
        {
          "Type":"Content",
          "Parameter":"categoryName",
          "Content":"IT Security->Patching"
        },
		"4":
		{
		  "Type":"Content",
          "Parameter":"serviceId",
          "Content":"36"
		},
		"5":
		{
		  "Type":"Content",
          "Parameter":"catalogId",
          "Content":"361"
		},
		"6":
		{
		  "Type":"Content",
          "Parameter":"bpmName",
          "Content":"UAT - Patching"

 

Link to comment
Share on other sites

@Steve G I still can't get this to trigger the BPM. 

I have added additional fields thinking it might be missing info or the info was not correct to trigger the BPM but still no joy.

"Enabled":true,
      "CronSchedule":"0 09 12 19 02 *",
      "ScheduleFrom":"2018-11-12T00:00:00.000Z",
      "ScheduleTo":"2099-01-01T00:00:00.000Z",
      "Service":"apps/com.hornbill.servicemanager/ChangeRequests",
      "API":"logChangeRequest",
      "APIParams":{
        "0":
        {
          "Type":"Content",
          "Parameter":"summary",
          "Content":"UAT Patching - March"
        },
        "1":
        {
          "Type":"Content",
          "Parameter":"description",
          "Content":"UAT patching will take place between the hours of 12:00 – 15:00."
        },
        "2":
        {
		  "Type":"Content",
		  "Parameter":"customerId",
		  "Content":"admin"
		},
		"3":
		{
		  "Type":"Content",
		  "Parameter":"teamId",
		  "Content":"STB/IT_*******_Development/*******_Development/"
		},
		"4":
		{
		  "Type":"Content",
          "Parameter":"status",
          "Content":"status.new"
        },
        "5":
        {
          "Type":"Content",
          "Parameter":"categoryId",
          "Content":"813"
        },
		"6":
		{
		  "Type":"Content",
          "Parameter":"serviceId",
          "Content":"36"
		},
		"7":
		{
		  "Type":"Content",
          "Parameter":"catalogId",
          "Content":"361"
		},
		"8":
		{
		  "Type":"Content",
          "Parameter":"bpmName",
          "Content":"***** IT - Patching"
		}
      }
    },

I have checked in the database and the info in the .json is all being added (I just cant see the BPM name associated with the request) but still no BPM ID. :( 

Link to comment
Share on other sites

@Steve G sorry to be a pain but I had an issue with the cron scheduler today where it logged two requests instead of just one. 

I have one for the second Wed and one for the third Wed of the month but both triggered today. 

This is the one that shouldn't have triggered: 0 0 08 09-15 2 3 which I read as everyday in Feb between 09th and 15th on Wed at 0800 so I dont see why it triggered. 

 This one also triggered, which I was expecting: 0 0 08 16-22 2 3 which I read as the same as above but between 16th and 22nd. 

Am I missing something? 

Link to comment
Share on other sites

  • 2 weeks later...

@Steve G the cron is still wrong somewhere. It is now raising 2 requests every Wednesday. It raised them today with the schedules set as so: 

      "Enabled":true,
      "CronSchedule":"0 0 8 9-15 3 3",
      "ScheduleFrom":"2018-11-12T00:00:00.000Z",
      "ScheduleTo":"2099-01-01T00:00:00.000Z",

      "Enabled":true,
      "CronSchedule":"0 0 8 16-22 3 3",
      "ScheduleFrom":"2018-11-12T00:00:00.000Z",
      "ScheduleTo":"2099-01-01T00:00:00.000Z",

It reads to me to raise the first request every Wednesday in March where the day is between 9th and 15th at 0800 with the second request being the same but with the days being between the 16th and 22nd. 

Am I going mad or am I totally going wrong somewhere?

Link to comment
Share on other sites

Hi @Dan Munns,

There was a duplicate task bug with the Go cron library used to build this tool, but was only evident on certain Windows builds - this was probably what was causing your issue. I've just released v1.2.1 of the tool that contains the latest cron library, which includes a fix for that issue. Could you download the OS-specific release ZIP from here and let me know if this fixes the issue for you? https://github.com/hornbill/goAPIScheduler/releases/tag/1.2.1

Cheers,

Steve 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...