Send netdisco-users mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.sourceforge.net/lists/listinfo/netdisco-users
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of netdisco-users digest..."
Today's Topics:

   1. Re: API Swagger (Robert Lewis)
--- Begin Message ---
I was able to figure out where I was mistaken in how I thought this would
work. I saw the new features

"Implementation of API authentication and Swagger-UI (pyro3d and ollyg)" in
2.042000 and assumed that mean that an API was available.

The API authentication worked as described. I needed to install a plugin in
order to retrieve information. If this isn’t correct please let me know but
the following is what I did. Thank you to ollyg and pyro3d for working on
Netdisco and the associated plugin.

I used the following command to get an api_key

curl -X POST \

 https://<netdiscoserver>/login \

 -H 'Accept: application/json' \

 -H 'Authorization: Basic <base64encoded username and password
username:password>' \

 -H 'Cache-Control: no-cache' \

 -H 'Connection: keep-alive' \

 -H 'Content-Type: application/json' \

 -H 'Host: <netdiscoserver>'\

 -c '<cookiefile>'


This returned the following.

{"api_key":”<api_key_is_here"}

I assumed after I retrieved the key that I had access to an API. I believe
this was incorrect. pyro3d has a REST API Plugin for Netdisco posted on
GitHub. https://github.com/pyro3d/netdisco-rest-api

I installed this plugin and then was able to use the cookie I generated
above to retrieve json from the REST API Plugin.

The following are the basic steps I used to setup up pyro3d's plugin.

To install the pyro3d's plugin I downloaded the files from github and put
them into an API folder under my App::NetdiscoX::Web::Plugin:: namespace.
For my server this ended up being

/usr/local/share/perl5/App/NetdiscoX/Web/Plugin/API/

The files in GitHub were named Device.pm and Node.pm. I renamed them based
on errors I received in my netdisco-web.log after finishing the plugin
setup and how I understood the documentation at
https://github.com/netdisco/netdisco/wiki/Web-Plugins Device.pm was renamed
to DEVICE.pm and Node.pm was NODEIP.pm .

/usr/local/share/perl5/App/NetdiscoX/Web/Plugin/API/NODEIP.pm

/usr/local/share/perl5/App/NetdiscoX/Web/Plugin/API/DEVICE.pm

After the plugin was installed I added the following to my deployment.yml
to enable the plugin.

extra_web_plugins:

 - X::API::NODEIP

 - X::API::DEVICE

I restarted netdisco-web to make sure the plugin was loaded.

In my web browser once authenticated to netdisco I went to

https://<netdiscoserver>/api/device/all and received back json with all of
my devices.

The following curl command then can retrieve this same information if I use
a cookie like I generated above.

curl -X GET \

 https://<netdiscoserver>/api/device/all \

 -H 'Accept: application/json' \

 -H 'Cache-Control: no-cache' \

 -H 'Connection: keep-alive' \

 -H 'Content-Type: application/json' \

 -H 'Host: <netdiscoserver>'\

 -b '<cookiefile>'


I hope this helps someone else.





On Wed, May 15, 2019 at 10:42 AM Robert Lewis <[email protected]>
wrote:

> Good morning,
>
> I was wondering if someone could point me to an example on how to use the
> API? I have been able to retrieve the api_key but I am unable to use it to
> retrieve anything.
>
> Does anyone have an example of querying the API they would be willing to
> share? When I load the http://netdisco/swagger-ui there is an error at
> the bottom saying 
> {"schemaValidationMessages":[{"level":"error","message":"Can't
> read from file https://netdisco.cgresd.net/swagger.json"}]} . I can view
> the file successfully.
>
> If I need to do more research please let me know.
>
> Thank you,
>
> --
> Robert Lewis
>


-- 
Robert Lewis

--- End Message ---
_______________________________________________
Netdisco mailing list - Digest Mode
[email protected]
https://lists.sourceforge.net/lists/listinfo/netdisco-users

Reply via email to