title: Submit Form POST using VB .NET
body: <p>I have searched a solution to my problem extensively, and while I found answers that seemed to have worked for others, I am just having a real hard time figuring this out. But I feel I am very close.</p>
  
  <p>I am trying to make an Rest API call to an online application called <a href="https://www.zoho.com/creator/help/api/rest-api/rest-api-add-records.html" rel="nofollow noreferrer">Zoho Creator</a>. I am trying to implement the Add Record call. The example they give is using an HTML form with a submit button. But I need to Add Records from a VB .NET desktop application. I have tried both WebClient and WebRequest, but I am unsuccessful in those attempts. But I have been successful using these methods with other API calls and other APIs, it's just this Add Records one that is giving me trouble. </p>
  
  <p>One of the required parameters is an authtoken, which for security reasons I replaced with "xxxxxxxxxx". Here is an html form that I created and when I use it, it created the record successfully thru the API, it's just adding a single record with the single field value for "TicketID".</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;body&gt;
     &lt;form method="POST" action="https://creator.zoho.com/api/max1stdirectcom/xml/service-orders/form/Ticket_form/record/add"&gt;
     &lt;input type="hidden" name="authtoken" value="xxxxxxxxxx"/&gt;
     &lt;input type="hidden" name="scope" id="scope" value="creatorapi"/&gt;
     &lt;input type="text" name="TicketID" value="123"/&gt;
     &lt;input type="submit" value="Add Record"/&gt;
  &lt;/form&gt;
  &lt;body&gt;
  </code></pre>
  
  <p>So, the above works perfectly fine. now, here is my VB .NET code trying to replicate the same result using WebRequest:</p>
  
  <pre><code>Protected Sub PostTo(sTicketID As String)
      Dim url As String = "https://creator.zoho.com/api/max1stdirectcom/xml/service-orders/form/Ticket_form/record/add"
      Dim request As WebRequest = WebRequest.Create(url)
  
      request.Method = "POST"
  
      ' Create POST data and convert it to a byte array.  
      Dim postData As String = "?authtoken=" &amp; "xxxxxxxxxx" &amp; "?scope=creatorapi" &amp; "?TicketID=" &amp; sTicketID
      Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
  
      ' Set the ContentType property of the WebRequest.  
      request.ContentType = "application/x-www-form-urlencoded"
  
      ' Set the ContentLength property of the WebRequest.  
      request.ContentLength = byteArray.Length
  
      ' Get the request stream.  
      Dim dataStream As Stream = request.GetRequestStream()
  
      ' Write the data to the request stream.  
      dataStream.Write(byteArray, 0, byteArray.Length)
  
      ' Close the Stream object.  
      dataStream.Close()
  
      ' Get the response.  
      Dim response As WebResponse = request.GetResponse()
  
      ' Display the status.  
      Debug.WriteLine(CType(response, HttpWebResponse).StatusDescription)
  
      ' Get the stream containing content returned by the server.  
      dataStream = response.GetResponseStream()
  
      ' Open the stream using a StreamReader for easy access.  
      Dim reader As New StreamReader(dataStream)
  
      ' Read the content.  
      Dim responseFromServer As String = reader.ReadToEnd()
      ' Display the content.  
  
      Debug.WriteLine(responseFromServer)
  
      ' Clean up the streams.  
      reader.Close()
      dataStream.Close()
      response.Close()
  
  End Sub
  </code></pre>
  
  <p>The response I get from the call using the above VB .Net code is:</p>
  
  <pre><code>&lt;response&gt;
    &lt;errorlist&gt;
      &lt;error&gt;
        &lt;code&gt;2899&lt;/code&gt;
        &lt;message&gt;&lt;![CDATA[Permission Denied To Add Record(s).]]&gt;&lt;/message&gt;
      &lt;/error&gt;
    &lt;/errorlist&gt;
  &lt;/response&gt;
  </code></pre>
  
  <p>So it is obviously making good communication with the API on some level. I am using the correct AuthToken, so not sure why it is rejecting the adding of the record. I am passing the same exact "credentials" as the basic form POST, but getting different result.</p>
  
  <p>Any recommendations for me to try?</p>