CUC Forums

« Back to CUPI Questions

415 - Unsupported Media Type Error on Pin Reset

Combination View Flat View Tree View
Threads [ Previous | Next ]
Showing 21 - 30 of 30 results.
of 2
As promised here is the function that I use to reset the Pins (it is in VB asp.net, but should be easily ported accross)

Function resetconnectionpassword(ByVal objectid As String, ByVal ucserver As String) As String
Dim req As WebRequest
Dim rsp As WebResponse
Dim xmltxt As String
Try
req = WebRequest.Create("https://" & ucserver & "/vmrest/users/" & objectid & "/credential/pin")
req.PreAuthenticate = True
req.Method = "PUT"
Dim xmlDoc As New XmlDocument
Dim xmlWriter As XmlTextWriter
req.ContentType = "application/xml"
req.Credentials = New NetworkCredential("Username", "Password")
xmltxt = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
xmltxt = xmltxt & "<Credential>"
xmltxt = xmltxt & "<Credentials>90210</Credentials>"
xmltxt = xmltxt & "<CredMustChange>true</CredMustChange> "
xmltxt = xmltxt & "<Locked>false</Locked> "
xmltxt = xmltxt & "</Credential>"
' MsgBox(xmltxt)
xmlDoc.LoadXml(xmltxt)
xmlWriter = New XmlTextWriter(req.GetRequestStream(), System.Text.Encoding.UTF8)
xmlDoc.WriteTo(xmlWriter)
xmlWriter.Close()
rsp = req.GetResponse()
Catch wex As WebException
If Not wex.Response Is Nothing Then
Dim errorResponse As HttpWebResponse = Nothing
Try
errorResponse = DirectCast(wex.Response, HttpWebResponse)
Return errorResponse.StatusCode & " - " & errorResponse.StatusDescription
Finally
If Not errorResponse Is Nothing Then errorResponse.Close()
End Try
End If
End Try
Return "200"
End Function

Simon,



Do you grab the user dynamically from a search function or did you just use the code as illustrated below?



-Andy



From: Cisco Developer Community Forums [mailto:cdicuser@developer.cisco.com]
Sent: Friday, November 11, 2011 4:15 AM
To: cdicuser@developer.cisco.com
Subject: New Message from Simon Granger in Cisco Unity Connection Provisioning Interface (CUPI) - CUPI Questions: RE: Re: New Message from Sascha Monteiro in Cisco Unity Connection Provisio



Simon Granger has created a new message in the forum "CUPI Questions":

--------------------------------------------------------------
As promised here is the function that I use to reset the Pins (it is in VB asp.net, but should be easily ported accross)

Function resetconnectionpassword(ByVal objectid As String, ByVal ucserver As String) As String
Dim req As WebRequest
Dim rsp As WebResponse
Dim xmltxt As String
Try
req = WebRequest.Create("https://" & ucserver & "/vmrest/users/" & objectid & "/credential/pin")
req.PreAuthenticate = True
req.Method = "PUT"
Dim xmlDoc As New XmlDocument
Dim xmlWriter As XmlTextWriter
req.ContentType = "application/xml"
req.Credentials = New NetworkCredential("Username", "Password")
xmltxt = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
xmltxt = xmltxt & "<Credential>"
xmltxt = xmltxt & "<Credentials>90210</Credentials>"
xmltxt = xmltxt & "<CredMustChange>true</CredMustChange> "
xmltxt = xmltxt & "<Locked>false</Locked> "
xmltxt = xmltxt & "</Credential>"
' MsgBox(xmltxt)
xmlDoc.LoadXml(xmltxt)
xmlWriter = New XmlTextWriter(req.GetRequestStream(), System.Text.Encoding.UTF8)
xmlDoc.WriteTo(xmlWriter)
xmlWriter.Close()
rsp = req.GetResponse()
Catch wex As WebException
If Not wex.Response Is Nothing Then
Dim errorResponse As HttpWebResponse = Nothing
Try
errorResponse = DirectCast(wex.Response, HttpWebResponse)
Return errorResponse.StatusCode & " - " & errorResponse.StatusDescription
Finally
If Not errorResponse Is Nothing Then errorResponse.Close()
End Try
End If
End Try
Return "200"
End Function
--
To respond to this post, please click the following link:

<http://developer.cisco.com/web/cupi/forums/-/message_boards/view_message/4735631>

or simply reply to this email.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 6619 (20111110) __________



The message was checked by ESET NOD32 Antivirus.



http://www.eset.com

I use this function to get the OBJECTID, It can either find the account by DTMFID or Alias

Function returnobjectid(ByVal ucserver As String, ByVal TelNo As String, ByVal objusername As String, ByVal searchbyusername As Boolean) As String
Try
Dim i As Integer
Dim req As WebRequest
Dim rsp As WebResponse
Dim result As String
Dim objectid As String = ""
If searchbyusername = True Then
req = WebRequest.Create("https://" & ucserver & "/vmrest/users?query=(alias%20is%20" & objusername & ")")
Else
req = WebRequest.Create("https://" & ucserver & "/vmrest/users?query=(DTMFAccessID%20is%20" & TelNo & ")")
End If
req.PreAuthenticate = True
req.Method = "get"
req.Credentials = New NetworkCredential("Username", "Password)
rsp = req.GetResponse()
Dim streamReader As New StreamReader(rsp.GetResponseStream())
result = streamReader.ReadToEnd()
streamReader.Close()
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
'Create the XML Document
m_xmld = New XmlDocument()
'Load the Xml file
m_xmld.LoadXml(result)
'Get the list of name nodes
m_nodelist = m_xmld.SelectNodes("/Users/User")

If m_nodelist.Count = 0 Then
Return "ZNo users mailbox found"
ElseIf m_nodelist.Count = 1 Then
'Loop through the nodes
For Each m_node In m_nodelist
For i = 0 To m_node.ChildNodes.Count - 1
'MsgBox(m_node.ChildNodes(i).Name.ToString)
If m_node.ChildNodes(i).Name.ToString.ToLower.Trim = "objectid" Then
objectid = m_node.ChildNodes.Item(i).InnerText
Exit For
End If
Next

If objectid = "" Then
Return "ZObject ID not found"
Else
Return objectid
End If
Next
Else
Return "ZTo Many Objects with the same number"
End If
m_xmld = Nothing
m_nodelist = Nothing
m_node = Nothing
Catch errorVariable As Exception
'Error trapping
Return "ZInternal Error: " & errorVariable.Message
End Try

Return "ZUnkown Error"
End Function

Simon,



Do you mind sending me your frontend page? How are you calling these functions.





From: Cisco Developer Community Forums [mailto:cdicuser@developer.cisco.com]
Sent: Friday, November 11, 2011 8:09 AM
To: cdicuser@developer.cisco.com
Subject: New Message from Simon Granger in Cisco Unity Connection Provisioning Interface (CUPI) - CUPI Questions: RE: Re: New Message from Sascha Monteiro in Cisco Unity Connection Provisio



Simon Granger has created a new message in the forum "CUPI Questions":

--------------------------------------------------------------
I use this function to get the OBJECTID, It can either find the account by DTMFID or Alias

Function returnobjectid(ByVal ucserver As String, ByVal TelNo As String, ByVal objusername As String, ByVal searchbyusername As Boolean) As String
Try
Dim i As Integer
Dim req As WebRequest
Dim rsp As WebResponse
Dim result As String
Dim objectid As String = ""
If searchbyusername = True Then
req = WebRequest.Create("https://" & ucserver & "/vmrest/users?query=(alias%20is%20" & objusername & ")")
Else
req = WebRequest.Create("https://" & ucserver & "/vmrest/users?query=(DTMFAccessID%20is%20" & TelNo & ")")
End If
req.PreAuthenticate = True
req.Method = "get"
req.Credentials = New NetworkCredential("Username", "Password)
rsp = req.GetResponse()
Dim streamReader As New StreamReader(rsp.GetResponseStream())
result = streamReader.ReadToEnd()
streamReader.Close()
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
'Create the XML Document
m_xmld = New XmlDocument()
'Load the Xml file
m_xmld.LoadXml(result)
'Get the list of name nodes
m_nodelist = m_xmld.SelectNodes("/Users/User")

If m_nodelist.Count = 0 Then
Return "ZNo users mailbox found"
ElseIf m_nodelist.Count = 1 Then
'Loop through the nodes
For Each m_node In m_nodelist
For i = 0 To m_node.ChildNodes.Count - 1
'MsgBox(m_node.ChildNodes(i).Name.ToString)
If m_node.ChildNodes(i).Name.ToString.ToLower.Trim = "objectid" Then
objectid = m_node.ChildNodes.Item(i).InnerText
Exit For
End If
Next

If objectid = "" Then
Return "ZObject ID not found"
Else
Return objectid
End If
Next
Else
Return "ZTo Many Objects with the same number"
End If
m_xmld = Nothing
m_nodelist = Nothing
m_node = Nothing
Catch errorVariable As Exception
'Error trapping
Return "ZInternal Error: " & errorVariable.Message
End Try

Return "ZUnkown Error"
End Function
--
To respond to this post, please click the following link:

<http://developer.cisco.com/web/cupi/forums/-/message_boards/view_message/4735909>

or simply reply to this email.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 6620 (20111111) __________



The message was checked by ESET NOD32 Antivirus.



http://www.eset.com

This is for asp.net and not classic ASP

Here is the functions that run it.
(If you do not have a asp.net developer application go to www.microsoft.com/express and download Visual Web Developer It's Free)

On the ASP.Net page add a button called button1 and a textbox called textbox1 and a label called label1

then the code behind is this

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

objectid = returnobjectid("CiscoUCserver", "", textbox1.text, True)
If objectid.Substring(0, 1).ToLower = "z" Then
Label1.Text = "Update Failed: " & objectid.Substring(1, objectid.Length - 1)
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
Else

'Reset the password
objectid = resetconnectionpassword(objectid, "CiscoUCserver")
If objectid.Length >= 3 Then
If objectid.Substring(0, 3) = "200" Then
Label1.Text = "Update Successful"
Label1.ForeColor = Drawing.Color.Black
Label1.Visible = True
Return True
Else
Label1.Text = "Update Failed: " & objectid
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
End If
End If
End If
End Sub

You will probably have to add the reference to this at the top
 

<font size="2" color="#0000ff"><font size="2" color="#0000ff">
Imports
</font></font><font size="2" color="#0000ff">
 
</font>
 System.IO
<font size="2" color="#0000ff"><font size="2" color="#0000ff">
Imports
</font></font><font size="2" color="#0000ff">
 
</font>
 System.Xml


 
This is for asp.net and not classic ASP

Here is the functions that run it.
(If you do not have a asp.net developer application go to www.microsoft.com/express and download Visual Web Developer It's Free)

On the ASP.Net page add a button called button1 and a textbox called textbox1 and a label called label1

then the code behind is this

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

objectid = returnobjectid("CiscoUCserver", "", textbox1.text, True)
If objectid.Substring(0, 1).ToLower = "z" Then
Label1.Text = "Update Failed: " & objectid.Substring(1, objectid.Length - 1)
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
Else

'Reset the password
objectid = resetconnectionpassword(objectid, "CiscoUCserver")
If objectid.Length >= 3 Then
If objectid.Substring(0, 3) = "200" Then
Label1.Text = "Update Successful"
Label1.ForeColor = Drawing.Color.Black
Label1.Visible = True
Return True
Else
Label1.Text = "Update Failed: " & objectid
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
End If
End If
End If
End Sub

It¿s not recognizing objectid? I wish I was proficient in VB.net.



From: Cisco Developer Community Forums [mailto:cdicuser@developer.cisco.com]
Sent: Friday, November 11, 2011 8:42 AM
To: cdicuser@developer.cisco.com
Subject: New Message from Simon Granger in Cisco Unity Connection Provisioning Interface (CUPI) - CUPI Questions: RE: Re: New Message from Sascha Monteiro in Cisco Unity Connection Provisio



Simon Granger has created a new message in the forum "CUPI Questions":

--------------------------------------------------------------
You will probably have to add the reference to this at the top


<font size="2" color="#0000ff"><font size="2" color="#0000ff">
Imports
</font></font><font size="2" color="#0000ff">

</font>
System.IO
<font size="2" color="#0000ff"><font size="2" color="#0000ff">
Imports
</font></font><font size="2" color="#0000ff">

</font>
System.Xml




This is for asp.net and not classic ASP

Here is the functions that run it.
(If you do not have a asp.net developer application go to www.microsoft.com/express and download Visual Web Developer It's Free)

On the ASP.Net page add a button called button1 and a textbox called textbox1 and a label called label1

then the code behind is this

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

objectid = returnobjectid("CiscoUCserver", "", textbox1.text, True)
If objectid.Substring(0, 1).ToLower = "z" Then
Label1.Text = "Update Failed: " & objectid.Substring(1, objectid.Length - 1)
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
Else

'Reset the password
objectid = resetconnectionpassword(objectid, "CiscoUCserver")
If objectid.Length >= 3 Then
If objectid.Substring(0, 3) = "200" Then
Label1.Text = "Update Successful"
Label1.ForeColor = Drawing.Color.Black
Label1.Visible = True
Return True
Else
Label1.Text = "Update Failed: " & objectid
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
End If
End If
End If
End Sub


--
To respond to this post, please click the following link:

<http://developer.cisco.com/web/cupi/forums/-/message_boards/view_message/4735956>

or simply reply to this email.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 6620 (20111111) __________



The message was checked by ESET NOD32 Antivirus.



http://www.eset.com

Zip up what you have, attach it to the post and I will take a look (Just remember to remove all passwords)

From: Cisco Developer Community Forums [mailto:cdicuser@developer.cisco.com]
Sent: 11 November 2011 13:50
To: cdicuser@developer.cisco.com
Subject: New Message from Andy Melick in Cisco Unity Connection Provisioning Interface (CUPI) - CUPI Questions: RE: New Message from Simon Granger in Cisco Unity Connection Provisioning I

Andy Melick has created a new message in the forum "CUPI Questions":
--------------------------------------------------------------
It¿s not recognizing objectid? I wish I was proficient in VB.net.



From: Cisco Developer Community Forums [mailto:cdicuser@developer.cisco.com]
Sent: Friday, November 11, 2011 8:42 AM
To: cdicuser@developer.cisco.com
Subject: New Message from Simon Granger in Cisco Unity Connection Provisioning Interface (CUPI) - CUPI Questions: RE: Re: New Message from Sascha Monteiro in Cisco Unity Connection Provisio



Simon Granger has created a new message in the forum "CUPI Questions":

--------------------------------------------------------------
You will probably have to add the reference to this at the top


<font size="2" color="#0000ff"><font size="2" color="#0000ff">
Imports
</font></font><font size="2" color="#0000ff">

</font>
System.IO
<font size="2" color="#0000ff"><font size="2" color="#0000ff">
Imports
</font></font><font size="2" color="#0000ff">

</font>
System.Xml




This is for asp.net and not classic ASP

Here is the functions that run it.
(If you do not have a asp.net developer application go to www.microsoft.com/express and download Visual Web Developer It's Free)

On the ASP.Net page add a button called button1 and a textbox called textbox1 and a label called label1

then the code behind is this

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

objectid = returnobjectid("CiscoUCserver", "", textbox1.text, True)
If objectid.Substring(0, 1).ToLower = "z" Then
Label1.Text = "Update Failed: " & objectid.Substring(1, objectid.Length - 1)
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
Else

'Reset the password
objectid = resetconnectionpassword(objectid, "CiscoUCserver")
If objectid.Length >= 3 Then
If objectid.Substring(0, 3) = "200" Then
Label1.Text = "Update Successful"
Label1.ForeColor = Drawing.Color.Black
Label1.Visible = True
Return True
Else
Label1.Text = "Update Failed: " & objectid
Label1.ForeColor = Drawing.Color.Red
Label1.Visible = True
Return False
End If
End If
End If
End Sub


--
To respond to this post, please click the following link:

<http://developer.cisco.com/web/cupi/forums/-/message_boards/view_message/4735956>

or simply reply to this email.



__________ Information from ESET NOD32 Antivirus, version of virus signature database 6620 (20111111) __________



The message was checked by ESET NOD32 Antivirus.



http://www.eset.com
--
To respond to this post, please click the following link:
<http://developer.cisco.com/web/cupi/forums/-/message_boards/view_message/4735976>
or simply reply to this email.

________________________________
Registered No. 755780 England
Registered Office: FM Insurance Company Limited
1 Windsor Dials, Windsor,
Berkshire, UK, SL4 1RS
Regulated by the Financial Services Authority.
VAT No. G.B.: 792 4276 02

Below is my classic ASP code. I know that I am very close with this... I still get an 415 media error when I try to process it. It works perfect if I change the PUT to a GET to retrieve the object. If someone could identify what I am doing wrong it would be greatly appropriated. On the same token if someone has a completed ASP.net project they are willing to share it give me a direction to run with in that manner as well.

Thanks,

-Andy


<script language="javascript" type="text/javascript" runat="server">

function Base64Encode(input) {

var base64Key = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var base64Pad = "=";
var result = "";
var length = input.length;
var i = 1;

for (i = 0; i < (length - 2); i += 3) {
result += base64Key.charAt(input.charCodeAt(i) >> 2);
result += base64Key.charAt(((input.charCodeAt(i) & 0x03) << 4) + (input.charCodeAt(i+1) >> 4));
result += base64Key.charAt(((input.charCodeAt(i+1) & 0x0f) << 2) + (input.charCodeAt(i+2)>> 6));
result += base64Key.charAt(input.charCodeAt(i+2) & 0x3f);
}

if (length%3) {
i = length - (length%3);
result += base64Key.charAt(input.charCodeAt(i) >> 2);
if ((length%3) == 2) {
result += base64Key.charAt(((input.charCodeAt(i) & 0x03) << 4) + (input.charCodeAt(i+1) >> 4));
result += base64Key.charAt((input.charCodeAt(i+1) & 0x0f) << 2);
result += base64Pad;
} else {
result += base64Key.charAt((input.charCodeAt(i) & 0x03) << 4);
result += base64Pad + base64Pad;
}
}

return result;
}
</script>

<%
sPassword = "12345"
sUserObjectId = "edb8da2b-74b4-43d4-9380-ef208f950dbd"
sUMServerToResetAgainst = "10.2.201.xx"
username = "cupiuser"
password = "xxxxxxxxxx"


Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")

objXML.Open "PUT", "http://" & sUMServerToResetAgainst & "/vmrest/users/" & sUserObjectId & "/credential/pin", False, "cupiuser", "xxxxxxxxxx"
objXML.setRequestHeader "Authorization", "Basic " & Base64Encode(username & ":" & password)
objXML.setRequestHeader "ContentType", "application/xml"
objXML.setRequestHeader "Content-lenght", len(sXml)
objXML.setOption(2) = 13056

'On Error Resume Next

xmltxt = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
xmltxt = xmltxt & "<Credential>"
xmltxt = xmltxt & "<Credentials>90210</Credentials>"
xmltxt = xmltxt & "<CredMustChange>true</CredMustChange> "
xmltxt = xmltxt & "<Locked>false</Locked> "
xmltxt = xmltxt & "</Credential>"



objXML.send xmltxt




ResponseXml = objXML.ResponseText
Response.ContentType = "application/xml"
response.write responseXML
%>

Hi Andy -

I encountered this same issue when working on this for our internal tools. I got it working by breaking the request into two separate requests. In the first PUT request, I set the parameters and then set the password or PIN. However, the format of the XML that is required is slighyly different. Try this:

First request, send

xmltxt = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
xmltxt = xmltxt & "<Password>"
xmltxt = xmltxt & "<CredMustChange>true</CredMustChange> "
xmltxt = xmltxt & "<Locked>false</Locked> "
xmltxt = xmltxt & "</Password>"

Then send a second request to the same URI with:

xmltxt = "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "UTF-8" & Chr(34) & "?>"
xmltxt = xmltxt & "<Password>"
xmltxt = xmltxt & "<Credentials>90210</Credentials>"
xmltxt = xmltxt & "</Password>"

Hopefully this will work for you.

- David

Showing 21 - 30 of 30 results.
of 2