cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Community Champion
Community Champion

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
Community Champion
Community Champion

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
Community Champion
Community Champion

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

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?

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

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

 

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

does this mean I do not need to creat api?

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

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
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Check out the Power Apps Community Call for January 2021

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (9,540)