Get your own customer support community
 

Is anyone using asp.net to connect to the Tracket API

We are integrating Tracker actually into our product. Users of our system can report bugs and post ideas, I want these to pipe straight into the Icebox where we then manage them.

Users do not see Pivotal tracker however all their interactions go directly into the system. When we then start a project and place it in the back log we want users to be able to see what we are working on - this binds our clients closer to us.

All this is done in asp.net we are trying to save time by getting some already written code. Anyone?
 
happy I’m excited at the prospect of solving this problem
Inappropriate?
1 person has this question

  • Michael McKerlie
    Inappropriate?
    We solved this issue and got it working. I will post the code up to PivotalTracker so it can be shared.

    Michael
     
    happy I’m happy
  • Michael McKerlie
    Inappropriate?
    here is the code
    Code here :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Threading;
    using System.Net;
    using System.IO;
    using System.Text;

    using System.Xml;
    using System.Xml.Serialization;
    using System.Diagnostics;

    namespace PivotalTrackerAPI
    {
    public partial class Default : System.Web.UI.Page
    {

    protected void Page_Load( object sender, EventArgs e )
    {

    }

    protected void AddStory_Click( object sender, EventArgs e )
    {

    // curl -H "X-TrackerToken: TOKEN" -H "Content-type: application/xml" \
    //-d "<story><story_type>feature</story_type><name>Fire torpedoes</name><requested_by>James Kirk</requested_by></story>" \
    //-X POST http://www.pivotaltracker.com/service...

    string url = "http://www.pivotaltracker.com/services/v2/projects/PROJECT_ID/stories?token=TOKEN";

    string story = "<story><story_type>feature</story_type><name>Fire torpedoes</name><requested_by>Peter</requested_by></story>";

    this.AddStoryOrTask( url, story );

    }

    protected void AddTask_Click( object sender, EventArgs e )
    {

    // curl -H "X-TrackerToken: TOKEN" -H "Content-type: application/xml" \
    //-d "<task><description>clean shields</description></task>" \
    //-X POST http://www.pivotaltracker.com/service...

    string url = "http://www.pivotaltracker.com/services/v2/projects/PROJECT_ID/stories/STORY_ID/tasks?token=TOKEN";

    string task = "<task><description>clean the torpedo tube</description></task>";

    this.AddStoryOrTask( url, task );

    }

    protected void GetStories_Click( object sender, EventArgs e )
    {

    string url = "http://www.pivotaltracker.com/services/v2/projects/PROJECT_ID/stories?token=TOKEN";

    GetStories( new Uri( url ) );

    }

    public static void GetStories( Uri url )
    {

    // Create a new HttpWebRequest object.
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );

    request.Proxy = WebProxy.GetDefaultProxy();

    Stream objStream;
    objStream = request.GetResponse().GetResponseStream();

    StreamReader objReader = new StreamReader( objStream );

    string sLine = "";
    int i = 0;
    StringBuilder sb = new StringBuilder();

    while( sLine != null )
    {
    i++;
    sLine = objReader.ReadLine();
    if( sLine != null )
    {
    Console.WriteLine( "{0}:{1}", i, sLine );
    sb.Append( sLine );
    }

    }
    Console.ReadLine();

    string xml = sb.ToString();

    XmlDocument xmlDoc = new XmlDocument();

    xmlDoc.LoadXml( xml );

    xmlDoc.Save( @"c:\stories.xml" );

    StreamReader str = new StreamReader( @"c:\stories.xml" );
    XmlSerializer xSerializer = new XmlSerializer( typeof( stories ) );

    stories myStories = (stories)xSerializer.Deserialize( str );

    foreach( storiesStory story in myStories.story )
    {
    Debug.Write( string.Format( "Name: {0} {1}", story.name, Environment.NewLine ) );
    Debug.Write( string.Format( "Description: {0} {1}", story.description, Environment.NewLine ) );
    Debug.Write( Environment.NewLine );

    }

    str.Close();

    }

    private void AddStoryOrTask( string url, string data )
    {

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );

    // Set the ContentType property.
    request.ContentType = "application/xml";

    // Set the Method property to 'POST' to post data to the URI.
    request.Method = "POST";

    request.Proxy = WebProxy.GetDefaultProxy();

    byte[] byteArray = Encoding.UTF8.GetBytes( data );

    request.ContentLength = byteArray.Length;

    Stream dataStream = request.GetRequestStream();
    dataStream.Write( byteArray, 0, byteArray.Length );

    dataStream.Close();

    Stream objStream;
    objStream = request.GetResponse().GetResponseStream();

    StreamReader objReader = new StreamReader( objStream );

    string sLine = "";
    int i = 0;
    StringBuilder sb = new StringBuilder();

    while( sLine != null )
    {
    i++;
    sLine = objReader.ReadLine();
    if( sLine != null )
    {
    Console.WriteLine( "{0}:{1}", i, sLine );
    sb.Append( sLine );
    }

    }
    Console.ReadLine();

    string xml = sb.ToString();

    XmlDocument xmlDoc = new XmlDocument();

    xmlDoc.LoadXml( xml );

    xmlDoc.Save( @"c:\stories.xml" );

    }

    }
    }
     
    happy I’m happy
    Sprite_screen 1 person says this answers the question
User_default_medium