Plantronics + Polycom. Now together as Poly Logo

help with REST API for G7500

SOLVED
Regular Advisor

help with REST API for G7500

Hello Steffen,

 

I am trying to use the REST API and PowerShell to execute a reboot command against a G7500.  Your CURL examples work, and I have tried to adapt the Trio examples but keep getting errors.  Can you help point me in the right direction?  This is important for us as we have over 100 of these systems deployed and are looking to script out management.  Thanks!

$body = "{`"action`": `"reboot`"}";

$password = "mypassword" | ConvertTo-SecureString -AsPlainText -Force

$cred = New-Object System.Management.Automation.PSCredential("admin",$password)

$url = "https://172.1.16.232/rest/system/reboot";

Invoke-WebRequest $url -Method Post -ContentType "application/json" -Credential $cred -body $body



Invoke-WebRequest : Forbidden
The server understood the request, but is refusing to fulfill it
You can get technical details here.
Please continue your visit at our home page.
At line:1 char:1
+ Invoke-WebRequest $url -Method Post -ContentType "application/json" - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
Message 1 of 7
1 ACCEPTED SOLUTION

Accepted Solutions
Regular Advisor

Re: help with REST API for G7500

For those looking to use PowerShell in the future, here is an adapted example for the G7500.  I do not know why the Trio REST method with a single line does not work with the G7500, as that would be more efficient (passing the $credentials in one shot).  Converting the CURL commands exactly to Invoke-WebRequest seemed fine, however.

 

#BEGIN POWERSHELL SCRIPT FOR POLY G7500 REST command
$password = "myPassword" #your password
$IP = "172.16.200.200" #IP of unit

#URL to make new session
$sessionURL = ("https://" + $IP + "/rest/session");
#Command to make new session
$sessionBody = "{`"user`": `"admin`",`"password`": `"" + $password + "`"}"

#URL to issue reboot
$rebootURL = ("https://" + $IP + "/rest/system/reboot");
#Command to issue reboot
$rebootBody = "{`"action`": `"reboot`"}"


# disable self signed certificate check
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore()
# End self signed certificate commands

Invoke-WebRequest $sessionURL -ContentType "application/json" -Method Post -body $sessionBody -SessionVariable sess;
Invoke-WebRequest $rebootURL -ContentType "application/json" -Method Post -WebSession $sess -Body $rebootBody

  

View solution in original post

Message 7 of 7
6 REPLIES 6
Polycom Employee & Community Manager

Re: help with REST API for G7500

Hello @philliplyle 

 

other community users may get put off if a question is raised to a specific user instead of a larger audience.

 

In addition, I am unable to answer all posts and cannot provide free support via the community. If an issue is urgent please work with our support team instead.

 

Looking at the REST API >here< from the Video FAQ and a reboot simply is:

curl -b cookies.txt -c cookies.txt -X POST -d "{\"user\": \"admin\",\"password\": \"123\"}" -H "Content-Type: application/json" -k https://10.252.149.104/rest/session
curl -b cookies.txt -c cookies.txt -H "Content-Type: application/JSON" -k https://10.252.149.104/rest/system/reboot -d "{\"action\": \"reboot\"}"

This is for CURL from a MS-Dos command line and not power shell as outlined in the above FAQ article.

 

Best regards

 

Steffen Baier

----------------
The title Polycom Employee & Community Manager is a community setting and does not reflect my role. I am just a simple volunteer in the community like everybody else. My official "day" Job is 3rd Level support at Poly but I am unable to provide official support via the community.

----------------

Notice: This community forum is not an official Poly support resource, thus responses from Poly employees, partners, and customers alike are best-effort in attempts to share learned knowledge. If you need immediate and/or official assistance please open a service ticket through your proper support channels.
Please also ensure you always check the VoIP , Video Endpoint , Skype for Business , PSTN or RPM FAQ's
Message 2 of 7
Regular Advisor

Re: help with REST API for G7500

Yes, that's why I said "I have tried to adapt your Trio PowerShell examples".


Okay, I will try the long and arduous Support process.

 

Message 3 of 7
Polycom Employee & Community Manager

Re: help with REST API for G7500

Hello @philliplyle 

 

I replied to your post within 6 minutes outside of my working hours in my personal time with a working solution to reboot 1x Studio X or G7500.

 

Adopting my working solution to 100x endpoints should not take more than 10 minutes of copying and pasting the relevant IP addresses.

 

Spending a bit longer may find an easier solution but the above using CURL in an MS-DOS window or on a Linux box should not require you to contact support.

 

I doubt our support team would provide you with a script as well as this is not part of our job.

 

I created and shared my own found solution as I am an enthusiast like others and have been in situations where a customer needed to automate this for thousands of devices.

 

Please simply look at my working example 1st.

 

Best regards

 

Steffen Baier

----------------
The title Polycom Employee & Community Manager is a community setting and does not reflect my role. I am just a simple volunteer in the community like everybody else. My official "day" Job is 3rd Level support at Poly but I am unable to provide official support via the community.

----------------

Notice: This community forum is not an official Poly support resource, thus responses from Poly employees, partners, and customers alike are best-effort in attempts to share learned knowledge. If you need immediate and/or official assistance please open a service ticket through your proper support channels.
Please also ensure you always check the VoIP , Video Endpoint , Skype for Business , PSTN or RPM FAQ's
Message 4 of 7
Regular Advisor

Re: help with REST API for G7500

Yes, as I already wrote Steffan - "I have tried adapting your examples".  This is why I mentioned you specifically - because they are your examples.  So saying I should refer to your examples is not helpful.

 

No, they do not work on the G7500.  Why did you tell me to contact support and then now tell me that they will likely not help?  I would suggest not responding at all in the future, as your responses often have an attitude that puts off customers.

 

 

Message 5 of 7
Polycom Employee & Community Manager

Re: help with REST API for G7500

 Hello @philliplyle 

 

I will respect your wishes and will never reply to another of your posts after this. Please be aware that English is not my 1st language but that should not matter regarding your offputting reply comment.

 

We are here within the Video Section.

 

The Video FAQ contains a Rest API post by myself >here< and in addition the Poly VideoOS REST API Reference Guide >here< can be consulted. This is why I refer to this post with examples as this has been tested and works.

 

You already confirmed my CURL examples work in your 1st initial post.

 

The G7500 and Studio X use a different format aka you need to get a session cookie 1st prior to communicating further to issue the reset command.

 

You have not posted any logs of using the Video FAQ G7500/Studio X Curl solution so others could comment.

 

The Poly Trio, VVX, or CCX phones use a different approach than the above that is why posted both CURL and Power Shell examples.

 

I explained the official way of getting support and in my last reply explained that support most likely will not be able to help as writing scripts is not part of our day job.

 

Poly offers many managing solutions for our different endpoints and/or our professional service team can be consulted for anything outside of this. All of this may involve a financial cost.

 

A final goodbye

 

Steffen Baier

----------------
The title Polycom Employee & Community Manager is a community setting and does not reflect my role. I am just a simple volunteer in the community like everybody else. My official "day" Job is 3rd Level support at Poly but I am unable to provide official support via the community.

----------------

Notice: This community forum is not an official Poly support resource, thus responses from Poly employees, partners, and customers alike are best-effort in attempts to share learned knowledge. If you need immediate and/or official assistance please open a service ticket through your proper support channels.
Please also ensure you always check the VoIP , Video Endpoint , Skype for Business , PSTN or RPM FAQ's
Message 6 of 7
Regular Advisor

Re: help with REST API for G7500

For those looking to use PowerShell in the future, here is an adapted example for the G7500.  I do not know why the Trio REST method with a single line does not work with the G7500, as that would be more efficient (passing the $credentials in one shot).  Converting the CURL commands exactly to Invoke-WebRequest seemed fine, however.

 

#BEGIN POWERSHELL SCRIPT FOR POLY G7500 REST command
$password = "myPassword" #your password
$IP = "172.16.200.200" #IP of unit

#URL to make new session
$sessionURL = ("https://" + $IP + "/rest/session");
#Command to make new session
$sessionBody = "{`"user`": `"admin`",`"password`": `"" + $password + "`"}"

#URL to issue reboot
$rebootURL = ("https://" + $IP + "/rest/system/reboot");
#Command to issue reboot
$rebootBody = "{`"action`": `"reboot`"}"


# disable self signed certificate check
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
    using System;
    using System.Net;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    public class ServerCertificateValidationCallback
    {
        public static void Ignore()
        {
            if(ServicePointManager.ServerCertificateValidationCallback ==null)
            {
                ServicePointManager.ServerCertificateValidationCallback += 
                    delegate
                    (
                        Object obj, 
                        X509Certificate certificate, 
                        X509Chain chain, 
                        SslPolicyErrors errors
                    )
                    {
                        return true;
                    };
            }
        }
    }
"@
    Add-Type $certCallback
 }
[ServerCertificateValidationCallback]::Ignore()
# End self signed certificate commands

Invoke-WebRequest $sessionURL -ContentType "application/json" -Method Post -body $sessionBody -SessionVariable sess;
Invoke-WebRequest $rebootURL -ContentType "application/json" -Method Post -WebSession $sess -Body $rebootBody

  

View solution in original post

Message 7 of 7