PowerApps: Cryptocurrency exchange rate API custom connector

As an example of what can be done with custom APIs in PowerApps, I created a connector to fetch the exchange rates of various cryptocurrencies from an open source.  You will be able to use the rates in formulas in PowerApps.  This approach is very flexible and can be used with almost any other API.  All you need is to edit the Swagger file below to match the output of your chosen API.The data returned by our chosen sample API can be looked at by navigating to this URL in your browser:

https://api.cryptonator.com/api/ticker/btc-usd

Basically you substitute the last element of the path for any pair of currencies to obtain their current exchange rate.

By looking at the structure of what is returned in your browser, you can create the following Swagger:

swagger: '2.0'
info:
 version: 1.0.0
 title: Cryptonator
host: api.cryptonator.com
paths:
 '/api/ticker/{tickers}':
  get:
   description: Fetches rates from cryptonator.com
   operationId: Run
   parameters:
    - name: tickers
      in: path
      required: true
      description: Tickers in xxx-xxx format
      type: string
   responses:
    '200':
     description: Successful response
     schema:
      title: The response of the api.
      type: object
      properties:
       ticker:
        type: object
        properties:
         base:
          type: string
         target:
          type: string
         price:
          type: string
         volume:
          type: string
         change:
          type: string
       timestamp:
        type: number
        format: integer
       success:
        type: boolean
       error:
        type: string

You can test the Swagger file by navigating to the Swagger editor site, pasting the above Swagger code instead of the sample in the left pane, and then pressing ‘Try it out’ in the right pane of the Swagger editor.

Once successfully tested (and edited if necessary), you can download the JSON file from the File menu of the Swagger editor.

Then log in to PowerApps and go to the ‘Custom connectors’ tab and create a new connector from an OpenAPI file (basically Swagger=OpenAPI), like this:

Give the connector the title Cryptonator to the connector and choose the JSON file that you saved in the previous steps.  After you press Continue, you should see this:

Add optional information on colour and description if you like, then press continue to see the following step:

No authentication is needed, so press Continue to see this

Simply press Create connector at the top of the screen and the connector should be created.  Now select the Test step to see this:

Press the + New connection button and a new connection should be created.  Unfortunately you will probably be taken to the Connections tab.  In order to test the Connector, go back to Custom connectors and choose to edit Crytonator, then select the Test step again to see this:

Write btc-usd (i.e. Bitcoin to USD) and press the Test operation button.  Initially you may get a 404 error.  I found that waiting a few minutes and then repeating, I finally got this:

Now you can create the PowerApp and use the connection that you created.  Do the following steps in your PowerApps editor:

  1. Create a new blank app
  2. Add Cryptonator as a data source with:
    View->Data sources-> +Add data source
    and select Cryptonator
  3. Insert a new drop down
  4. Rename it DropdownBase
  5. Set its Items property for example to: [“AUD”, “EUR”, “GBP”, “USD”]
  6. Insert another new drop down
  7. Rename it DropdownTarget
  8. Set its Items property for example to: [“BTC”, “ETH”]
  9. Insert a new label
  10. Set its Text property to this:
    Value(Cryptonator.Run(DropdownBase.Selected.Value&"-"&DropdownTarget.Selected.Value).ticker.price)

The Value function is not really needed, but if you need the value in a formula please use it, since the price property is returned as text so needs conversion to a number.

The app should look something like this:

You can customise the Swagger file to work with any API, please experiment.

I hope this worked for you too, any comments would be very welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *