6 Replies Latest reply on Apr 2, 2015 8:27 AM by Stu McNeill

    How to call an action via the REST interface?

    jkhill Specialist

      I have a Create Related action for a collection in my Incident process that I'd like to call via the REST interface.  I seem to missing something, because every time I try this in the browser, I get the window I would expect to see if I clicked on the action manually, and when I try it via cURL, I get the json definition of the incident.  What I don't get is an error message.

       

      Here's my url:

      /SD.WebAccess/object/open.rails?class_name=IncidentManagement.Incident&key=b80f236c-19a3-4353-be86-e6630cdf713c&function_name=AddInterestedParty&_Title=test&_InterestedParty.Guid=20B1509E-B2A9-4BB3-96E6-EDE5812D342B

       

      My _AutosysInterestedParty object has one mandatory field (_Title) and one optional field (_InterestedParty, which links to the User object).  It also has an optional field to link back to the incident and some persistence fields for Create User and Update User.

       

      I tried adding &_Incident.Guid=b80f236c-19a3-4353-be86-e6630cdf713c to the tail end but that didn't help.

       

      I tried adding &class_name=IncidentManagement._AutosysInterestedParty after the function_name argument, but that gave me the following error:

      Invalid class type: IncidentManagement.Incident,IncidentManagement._AutosysInterestedParty.

       

      I also tried adding &child_class_name=IncidentManagement._AutosysInterestedParty after the function_name argument.  It accepted the argument but ignored it, behaving the same way as excluding the argument altogether did.  That said, when I mistyped the value as Incident._AutosysInterestedParty it generated an error about an invalid module Id, so I know it's paying attention; I just don't know what else I'm missing.

        • 1. Re: How to call an action via the REST interface?
          dmshimself ITSMMVPGroup

          Tricky - have you been given access to the mashup documentation by support?

          • 2. Re: How to call an action via the REST interface?
            jkhill Specialist

            Yes.  It has a good example of how to add a child incident but not of how to create a new collection item.  The other thing I was toying with was just creating a new object of type Autosys Interested Party and at that time adding the incident guid, but (a) that feels like cheating and (b) it doesn't create the history in the Incident.

             

            If I can't figure it out I'll probably just use Event Manager, but I find that more complicated to set up.

            • 3. Re: How to call an action via the REST interface?
              Jamie Cannon ITSMMVPGroup

              You may need to include the lifecycle name.. it may not automatically pick up.

              • 4. Re: How to call an action via the REST interface?
                Stu McNeill Employee

                Hi,

                 

                You won't have much luck with using "object/open" to run an action.  Depending on the type of action you  need to be calling either "object/save" or "object/invokeFunction".  If this is a regular old collection action you need to use "object/save" and pass in the right parameters so it knows the action name and the parent object.  The easiest way to find out the exact parameters required is to try it using the examples provided in the JavaScript library we released and trace the web request it generates using either Fiddler of the F12 developer tools directly in your web browser.  You can get the library here: JavaScript library for integrating with Web Access v1.1.

                 

                Thanks

                Stu

                • 5. Re: How to call an action via the REST interface?
                  jkhill Specialist

                  Great tip, Stu!

                   

                  I had previously tried to decode the JavaScript library by hand but wasn't getting anywhere.  Running it through Fiddler proved to be the easiest solution - though I had previously used Fiddler only once before about two years ago, it took me all of five minutes to figure out where the data was that I needed.

                   

                  For the record, here's the syntax that works.

                  /object/save.rails?class_name=IncidentManagement._AutosysInterestedParty&is_new=true&_Title=jon&_InterestedParty=20B1509E-B2A9-4BB3-96E6-EDE5812D342B&parent_function_name=AddInterestedParty&parent_class_name=IncidentManagement.Incident&parent_key=b80f236c-19a3-4353-be86-e6630cdf713c


                  I was going about it all wrong.  Rather than reference an incident and create its child objects, the new code creates the collection item and then pulls in the Incident as a parent object.  I also see the convention of using parent_ and child_ in the attribute names.

                  • 6. Re: How to call an action via the REST interface?
                    Stu McNeill Employee

                    Glad it was nice and easy to figure out.  I love it when a plan comes together!