cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Meneghino
Level 10

Swagger file definiton for object/array response

I have a Swagger file for fetching exchange rates, and everything works fine except that I do not know what to do with the Response section.  The issue is with the "rates" piece: the number of items and the list of currencies is variable.

 

A sample response is something like this, which is an object or array I think (I am not a JSON expert):

{
  "base": "EUR",
  "date": "2016-01-12",
  "rates": {
    "RUB": 82.69,
    "SGD": 1.557,
    "USD": 1.0836
  }
}

 

The current response section I have actually returns both "base" and "date" but gives an empty table for "rates":

 

   "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "title": "The response of the api.",
              "type": "object",
              "properties":{
                "base":{
                  "type": "string"
                },
                "date":{
                  "type": "string"
                },
                "rates":{
                  "type": "object"
                }
              }
             }
}

 

Any help would be really appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Meneghino
Level 10

Re: Swagger file definiton for object/array response

I have found the below solution (and I show the full swagger if anyone needs to fetch European Central Bank exchange rates).

The only problem is that I am limited to currencies I define in the swagger, and input/hints as to how to make this work with any list of currencies would be welcome.

 

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Fixer"
  },
  "host": "api.fixer.io",
  "paths": {
    "/{FXdate}": {
      "get": {
        "description": "Fetches historical FX rates from fixer.io",
        "operationId": "Run",
        "parameters": [
          {
            "name": "FXdate",
            "in": "path",
            "required": true,
            "description": "FX date in yyyy-mm-dd format",
            "type": "string"
          },
          {
            "name": "base",
            "in": "query",
            "required": true,
            "description": "ISO symbol of base currency",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "title": "The response of the api.",
              "type": "object",
              "properties":{
                "base":{
                  "type": "string"
                },
                "date":{
                  "type": "string"
                },
                "rates":{
                  "type": "object",
                  "properties":{
                    "USD":{
                      "type": "number",
                      "format": "double"
                    },
                    "EUR":{
                      "type": "number",
                      "format": "double"
                    },
                    "GBP":{
                      "type": "number",
                      "format": "double"
                    },
                    "RUB":{
                      "type": "number",
                      "format": "double"
                    },
                    "CHF":{
                      "type": "number",
                      "format": "double"
                    },
                    "BRL":{
                      "type": "number",
                      "format": "double"
                    },
                    "CZK":{
                      "type": "number",
                      "format": "double"
                    },
                    "HKD":{
                      "type": "number",
                      "format": "double"
                    },
                    "SGD":{
                      "type": "number",
                      "format": "double"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

View solution in original post

6 REPLIES 6
Meneghino
Level 10

Re: Swagger file definiton for object/array response

I have found the below solution (and I show the full swagger if anyone needs to fetch European Central Bank exchange rates).

The only problem is that I am limited to currencies I define in the swagger, and input/hints as to how to make this work with any list of currencies would be welcome.

 

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Fixer"
  },
  "host": "api.fixer.io",
  "paths": {
    "/{FXdate}": {
      "get": {
        "description": "Fetches historical FX rates from fixer.io",
        "operationId": "Run",
        "parameters": [
          {
            "name": "FXdate",
            "in": "path",
            "required": true,
            "description": "FX date in yyyy-mm-dd format",
            "type": "string"
          },
          {
            "name": "base",
            "in": "query",
            "required": true,
            "description": "ISO symbol of base currency",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "schema": {
              "title": "The response of the api.",
              "type": "object",
              "properties":{
                "base":{
                  "type": "string"
                },
                "date":{
                  "type": "string"
                },
                "rates":{
                  "type": "object",
                  "properties":{
                    "USD":{
                      "type": "number",
                      "format": "double"
                    },
                    "EUR":{
                      "type": "number",
                      "format": "double"
                    },
                    "GBP":{
                      "type": "number",
                      "format": "double"
                    },
                    "RUB":{
                      "type": "number",
                      "format": "double"
                    },
                    "CHF":{
                      "type": "number",
                      "format": "double"
                    },
                    "BRL":{
                      "type": "number",
                      "format": "double"
                    },
                    "CZK":{
                      "type": "number",
                      "format": "double"
                    },
                    "HKD":{
                      "type": "number",
                      "format": "double"
                    },
                    "SGD":{
                      "type": "number",
                      "format": "double"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

View solution in original post

Re: Swagger file definiton for object/array response

Hi this is cool!

So in this file I just need to put EU "paths": {
    "/{FXdate}": {

URL and it should return me the current live rates in powerapps right?

Meneghino
Level 10

Re: Swagger file definiton for object/array response

No, you need to create a custom api by uploading the swagger:

https://powerapps.microsoft.com/en-us/tutorials/register-custom-api/

 

Meneghino
Level 10

Re: Swagger file definiton for object/array response

You need to copy/paste the swagger in notepad or something, save as txt then change the extension to .json

Then you can upload as a custom connection file

Re: Swagger file definiton for object/array response

does this mean I do not need to creat api?

 or shall I first create api, publish and then add swagger?

Meneghino
Level 10

Re: Swagger file definiton for object/array response

The steps are all described here:

https://powerapps.microsoft.com/en-us/tutorials/register-custom-api/#register-a-custom-api

 

Please be specific is what is not clear

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,262)