Using the API to create Contacts in Scalix from intranet

Best practice information from Scalix users relating to integration of Scalix with other products.

Moderator: ScalixSupport

tenchi96
Posts: 15
Joined: Fri Dec 08, 2006 4:38 pm

Using the API to create Contacts in Scalix from intranet

Postby tenchi96 » Sun May 04, 2008 8:00 pm

Hey everyone, I'm working on an intranet site for my company and one of the requests was to be able to dump contacts into a public folder when they are created or modified on the intranet. I am using ASP/VB.net 3.5. Here is the code I always seem to get a 400 error when it POSTS to the API can anyone help. Thanks
Dim Webrequest As HttpWebRequest
Dim Webresponse As HttpWebResponse = Nothing
Dim address As Uri
Dim post As String = "<?xml version=""1.0"" encoding=""UTF-8""?>" _
& "<contact>" _
& "<subject>" & LNametxt.Text & ", " & FNametxt.Text & "</subject>" _
& "<direct_ref>" & scalixDref.Value & "</direct_ref>" _
& "<message_class>IPM.Contact</message_class>" _
& "<display_name>" & FNametxt.Text & " " & MNametxt.Text & " " & LNametxt.Text & "</display_name>" _
& "<first_name>" & FNametxt.Text & "</first_name>" _
& "<middle_name>" & MNametxt.Text & "</middle_name>" _
& "<last_name>" & LNametxt.Text & "</last_name>" _
& "<company_name>" & Companytxt.Text & "</company_name>" _
& "<email1_address>" & Emailtxt.Text & "</email1_address>" _
& "<email1_address_with_comment>" & FNametxt.Text & " " & LNametxt.Text & "<""" & Emailtxt.Text & """></email1_address_with_comment>" _
& "<email1_display_name>" & Emailtxt.Text & "</email1_display_name>" _
& "<email1_address_type>SMTP</email1_address_type>" _
& "<work_phone_number>" & Phonetxt.Text & "</work_phone_number>" _
& "<fax1_address_type>FAX</fax1_address_type>" _
& "<work_fax_number>" & Faxtxt.Text & "</work_fax_number>" _
& "<mobile_phone_number>" & Celltxt.Text & "</mobile_phone_number>" _
& "<pager_phone_number>" & Pagertxt.Text & "</pager_phone_number>" _
& "<work_address_street>" & Addresstxt.Text & "</work_address_street>" _
& "<work_address_city>" & Citytxt.Text & "</work_address_city>" _
& "<work_address_state>" & Stateddl.SelectedValue & "</work_address_state>" _
& "<work_address_zip>" & Ziptxt.Text & "</work_address_zip>" _
& "<job_title>" & txtJobTitle.Text & "</job_title>" _
& "<mapi_charset>UTF8</mapi_charset>" _
& "<is_recurring>false</is_recurring>" _
& "<reminder_set>false</reminder_set>" _
& "<send_rich_info>false</send_rich_info>" _
& "<selected_mailing_address>2</selected_mailing_address>" _
& "</contact>"
address = New Uri("http://192.168.13.10/api/sguilford@muyo.net/mailbox/Public%20Folders/Contacts")
Webrequest = DirectCast(Net.WebRequest.Create(address), HttpWebRequest)
Webrequest.Credentials = New NetworkCredential("*************", "*****")
Dim data = New StringBuilder()
Dim byteData() As Byte
Dim reader As StreamReader
data.Append(HttpUtility.UrlEncode(post))
Webrequest.Method = "POST"
Webrequest.ProtocolVersion = HttpVersion.Version11
byteData = UTF8Encoding.UTF8.GetBytes(data.ToString())
Webrequest.ContentType = "application/scalix-properties"
Webrequest.ContentLength = byteData.Length
Dim postStream As Stream = Nothing
Try
postStream = Webrequest.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)
Finally
If Not postStream Is Nothing Then postStream.Close()
End Try
Try
Webresponse = DirectCast(Webrequest.GetResponse(), HttpWebResponse)
reader = New StreamReader(Webresponse.GetResponseStream())
lblError.Text = reader.ReadToEnd()
Finally
If Not Webresponse Is Nothing Then Webresponse.Close()
End Try

tenchi96
Posts: 15
Joined: Fri Dec 08, 2006 4:38 pm

Postby tenchi96 » Tue May 06, 2008 9:04 am

I checked the API logs and I noticed I was getting this message "M00013 error while parsing the provided XML data" not exactly sure what it means

gren
Scalix
Scalix
Posts: 264
Joined: Thu Mar 25, 2004 10:27 am
Contact:

Postby gren » Wed May 07, 2008 11:57 am

You might want to catch a network trace of port 80 traffic using wireshark or something similar to catch exactly what XML you are including in your request. You could then pass this through xmllint or something similar to validate it.

The M00013 error code is emitted if there is a SAXException thrown whilst parsing the XML. The most likely reason for this is that the XML is invalid. Perhaps there are some characters in the text which need to be encoded?

Regards,
Gren.

tenchi96
Posts: 15
Joined: Fri Dec 08, 2006 4:38 pm

Postby tenchi96 » Wed May 07, 2008 8:56 pm

While running wireshark I noticed It was erroring twice

The first at
postStream.Write(byteData, 0, byteData.Length)

POST /api/sguilford@muyo.net/mailbox/Public%20Folders/Contacts HTTP/1.1\r\n

HTTP/1.1 401 Unauthorized\r\n

i know my credentials are correct because I can browse to the same folder and put mu credentials in and the system authenticates correctly


Then at
Webresponse = DirectCast(Webrequest.GetResponse(), HttpWebResponse)

POST /api/sguilford@muyo.net/mailbox/Public%20Folders/Contacts HTTP/1.1\r\n

HTTP/1.1 400 Bad Request\r\n

Has anyone ever got the scalix api to communicate with VB 2005/2008

tenchi96
Posts: 15
Joined: Fri Dec 08, 2006 4:38 pm

Postby tenchi96 » Tue May 20, 2008 8:56 pm

Just wondering if anyone hsa gotten Scalix to wor with VB 2005/2008 still having problems???????????????????????


Return to “Third Party Integration”



Who is online

Users browsing this forum: No registered users and 2 guests