Cycle port API not working "None of the fields... were specified"

Solved
steve4
New here

Cycle port API not working "None of the fields... were specified"

I'm using Curl through PHP to try to cycle a port, I have done this according to the docs but it's not working.

 

Getting the error:  Array ( [0] => Error for /devices/{serial}/switch/ports/{portId}: None of the fields ('name', 'tags', 'enabled', 'poeEnabled', 'type', 'vlan', 'voiceVlan', 'allowedVlans', 'isolationEnabled', 'rstpEnabled', 'stpGuard', 'linkNegotiation', 'portScheduleId', 'udld', 'accessPolicyType', 'accessPolicyNumber', 'macAllowList', 'stickyMacAllowList', 'stickyMacAllowListLimit', 'stormControlEnabled', 'adaptivePolicyGroupId', 'peerSgtCapable', 'flexibleStackingEnabled', 'daiTrusted' or 'profile') were specified. ) )

 

According to the docs all I need to post is { "ports": [ "17" ]}

https://developer.cisco.com/meraki/api-latest/#!cycle-device-switch-ports

 

This is my code:

$json_data = '{ "ports": [ "17" ]}'; 
$headr = array();
$headr[] = 'Content-Type: application/json';
$headr[] = 'Accept: application/json';
$headr[] = 'X-Cisco-Meraki-API-Key:  '.$apikey;
 
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($curl, CURLOPT_POSTFIELDS, $json_data);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
$reply = curl_exec($curl);
1 Accepted Solution
yujiterada
Meraki Employee
Meraki Employee

The request should be a POST and not PUT.

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");

View solution in original post

6 Replies 6
rhbirkelund
Kind of a big deal
Kind of a big deal

Could it be that your $url statement is set somewhere else aswell, and it's that statement that's being used?

 

According to your error message, if failing on the endpoint ressource /devices/{serial}/switch/ports/{portId}, but the ressource for cycling the port is /devices/{serial}/switch/ports/cycle as you've also stated yourself.

 

So I'm assuming that $url is being set somewhere to /devices/{serial}/switch/ports/{portId}

 

I haven't worked with PHP for a long time, but I think it looks correct.

 

LinkedIn ::: https://blog.rhbirkelund.dk/

Like what you see? - Give a Kudo ## Did it answer your question? - Mark it as a Solution 🙂

All code examples are provided as is. Responsibility for Code execution lies solely your own.
steve4
New here

The URL is only set as https://api.meraki.com/api/v1/devices/{serial}/switch/ports/cycle

 

The response is strange.

Greenberet
Head in the Cloud

you are not changing the {serial} to any real serial number in the URL.

the URL should look like this https://api.meraki.com/api/v1/devices/Q2BX-XXXX-XXXX/switch/ports/cycle
just with the real serial number of your switch

steve4
New here

No it's there, I didn't want to display it in this forum.
it's in the format Q2GX-XXXX-XXXX

yujiterada
Meraki Employee
Meraki Employee

The request should be a POST and not PUT.

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");

steve4
New here

Yes that was it I missed that. Thank you!

Get notified when there are additional replies to this discussion.