Cannot send multiline notes/conversations with API

Cannot send multiline notes/conversations with API

I'm using a couple of scripts to automate a workflow we are using. The workflow is as follows :

A user requests access to a certain system, He or she has to fill in 2 fields, 1 dropdown and 1 multiline. Both are custom fields. Upon submitting the request, SDP asks for an approval to the user's manager. Depending on getting an approval or not, SDP sends an email to the department that grants the access or sends a mail to the user that the approval is denied and in both cases it adds a note with the taken action to the request. We use Powershell for this.

However, when the user uses linebreaks in the multilined field, the script breaks because somehow the API does not accept the JSON, because of the linebreaks. So the script is executed, but nothing happens because of the linebreaks. If we manually remove the linebreaks and run the script again, everything is fine. Due to the amount of tickets that we get, we really like to automate this. Is there a way to use a multilined field with the API. The JSON we are generating is below


  1. #=======================================================================
  2. # Add Request fields values
  3. #=======================================================================
  4. $workorderid = $obj.request.WORKORDERID
  5. $requester = $obj.request.REQUESTER
  6. $Systemtyperequest = $obj.request."Tot welk systeem vraag je toegang"
  7. $Queuename = $obj.request."Welke Queues in Blue heb je nodig?"

  8. #=======================================================================
  9. # Setting Reply settings
  10. #=======================================================================
  11. $replyurl = $sdphost + "sdpapi/request/" + $workorderid
  12. $replymethod = "POST"
  13. $replyoperation = "REPLY_REQUEST"
  14. $Replyreciever = "reciever email"
  15. #=======================================================================
  16. # Configure the textinput for the reply
  17. #=======================================================================
  18. $replydescription = "$requester heeft toegang gevraagd tot het systeem $Systemtyperequest. Hij wil graag toegang tot de volgende queues: $Queuename."

  19. #=======================================================================
  20. #Configure input data for adding a reply
  21. #=======================================================================
  22. $replyinputdata = @"
  23. {
  24.     "operation": {
  25.         "details": {
  26.             "to": "$Replyreciever",
  27.             "cc": "",
  28.             "subject": "[Request ID:##$workorderid##] Aanvraag Toegang Blue/Parley/Obi4wan/Bas",
  29.             "description": "$replydescription"
  30.         }
  31.     }
  32. }
  33. "@

  34. #=======================================================================
  35. # Sending Reply
  36. #=======================================================================
  37. $replyparams = @{INPUT_DATA=$replyinputdata;OPERATION_NAME=$replyoperation;TECHNICIAN_KEY=$techkey;format='json'}
  38. Invoke-WebRequest -Uri $replyurl -Method $replymethod -Body $replyparams

  39. #=======================================================================
  40. # Setting Notes settings
  41. #=======================================================================
  42. $notesurl = $sdphost + "sdpapi/request/" + $workorderid + "/notes"
  43. $notesmethod = "POST"
  44. $notesoperation = "ADD_NOTE"

  45. #=======================================================================
  46. # Configure the textinput for the note
  47. #=======================================================================
  48. $notescontent = "$requester wil in het systeem $Systemtyperequest toegang tot de queue $Queuename. De aanvraag is doorgestuurd naar het volgende adres: $Replyreciever"

  49. #=======================================================================
  50. # Configure input data for adding note to request
  51. #=======================================================================
  52. $notesinputdata = @"
  53. {
  54.     "operation": {
  55.         "details": {
  56.             "notes": {
  57.                 "note": {
  58.                     "ispublic": "false",
  59.                     "notestext": "$notescontent"
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
  65. "@

  66. #=======================================================================
  67. # Sending Notes
  68. #=======================================================================
  69. $noteparams = @{INPUT_DATA=$notesinputdata;OPERATION_NAME=$notesoperation;TECHNICIAN_KEY=$techkey;format='json'}
  70. Invoke-WebRequest -Uri $notesurl -Method $notesmethod -Body $noteparams


Edit : We are using SDP version 10.0 Build 100200 on Postgres

                  New to ADSelfService Plus?