Create request via powershell script (custom trigger)

Create request via powershell script (custom trigger)

Hi everyone!

Please, give me some example - about create new request via custom triggers on powershell. I write script on python, but there is a problem with OS :(. Just need translate.  I would appreciate for an early reply

Script on python:

  1. import requests
  2. import sys
  3. import json
  4. import datetime

  5. +filename = str(sys.argv[1])
  6.    
  7. with open(filename) as data_file:
  8. data = json.load(data_file)
  9. requestObj = data['request']

  10. workorderid = requestObj['WORKORDERID']
  11. requester = requestObj['REQUESTER']
  12. createdby = requestObj['CREATEDBY']
  13. site = requestObj['SITE']
  14. CREATEDTIME = requestObj['CREATEDTIME']
  15. scheduledstarttime = datetime.datetime.fromtimestamp(int(CREATEDTIME) / 1e3).strftime('%d %b %Y, %H:%M:%S')

  16. with requests.Session() as s:
  17.     url = "localhost:8080" 

  18. jsonData ='''{
  19.     "operation": {
  20.         "details": {
  21.             "title": "title1",
  22.             "description": "description 1 :'''+workorderid+'''.",
  23.             "requester": "'''+requester+'''",
  24.             "IS_CATALOG_TEMPLATE": "true",
  25.             "SITE": "'''+site+'''",
  26.             "CATEGORY": "cat1",
  27.             "SUBCATEGORY": "subcat1",
  28.             "ITEM": "item1",
  29.             "GROUP": "line1"
  30.         }
  31.     }
  32. }'''

  33. json_data = json.dumps(jsonData)
  34. apprUrl = url + "/sdpapi/request"
  35. data = {'INPUT_DATA' : jsonData ,'TECHNICIAN_KEY': '*******************','format':'json','OPERATION_NAME':'ADD_REQUEST'}

  36. r = s.post(apprUrl,data)
  37. if(r.status_code == 200):
  38.   print("Session request submitted successfully")
  39.   print(r.json())
  40. else :
  41.   print("Problem submitting session request")
  42.   print(r.json())