Here is sample code written in C# to create a Company.

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Xml;
namespace TeamSupport.Api.Consumer
{
  class Program
  {
    static void Main(string[] args)
    {
      // Create a company
      string URI = "https://app.[ServerName].teamsupport.com/api/xml/customers";
      HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
      string organizationID       = "{Your organization ID}";
      string apiToken             = "{Your API Token}";
      string credentials          = string.Format("{0}:{1}", organizationID, apiToken);
      Byte[] credentialsByteArray = UTF8Encoding.UTF8.GetBytes(credentials);
      string encodedCredentials   = Convert.ToBase64String(credentialsByteArray);
      request.Headers.Add("Authorization", "Basic " + encodedCredentials);
      request.Method      = "POST";
      request.ContentType = "application/xml";
      request.UserAgent   = "your organization name";
      MemoryStream stream = new MemoryStream();
      XmlTextWriter writer = new XmlTextWriter(stream, new UTF8Encoding(false));
      writer.Formatting = Formatting.Indented;
      writer.WriteStartElement("Customer");
      writer.WriteElementString("Name", "Second Company, Inc.");
      writer.WriteElementString("Website", "www.secondcompany.com");
      writer.WriteElementString("Customercustomfield1", "CustomField1Value");
      writer.WriteFullEndElement();
      writer.Flush();
      stream.Position = 0;
      StreamReader reader = new StreamReader(stream);
      string body = reader.ReadToEnd();
      Byte[] bodyByteArray = UTF8Encoding.UTF8.GetBytes(body);
      int offSet = 0;
      int count = bodyByteArray.Length;
      using (Stream requestStream = request.GetRequestStream())
      {
        requestStream.Write(bodyByteArray, offSet, count);
      }
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    }
  }
}

Here is sample code written in PHP to create a ticket.

<?php
/* CREATE TICKET */
$orgID='ORGANIZATION_ID';
$apiToken ='Your_API_KEY';
$input_xml="<Ticket>
     <TicketStatusID>28730</TicketStatusID>
     <TicketTypeID>13237</TicketTypeID>
        <TicketTypeName>Support</TicketTypeName>
        <Name>Title goes here</Name>
        <Description>This is the content of the new ticket description.</Description>
        <Status>New</Status>
   </Ticket>";
  $host="https://app.[ServerName].teamsupport.com/api/xml/Tickets";
  $base64str=base64_encode("$orgID:$apiToken");
  $process = curl_init();
  curl_setopt( $process, CURLOPT_URL, $host );
  curl_setopt( $process, CURLOPT_POST, true );
  curl_setopt($process, CURLOPT_HTTPHEADER,array('Content-Type: application/xml', 'Authorization: Basic '.$base64str));
  curl_setopt($process, CURLOPT_TIMEOUT, 30);
  curl_setopt($process, CURLOPT_POSTFIELDS, $input_xml);
  curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
  $return = curl_exec($process);
  $response = curl_getinfo( $process );
  curl_close($process);
  print_r($return);

Here is sample code written in C# to upload an attachment to a Ticket Action or Inventory Asset:

using System;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Net;
<br>
namespace Tests
{
	class Program
	{
		static void Main(string[] args)
		{
			//**********************************************************************************************************************
			//example of API url to upload attachment file to an Action. Replace values appropriately.
			//**********************************************************************************************************************
			string URI = "https://app.teamsupport.com/api/xml/Tickets/{ticketId}/Actions/{actionId}/Attachments"; //Use correct values here
			HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URI);
			string organizationID = "{organizationId}"; //Use correct values here
			string apiToken = "{apiToken}"; //Use correct values here
			string credentials = string.Format("{0}:{1}", organizationID, apiToken);
			Byte[] credentialsByteArray = UTF8Encoding.UTF8.GetBytes(credentials);
			string encodedCredentials = Convert.ToBase64String(credentialsByteArray);
			string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x");
			request.Headers.Add("Authorization", "Basic " + encodedCredentials);
			request.Method = "POST";
			request.ContentType = "multipart/form-data; boundary=" + boundary;
			request.Accept = "text/html, application/xhtml+xml, */*";
			request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
			MemoryStream stream = new MemoryStream();
			string FilePath = "{fileToUploadPath}"; //Use correct values here
			Stream postDataStream = GetPostStream(FilePath, boundary);
			request.ContentLength = postDataStream.Length;
			Stream reqStream = request.GetRequestStream();
			postDataStream.Position = 0;
			byte[] buffer = new byte[1024];
			int bytesRead = 0;
			while ((bytesRead = postDataStream.Read(buffer, 0, buffer.Length)) != 0)
			{
				reqStream.Write(buffer, 0, bytesRead);
			}
			postDataStream.Close();
			reqStream.Close();
			StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream());
			string Result = sr.ReadToEnd();
		}
		private static Stream GetPostStream(string filePath, string boundary)
		{
			Stream postDataStream = new System.IO.MemoryStream();
			FileInfo fileInfo = new FileInfo(filePath);
			string fileHeaderTemplate = "--" + boundary + Environment.NewLine +
			"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"" +
			Environment.NewLine + "Content-Type: */*" + Environment.NewLine + Environment.NewLine;
			byte[] fileHeaderBytes = System.Text.Encoding.UTF8.GetBytes(string.Format(fileHeaderTemplate, "UploadFile", fileInfo.FullName));
			postDataStream.Write(fileHeaderBytes, 0, fileHeaderBytes.Length);
			FileStream fileStream = fileInfo.OpenRead();
			byte[] buffer = new byte[1024];
			int bytesRead = 0;
			while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
			{
				postDataStream.Write(buffer, 0, bytesRead);
			}
			fileStream.Close();
			byte[] endBoundaryBytes = System.Text.Encoding.UTF8.GetBytes(Environment.NewLine + "--" + boundary);
			postDataStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
			return postDataStream;
		}
	}
}

Click here to learn more about our API.

Need more help with this?
Customer Support

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.