Creating a custom connector to upload a file to Google Drive from Power Apps – Part 2
Part 1 can be found here.
Swagger time
To create a customer connector, you can upload either a swagger file or a Postman collection. I am not a swagger expert. But, apistudio makes my life easier. Let’s jump onto http://specgen.apistudio.io.
Paste the URL that you used in Postman. Make sure you are using POST. You should receive 202 status after sending the request. One more thing to remember is to click ‘Next Step‘ button instead of clicking tabs. Otherwise, you will need to rework.
Enter API Program and contact info. Ensure to use valid Contact Url and Contact Email. What’s next? Next Step button.
Next is API Info. You can play around with the slider which will change API Base Path and API Path. Give a meaningful OperationId.
There is nothing special to do with Headers Info and Params Info, although we will make some manual changes in them. I don’t see (and I don’t know) to make those changes in the generator.
Keep clicking Next Step until you get Open API Spec. There you can download the swagger file.
Now, let’s make a few changes to swagger file.
First, we need to replace null with application/json in “produces” collection, and remove the whole section for “content-type”
Set default values for api-version, sp, sv and sig. You can find these values in URL or using Postman.
Lastly, you need to add parameters for file content, which will be reading from formData as a file type.
That’s pretty much you need to do in Swagger file before creating a custom connector in Power Apps.
Creating a custom connector
Launch Power Apps in the browser and go to Custom connectors, and import your swagger file.
Generally, you don’t need to change anything until you get to 3. Definition. At 2. Security, you can still use ‘No authentication’ as the API will authenticate using sig parameter you have provided in the query string. As long as you don’t expose signature parameter, no authorised user can use your API.
At step 3, scroll to Request section where you will see query parameters. Edit api-version, sp, sv and sig, and change their visibility to internal since we have set default values in swagger file.
After changing visibility of api-version, sp, sv and sig, you can now create a custom connector.
Once it is created, it is time to head into Power Apps. In your Power Apps, while adding a new data source, you can now find your custom connector.
After creating a data source, let’s add some controls to Power Apps and check whether it’s working. I have added PenInput and Button as below. OnSelect of Button, I am going to push the image from PenInput to my Google Drive.
Viola. It is now uploaded to Google Drive.
Power Apps does not work
You know it right? Save, close and open your Power Apps again.
One last thing
This is only an example of how we can easily (of course, I can know say ‘it is easy’) transform any Flow functionalities as custom connectors. This also solves the concern of using Camera control which produces a low resolution photo. With this approach, we can use AddPicture control not only to take full advantage of device camera but also to pick up photos/files which are already existed in the device.
Generally, we don’t need custom connectors if parameter types are simple. In this example, we need Base64. I guess, depending on the parameter type of an endpoint, Power Apps may be passing suitable parameters.
Anyway, we can now invoke all those infinite possible connectors of Flow from Power Apps.
Creating a custom connector to upload a file to Google Drive from Power Apps – Part 2