Been searching around and cannot find the answer to either of my problems.
a) can i create a new user with a company in one go via API or does it need to be 2 separate posts? (a customer and then user?)
b) i am using VB .NET and although i can find many examples with PHP none with VB,
I am sure it is simple but everything i tried receives error 406:Not Acceptable at this point i am unsure if it is my XML string builder or my credentials but i was hoping that someone would have experience in VB.
Here is my code:
Shared Function Create() As String
Dim n As String
Dim em As String
Dim c As String
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim address As Uri
Dim data As StringBuilder
Dim byteData() As Byte
Dim postStream As Stream = Nothing
Dim results As String
n = "TESTS"
em = "email@example.com"
c = "clientref"
address = New Uri("https://****.freshdesk.com/contacts.xml")
request = DirectCast(WebRequest.Create(address), HttpWebRequest)
request.Method = "POST"
request.ContentType = "application/xml"
request.Credentials = New NetworkCredential("APIKEY", "x")
request.Accept = "*/*"
' Create the data we want to send (each data.Append is for specific paramater data)
data = New StringBuilder()
data.Append("<?xml version=""1.0"" encoding=""UTF-8""?>")
data.Append("<email>" + em + "</email>")
data.Append("<name>" + n + "</name>")
' Create a byte array of the data we want to send
byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())
' Set the content length in the request headers
request.ContentLength = byteData.Length
' Write data
postStream = request.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
response = request.GetResponse
Dim receiveStream As Stream = response.GetResponseStream
Dim rdr As New StreamReader(receiveStream, System.Text.Encoding.ASCII)
Dim strResp As String = rdr.ReadToEnd
If Not postStream Is Nothing Then postStream.Close()
Many thanks in advance