Restarting a Phone via REST API

23 views
Skip to first unread message

kskla...@gmail.com

unread,
Sep 14, 2018, 1:45:17 PM9/14/18
to sipxcom-users
Hello there,

I'm currently running server version 17.04.

I'm attempting to restart a specific phone via the rest api. But I'm getting a 500/405 error when I call the api endpoint.

Here's my code (this is in python 3):

import requests

auth
= requests.auth.HTTPDigestAuth('username','password')

response
= requests.put('http://server_ip_address/sipxconfig/api/phones/phone_mac_address/sendProfiles/restart', auth=auth, verify=False')

print('
%s - %s' % (response.status_code, response.reason))
print(response.text)

And I get the following output:

'500 - Server Error'
'javax.ws.rs.ClientErrorException: HTTP 405 Method Not Allowed'

Can anyone tell me what I'm doing wrong?

Thanks!

Mircea Carasel

unread,
Sep 14, 2018, 1:48:57 PM9/14/18
to kskla...@gmail.com, sipxcom-users
Hi,

You are doing HTTP  PUT  method, try with POST

Mircea

--
You received this message because you are subscribed to the Google Groups "sipxcom-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sipxcom-user...@googlegroups.com.
To post to this group, send email to sipxco...@googlegroups.com.
Visit this group at https://groups.google.com/group/sipxcom-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/sipxcom-users/7e408f01-5141-4357-ba5a-d495fbdeab0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kskla...@gmail.com

unread,
Sep 14, 2018, 2:04:21 PM9/14/18
to sipxcom-users
Hi Mircea,

Unfortunately I get the same output regardless of the HTTP method I use. I also realize I made a few syntax mistakes in the code of my original question, and these are not present in my actual code.

Thanks!

Mircea Carasel

unread,
Sep 14, 2018, 2:19:27 PM9/14/18
to kskla...@gmail.com, sipxcom-users
The right method is PUT (I checked the code), and the sintax is  sendProfile/restart

If still does not work, please attach /var/log/sipxpbx/sipxconfig. log

Mircea

kskla...@gmail.com

unread,
Sep 14, 2018, 3:13:42 PM9/14/18
to sipxcom-users
Hi Mircea,

Still not working. Check out the relevant section of the log below.

"2018-09-14T19:07:16.585000Z":2971:JAVA:WARNING:server_fqdn:qtp1030903484-20:00000000:LoggerListener:"Authentication event AuthenticationSuccessEvent: username; details: org.sipfoundry.sipxconfig.security.SipxAuthenticationDetails@166c8: RemoteIpAddress: ip_of_client_sending_request; SessionId: 1ackxo4zhtnz5fj0yl6exthb4"
"2018-09-14T19:07:16.587000Z":2972:JAVA:INFO:server_fqdn:qtp1030903484-20:00000000:LoggingInInterceptor:"Inbound Message\n----------------------------\nID: 87\nAddress: http://sipx_server_ip/sipxconfig/api/phones/0004f248a519/sendProfile/restart\nHttp-Method: GET\nContent-Type: \nHeaders: {Accept=[*/*], accept-encoding=[gzip, deflate], Authorization=[Digest username=\"username\", realm=\"sip_fqdn\", nonce=\"MTUzNjk1MjA0NjUwNzo0ZjRiNTY5NmM5YWIyYzdjNTQwNTViZmFkZGQzNjI2Nw==\", uri=\"/sipxconfig/api/phones/0004f248a519/sendProfile/restart\", response=\"cb1c69723f031c131ca62b6f9f8a2d3b\", qop=\"auth\", nc=00000001, cnonce=\"e992c904797b78c8\"], connection=[keep-alive], Content-Type=[null], Cookie=[JSESSIONID=1ackxo4zhtnz5fj0yl6exthb4], Host=[sipx_server_ip], User-Agent=[python-requests/2.18.4], X-Forwarded-For=[ip_of_client_sending_request], X-Forwarded-Host=[sipx_server_ip], X-Forwarded-Server=[server_fqdn]}\n--------------------------------------"
"2018-09-14T19:07:16.588000Z":2973:JAVA:WARNING:server_fqdn:qtp1030903484-20:00000000:JAXRSUtils:"No operation matching request path \"/sipxconfig/api/phones/0004f248a519/sendProfile/restart\" is found, Relative Path: /0004f248a519/sendProfile/restart, HTTP Method: GET, ContentType: */*, Accept: */*,. Please enable FINE/TRACE log level for more details."
"2018-09-14T19:07:16.592000Z":2974:JAVA:INFO:server_fqdn:qtp1030903484-20:00000000:LoggingOutInterceptor:"Outbound Message\n---------------------------\nID: 87\nResponse-Code: 500\nContent-Type: text/xml\nHeaders: {Content-Type=[text/xml], Date=[Fri, 14 Sep 2018 19:07:16 GMT]}\nPayload: javax.ws.rs.ClientErrorException: HTTP 405 Method Not Allowed\n--------------------------------------"

Thank you so much for the help!

kskla...@gmail.com

unread,
Sep 14, 2018, 3:22:10 PM9/14/18
to sipxcom-users
Looking at the logs, regardless of which HTTP method I use it shows up in the logs as an HTTP GET. Perhaps thats the issue?

Mircea Carasel

unread,
Sep 14, 2018, 3:25:57 PM9/14/18
to kskla...@gmail.com, sipxcom-users
Are you sure you are doing HTTP PUT?

From the logs I see you do GET.

"No operation matching request path \"/sipxconfig/api/phones/0004f248a519/sendProfile/restart\" is found, Relative Path: /0004f248a519/sendProfile/restart, HTTP Method: GET, ContentType: */*, Accept: */*,. Please enable FINE/TRACE log level for more details."

Mircea Carasel

unread,
Sep 14, 2018, 3:26:56 PM9/14/18
to kskla...@gmail.com, sipxcom-users
Yes, you are doing GET instead of PUT

Mircea

kskla...@gmail.com

unread,
Sep 14, 2018, 3:51:20 PM9/14/18
to sipxcom-users
Mircea

Check this out. I ran a debug on my request code. It looks like I'm getting a redirection which would explain why everything looks like a get.

DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): sipx_server_fqdn
send: b'PUT /sipxconfig/api/phones/0004f248a519/sendProfile/restart HTTP/1.1\r\nHost: sipx_server_fqdn\r\nUser-Agent: python-requests/2.18.4\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n'
reply: 'HTTP/1.1 302 Found\r\n'

DEBUG:urllib3.connectionpool:http://sipx_server_fqdn:80 "PUT /sipxconfig/api/phones/phonemac/sendProfile/restart HTTP/1.1" 302 335

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): sipx_server_fqdn
/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
header: Date header: Server header: Location header: Content-Length header: Connection header: Content-Type send: b'GET /sipxconfig/api/phones/phonemac/sendProfile/restart HTTP/1.1\r\nHost: sipx_server_fqdn\r\nUser-Agent: python-requests/2.18.4\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'
reply: 'HTTP/1.1 401 An Authentication object was not found in the SecurityContext\r\n'

DEBUG:urllib3.connectionpool:https://sipx_server_fqdn:443 "GET /sipxconfig/api/phones/phonemac/sendProfile/restart HTTP/1.1" 401 442

DEBUG:urllib3.connectionpool:Resetting dropped connection: sipx_server_fqdn
/usr/local/lib/python3.6/site-packages/urllib3/connectionpool.py:858: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
  InsecureRequestWarning)
header: Date header: Server header: Access-Control-Allow-Credentials header: Access-Control-Allow-Methods header: Access-Control-Max-Age header: Access-Control-Allow-Headers header: WWW-Authenticate header: Content-Type header: Cache-Control header: Content-Length header: Set-Cookie header: Connection send: b'GET /sipxconfig/api/phones/phonemac/sendProfile/restart HTTP/1.1\r\nHost: sipx_server_fqdn\r\nUser-Agent: python-requests/2.18.4\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nCookie: JSESSIONID=iv8ovrwvt1zfda9alm39kufc\r\nAuthorization: Digest username="username", realm="sip_fqdn", nonce="MTUzNjk1NDEwMDY5NzoyYzc1YjYxMDc3NDIwOTk0NDk1Yjg5ZWMwZWE5OGI3MA==", uri="/sipxconfig/api/phones/phonemac/sendProfile/restart", response="0a02e42187c4bb33d57be4838635027f", qop="auth", nc=00000001, cnonce="1ccc29d2e521b727"\r\n\r\n'
reply: 'HTTP/1.1 500 Server Error\r\n'

Mircea Carasel

unread,
Sep 14, 2018, 4:03:23 PM9/14/18
to kskla...@gmail.com, sipxcom-users
Maybe because your python agent does not like the certificate, which is not trusted.
I also see :
reply: 'HTTP/1.1 401 An Authentication object was not found in the SecurityContext\r\n

Which is authentication error
So looks like a client side problem

Mircea

Reply all
Reply to author
Forward
0 new messages