Tutorial - Using Google services with webMethods.io Integration
This article is a short guide for those wanting to use Google (e.g. gmail™, sheets™) with webMethods.io Integration. Shout-out to Vidyesh for some crucial pointers.
The proposed flow is very simple:
Run on demand, get some rows from a Google Sheets workbook and print them using the Logger (hidden in the Loop).
If you look closely at the figures in the article you are likely to see some mismatching names - this is due to me creating new versions of something that was already there, don't let that distract you.
Steps to follow:
Authorize webMethods.io to access Google
Go to the Google “APIs and Services” page: https://console.developers.google.com/apis
Log in using the account you are going to use for the exercise (for testing I would really recommend using a “throw-away” account, or at the least, revoke any access afterwards!)
Go to “Credentials”, shown below:
As you can see, I already have webMethods.io added as an OAuth2 client, add yours as shown below:
Create a new OAuth Client ID (choose web application):
Note that the URLs used should be the base URL of your webMethods.io tenant.
Once created, you can retrieve the Client ID and secret at any time by looking at the detail of the client you just created. Also see the “Download JSON” link – this gives you everything in one handy file. It contains sensitive information though, SO BE CAREFUL WHERE YOU STORE IT AND DO NOT SHARE IT WITH ANYBODY.
The important parts of the JSON file are the following:
You will need this information to get your Google access token – more about this later.
In order to figure out the Scope that you will need later, refer to this: https://developers.google.com/identity/protocols/googlescopes
In this example, we are interested in Google Sheets, highlighted below:
You may need the scopes in the next activity – completing the OAuth consent screen:
Add the scope(s) if they are not available (like the one shown above that ends in “readonly”). Click the "manually paste" link to get the little text box where you can add it:
Also make sure that you enable the API for use in your project (API Library tab) - if you don't, you are likely going to run into an error when you try using it in the workflow:
You should now be good to go and in a position to use this configuration in webMethods.io Integration.
In a client that support OAuth, get your token
I used the RESTer plugin for Firefox – feel free to use whatever works for you (I could not get my favorite Postman to work, Google was unhappy with the browser it uses, if you manage to get this working, please let me know!)
Complete the following information to get your access token:
If you click on the OAuth2 configuration (mine is called “gmail” as you can see in the following figure) that you set up in the previous step, you should see popup screens for authentication/ authorization. If successful, you should see a new token appear under “Use existing tokens”, highlighted below:
You can get the access token by going to the “Headers” tab, copy the value of the token (the part that is highlighted):
In webMethods.io Integration workflow
Open the workflow (shown at the start of the article) and configure the Google Sheets connector:
In this example, I want to “Get Rows”:
Add the authorization – this brings up a new screen (name and Client ID are hidden from view here) - use the client ID and secret that you got when you registered the client and use the Refresh URL and Grant Type as shown below. I used the same token for access and refresh token - probably not a good idea, but since I can only get teh Bearer token in RESTer, I stuck with that.
If you get a message that the action was successful, save and continue. If not, look at the error (the message may not be very helpful - recheck all of your inputs, make sure you have no leading/ trailing spaces).
Below is an example of what you should see (Spreadsheet ID and Sheet Name will show you a list of what is available if you click the “expand” icon - this is also where you are likely to see an error if you forgot to enable the API as was mentioned earlier in the article):
Now configure the logger in the loop:
And once completed, run your workflow:
As you can see – this very simple flow fetched data from Google Sheets and printed it out.
And that concludes the test and the article. It is a very simple example, but the same approach works with Gmail and should work with any of the Google connectors that are available although I have not tested them all.
Update: I found that I can use Postman to get the Google tokens - but for one of my accounts (the one I used in the tutorial) this does NOT work for some reason that I haven't been able to figure out yet. Also, if you add "?access_type=offline" to the authorization URL, it should return a refresh token when you call it the first time.