Usage of web services nodes to connect swagger auth-key API

Hi all.

I need to create a massive quantity of records using a swagger API 2.0 with api-key from an excel file as datas source. I tried with some examples and the OPS_KNIME_1.4 without success. To test, i am working with http://petstore.swagger.io/. Anyone can help me? Also, i don't know if i must convert each excel row in json (i already do) or another way to adjust.

Thanks!

Hi,

I believe the nodes used in the OPS_KNIME_1.4 workflow are outdated. The Swagger API is now on version 2 and those nodes/examples have not been updated for more than 1 year now. I believe they still refer to the 1.x specifications and this is why the sample workflow doesn't work as expected.

You can still use a RESTful service based on the the Swagger API through the REST nodes part of REST Web Services (KNIME Labs) or the REST Nodes (Community Nodes), even though it is not so automatic. You will have to do some manual work though.

For example, depending on your service specifications, to add a record you can use the POST node and pass to it a JSON representation of the content you intend to add.

In the case of the demo Petstore on Swagger, you can place a POST request to add a new pet to the store with a body that looks like this:

{
  "id": 0,
  "category": {
    "id": 0,
    "name": "string"
  },
  "name": "fishy",
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}

Which adds a pet named "fishy" to the store. The POST request is placed to the URL:

http://petstore.swagger.io/v2/pet/

as described in sample store documentation. It works very similarly for other requests.

Hope this puts you on the right track. Give it a try and post again here if it doesn't work.

Cheers,
Marco.

Thanks Marco.

Great help. Do you have a sample dame to do so? Sorry for disturb.

I quickly put one together. It shows a GET as well as a POST to the demo Swagger service, followed by another GET to check that the new entry was created correctly.

Cheers,
Marco.

Awesome, let me try.

Thanks a lot.

Sorry, how i can import this file? I have knime 3.1.2 and i don't know how proceed. i tried compressing and importing and doesn't work. 

Solved, please omit my question :)

Great, thank you so much, great example!

Kudos for you.

Any way to set an api-key or static auth-key?

Ok, I am not that much of a Swagger expert and this is more a Swagger question than a KNIME one, but from the API documentation I understand you can pass the api-key directly in the header of the HTTP request.

Just go to the Request Headers tab in the configuration dialogue of each node (e.g. GET) and add an header element looking like this:

Header Key: api-key
Header Value: <your api key>
Value type: constant

As an alternative I understand that Basic authentication should also work (see the Authentication tab).

Cheers,
Marco.