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 = "firstname.lastname@example.org"
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
FYI we managed to solve this problem.
The authorisation section must be converted to 64bit string, then the api works.
To add company to a user:
Company must be set up first
<?xml version="1.0" encoding="UTF-8"?>
<name>Company Name</name> <!--(Mandatory)-->
then ID returned.
Once company set and you know ID
In new user created include <customer-id>Returned ID</customer-id>
Could you post your working solution - I am struggling with a similar problem with Tickets and c#?
One of the programers i work with cracked it, they included;
Public credidentials As String = "API:X"
then a "Send freshdesk" function
Dim wHeader As WebHeaderCollection = New WebHeaderCollection()
Dim wRequest As HttpWebRequest = DirectCast(System.Net.HttpWebRequest.Create(sUrl), HttpWebRequest)
Thanks Mark, I have it working now.
For anyone else, here is a C# example that gets all tickets. It sits behind a form with a textbox and a button on it.
You can find more API repos here : github.com/freshdesk/fresh-samples