0

I am trying to convert a cURL string to VB.NET from the Pivotal Tracker REST V5 API, see the below example from https://www.pivotaltracker.com/help/api/rest/v5#Story:

export TOKEN='your Pivotal Tracker API token'
export PROJECT_ID=99

curl -X PUT -H "X-TrackerToken: $TOKEN" -H "Content-Type: application/json" -d '{"current_state":"accepted","estimate":1,"name":"Exhaust ports have ray shielding"}' "https://www.pivotaltracker.com/services/v5/projects/$PROJECT_ID/stories/555"

I am trying to use cURL to transfer sample data to Pivotal Tracker. Once working, I will be setting up a ASP.NET bug submission form.

Here is my VB.NET button click code:

Protected Sub submitinfo_Click(sender As Object, e As EventArgs) Handles submitinfo.Click

    Dim wHeader As WebHeaderCollection = New WebHeaderCollection()

    wHeader.Clear()
    wHeader.Add("X-TrackerToken: [***MY TOKEN***]")

    ' variables to store parameter values
    Dim surl As String = "https://www.pivotaltracker.com/services/v5/projects/1398094/stories"
    Dim data As String = "{'current_state':'accepted','estimate':1,'name':'Exhaust ports have ray shielding'}"

    ' create the POST request
    Dim webRequest__1 As HttpWebRequest = DirectCast(System.Net.WebRequest.Create(surl), HttpWebRequest)
    webRequest__1.Method = "PUT"
    webRequest__1.Headers = wHeader
    webRequest__1.ContentType = "application/json"

    '  This actually does the request and gets the response back
    Dim resp As HttpWebResponse = DirectCast(webRequest__1.GetResponse(), HttpWebResponse)
    Dim sResponse As String = ""



    ' POST the data
    Using requestWriter2 As New StreamWriter(webRequest__1.GetRequestStream())
        requestWriter2.Write(data)
    End Using


    Dim responseData As String = String.Empty

    Using responseReader As New StreamReader(webRequest__1.GetResponse().GetResponseStream())
        ' dumps the HTML from the response into a string variable
        responseData = responseReader.ReadToEnd()
    End Using

    Label1.Text = responseData

End Sub

I have tried to adapt code from:

I am getting a 404 error - but the address is correct! I am pulling my hair out, please help!

Many Thanks!

Chris

Community
  • 1
  • 1
Chris Hill
  • 51
  • 12
  • Try altering single quote with double quote for your json data. Some json decoder may fail to parse json with single quote (i.e. my version of php5.3.2 decoder fails) – Sabuj Hassan Nov 26 '15 at 11:08
  • Thanks for reply Sabuj - but I'm still getting the 404 error. – Chris Hill Nov 26 '15 at 11:59

0 Answers0