7 Replies Latest reply on Mar 14, 2018 5:25 AM by DanielKakona

    Web API

    Pandor Apprentice

      Hi All,

       

       

      I have a web application in our IP Management system which creates a config file for the subnet management. I want that when this config file is created, a task is automatically created in HEAT (Ivanti SM) and this config file should be attached to this Task record in HEAT. I want to achieve this using Web API.

       

       

      Has someone already done something like that? I will really appreaciate some inputs on how I can achieve this (if this is even possible) as I don't have much expertise with Web APIs.

       

       

       

       

      Thank You.

        • 1. Re: Web API
          florian1 Expert

          First of all, I definitely recommend you to take a look at Ivanti SM Web Services Guide v2017.2.

          It's a good documentation to start with.

           

          A task always needs a parent object, here's a simple example when using Incident# as the parent object.

             class Program
              {
                  private static FRSHEATIntegration frSvc = new FRSHEATIntegration();
                  private static string _apiUserName = "HEATAdmin";
                  private static string _apiPassword = "[email protected]";
                  private static string _apiTenantId = "yourtenant.contoso.com";
                  private static string _apiRole = "Admin";
                  private static string _authSessionKey = String.Empty;
                  
                  static void Main(string[] args)
                  {
                      // Connect to obtain API key
                      var connectResponse = frSvc.Connect(_apiUserName, _apiPassword, _apiTenantId, _apiRole);
                      if (connectResponse.connectionStatus == "Success")
                      {
                          _authSessionKey = connectResponse.sessionKey;
                      }
          
                      // create Incident object
                      ObjectCommandData dataIncident = new ObjectCommandData();
                      dataIncident.ObjectType = "Incident#";
                      List<ObjectCommandDataFieldValue> dataFieldsIncident = new List<ObjectCommandDataFieldValue>();
          
                      Dictionary<string, object> fieldsIncident = new Dictionary<string, object>
                      {
                          ["ProfileLink"] = "3734B48625D043B0939456EBF5B07F43", // InternalServices, change as needed
                          ["Subject"] = "Need to swap out the hard disk",
                          ["Service"] = "Desktop-Service",
                          ["Category"] = "Hardware",
                          ["Urgency"] = "Low",
                          ["Impact"] = "Low",
                          ["OwnerTeam"] = "IT",
                          ["Owner"] = "fdeutsch",
                          ["Symptom"] = @"Description"
                      };
          
                      foreach (string key in fieldsIncident.Keys)
                      {
                          dataFieldsIncident.Add(new ObjectCommandDataFieldValue()
                          {
                              Name = key,
                              Value = fieldsIncident[key].ToString()
                          });
                      }
          
                      dataIncident.Fields = dataFieldsIncident.ToArray();
          
                      FRSHEATIntegrationCreateBOResponse result = frSvc.CreateObject(_authSessionKey, _apiTenantId, dataIncident);
          
                      // create task object
                      var parentObjectRecId = result.recId;
                      var parentObjectType = result.obj.TableRef;
          
                      ObjectCommandData dataTask = new ObjectCommandData();
                      dataTask.ObjectType = "Task#Assignment";
                      List<ObjectCommandDataFieldValue> dataFieldsTask = new List<ObjectCommandDataFieldValue>();
          
                      Dictionary<string, object> fieldsTask = new Dictionary<string, object>
                      {
                          ["Subject"] = "Need to swap out the hard disk",
                          ["Details"] = "Task Details",
                          ["OwnerTeam"] = "IT"
                      };
          
                      foreach (string key in fieldsTask.Keys)
                      {
                          dataFieldsTask.Add(new ObjectCommandDataFieldValue()
                          {
                              Name = key,
                              Value = fieldsTask[key].ToString()
                          });
                      }
          
                      dataTask.Fields = dataFieldsTask.ToArray();
                      dataTask.LinkToExistent = new LinkEntry[]
                      {
                          // link to the Incident we just created
                          new LinkEntry()
                          {
                              Action = "Link",
                              Relation = "IncidentContainsTask",
                              RelatedObjectType = parentObjectType,
                              RelatedObjectId = parentObjectRecId
                          }
                      };
          
                      FRSHEATIntegrationCreateBOResponse taskResult = frSvc.CreateObject(_authSessionKey, _apiTenantId, dataTask);
          
                      // add attachment
                      ObjectAttachmentCommandData taskAttachmentData = new ObjectAttachmentCommandData() {
                          ObjectId = taskResult.recId,
                          ObjectType = taskResult.obj.TableRef,
                          fileName = "testfile.txt",
                          fileData = File.ReadAllBytes(@"c:\temp\testfile.txt"),
                      };
          
                      FRSHEATIntegrationAddAttachmentResponse attachmentResponse = frSvc.AddAttachment(_authSessionKey, _apiTenantId, taskAttachmentData);
          
                      Console.ReadLine();
                  }
              }
          
          1 of 1 people found this helpful
          • 2. Re: Web API
            Pandor Apprentice

            Hi florian1

             

            Thanks so much for your input. Now I have something to guide me through what I want to achieve. Much appreciated.

             

            However is it possible to link the attachments to various task records or just to specific records as I see the RecID's for a specific record is stated in the code.

             

            TIA.

            1 of 1 people found this helpful
            • 3. Re: Web API
              DanielKakona Apprentice

              Hi Florian,

               

              Thanks for the code which you provided above. I have tried this and it works for me.

               

              However, I am only able to access the FRSHEATIntegration Web Service link (https://<TenantName>/ServiceAPI/FRSHEATIntegration.asmx) on my App Server. I cannot access this link outside the server. Is there something which I need to do in order to be able to access this url out of the server?

               

              TIA.

              • 4. Re: Web API
                florian1 Expert

                Hi Daniel,

                 

                normally you don't need to do anything.

                Can you please try to access the URL directly from your browser? On my development machine it's "http://192.168.180.1/HEAT/ServiceAPI/FRSHEATIntegration.asmx?wsdl" for example.

                Maybe you get a HTTP 401 or any other 4xx error..

                • 5. Re: Web API
                  florian1 Expert

                  Of course, you are not limited to specific records.

                  The only hard coded RecId here refers to the employee record. Instead of hard coding this you can also use the Search() method and parse the Loginid as search parameter to get the employee's RecId.

                   

                  If you create a task object,

                  FRSHEATIntegrationCreateBOResponse taskResult = frSvc.CreateObject(_authSessionKey, _apiTenantId, dataTask); 
                  

                  you will receive the whole created object (with its RecId etc.) in the response.

                   

                  So if you were to create 5 tasks you will receive 5 different RecIds:

                  Enumerable.Range(0, 5).ToList().ForEach(arg =>
                  {
                      // create 5 tasks..
                      ObjectCommandData dataTask = new ObjectCommandData();
                      dataTask.ObjectType = "Task#Assignment";
                      // [...]
                      FRSHEATIntegrationCreateBOResponse taskResult = frSvc.CreateObject(_authSessionKey, _apiTenantId, dataTask);
                  
                      Console.WriteLine($"Created task #{arg.ToString()}: {taskResult.recId}");
                  });
                  

                   

                  You can also query existing Incidents with the Search() method and update these tasks' attachments.

                  Here's a Powershell example to use the Search function: Simplified API search using Powershell + JSON.

                  1 of 1 people found this helpful
                  • 6. Re: Web API
                    Pandor Apprentice

                    Thanks so much. This was a guide in the right direction.I have tried it already,and its working.

                     

                    Thanks again florian1

                    • 7. Re: Web API
                      DanielKakona Apprentice

                      Hi Florian,

                      Thanks so much . It worked perfectly.