How to post an API key on a header with the post() method using Groovy?
I'm trying to write a script in Groovy that makes an API request to check the status of VPN tunnels. I've been trying the implement the post() method from the HTTP library to update the header of the url with the API key. I keep running into an error "no signature on method". This is my code so far.
import com.santaba.agent.groovyapi.http.*;
ip = <span style="border-bottom-style:none;border-bottom-width:0px;border-left-style:none;border-left-width:0px;border-right-style:none;border-right-width:0px;border-top-style:none;border-top-width:0px;font-family:inherit;font-size:100%;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;vertical-align:baseline;">"api-mp.meraki.com"</span>;
httpClient = HTTP.open(ip, 443);
url = <span style="border-bottom-style:none;border-bottom-width:0px;border-left-style:none;border-left-width:0px;border-right-style:none;border-right-width:0px;border-top-style:none;border-top-width:0px;font-family:inherit;font-size:100%;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;vertical-align:baseline;">"https://"</span>+ip+<span style="border-bottom-style:none;border-bottom-width:0px;border-left-style:none;border-left-width:0px;border-right-style:none;border-right-width:0px;border-top-style:none;border-top-width:0px;font-family:inherit;font-size:100%;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;vertical-align:baseline;">"/api/v1/organizations/999999/appliance/vpn/statuses"</span>;
def postResponse = httpClient.post(url,[<span style="border-bottom-style:none;border-bottom-width:0px;border-left-style:none;border-left-width:0px;border-right-style:none;border-right-width:0px;border-top-style:none;border-top-width:0px;font-family:inherit;font-size:100%;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;vertical-align:baseline;">"X-Cisco-Meraki-API-Key"</span>:<span style="border-bottom-style:none;border-bottom-width:0px;border-left-style:none;border-left-width:0px;border-right-style:none;border-right-width:0px;border-top-style:none;border-top-width:0px;font-family:inherit;font-size:100%;font-style:inherit;font-variant:inherit;font-weight:inherit;line-height:inherit;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:0px;padding-left:0px;padding-right:0px;padding-top:0px;vertical-align:baseline;">"ApiKey"</span>]);
I just followed the example from this tutorial: https://www.logicmonitor.com/support/terminology-syntax/scripting-support/access-a-website-from-groovy
I'm wondering if I'm getting the error because I'm not inserting a payload in my method. But I don't have a payload... I'm just trying to update the header.
SmokinIndo
2 comments
LM User
From the support docs:
It appears you want to pass a blank payload and add the X-Cisco-Meraki-API-Key header. In that case, you'll need to include a blank payload string:
I haven't checked this, so it'd remain to be verified, but this is at least how the docs indicate it should work. I've also reordered it to be more standard and to fetch the api key from the device property (assuming you're running this as a scripted LogicModule).
Vitor_Santos
Maybe it's easier for you to use one the already existent datasource(s) that queries Cisco Meraki API & from there build the query you actually want
You can refer to the code of the DS below for example:
This is usually what I do if I want to extend the capabilities of certain monitoring... I always check if they didn't did the 'connection' already. That way I don't need to loose time understanding how to do it :)/emoticons/smile@2x.png 2x" title=":)" width="20" />