简体   繁体   中英

Autotask Web Service API integration with C#


I want to develop an Application that gets data form Autotask(Web Service API) using c#.
I just only want to count all the task or ticket form Autotask.
I have here the link of the sample of autotask in visual studio and I don't know how does this complex query works like , I just want to select all the task or the ticket, but dont know where to start.

I do a lot of research but nothing can answer my question. Does anyone knows about this? Can you help me with this. Thank you

This post is a little late. Still here goes. You might want to work with Autotask API's own Visual Studio solutions which are linked on their web services page . Namely the VS solutions are here . Please open the solution (the C# one) in Visual Studio and work with the sample code there. It has code to get popular entities like accounts, tickets, contacts etc. All you need to get it running is your Autotask API username and password which you will need to update in app.config of the C# sample console app.

To get all the tickets, query tickets which have id greater than zero.Generally ticket ids are greater than zero.

<queryxml>
<entity>ticket</entity>
<query>
<field>id
<expression op="greaterthan">0</expression>
</field>
</query>
</queryxml>

You may also want to narrow down the search by passing an account id which will return a lower number of tickets than the above search.

<queryxml>
<entity>ticket</entity>
<query>
<field>AccountID
<expression op="equals">123</expression>
</field>
</query>
</queryxml>

Here's how I'm doing it by ID. I added this code to the SampleAutoTaskAPI.AutoTaskAPITests in the sample file here . However, it did not contain a method for retrieving tickets, so I added one. Here it is: (this get's one ticket by ID, but could be easily modified)

     /// <summary>
    /// This method searches for a ticket given an ID.
    /// </summary>
    /// <param name="ticketId">Contains the ticket id to search for</param>
    /// <returns>ID of the resource.</returns>
    public Ticket FindTicket(string ticketId)
    {
       Ticket ticket = null;

        // Query Resource to get the owner of the lead
        StringBuilder strResource = new StringBuilder();
        strResource.Append("<queryxml version=\"1.0\">");
        strResource.Append("<entity>Ticket</entity>");
        strResource.Append("<query>");
        strResource.Append("<field>id<expression op=\"equals\">");
        strResource.Append(ticketId);
        strResource.Append("</expression></field>");
        strResource.Append("</query></queryxml>");

        ATWSResponse respResource = this.atwsServices.query(strResource.ToString());

        if (respResource.ReturnCode > 0 && respResource.EntityResults.Length > 0)
        {
            ticket = (Ticket)respResource.EntityResults[0];
        }

        return ticket;
    }

**In your program.cs:**

AutotaskApiTests test = new AutotaskApiTests(ConfigurationManager.AppSettings["APIUsername"], ConfigurationManager.AppSettings["APIPassword"]);

Ticket ticket  = test.FindTicket("1234");
Debug.Write(ticket);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM