DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Understanding Salesforce Composite Connector With MuleSoft
  • Real-Time Risk Signals for AI Agent Authorization
  • The Trust Problem in Modern SaaS: Why Your Authentication Succeeded, and You Still Got Breached
  • Your API Authentication Isn’t Broken; It’s Quietly Failing in These 6 Ways

Trending

  • PostgreSQL vs Oracle: When Higher Cost Means Better Performance
  • Java 8 Optional - Avoid Null and NullPointerException Altogether - and Keep It Pretty
  • Who Should Grade Your AI? Rules vs LLM Judges vs Humans
  • Replay, Scheduling, and Throttling: Engineering a Self-Service Kafka Streaming Tool at Scale

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Connecting Google Spreadsheet APIs With Mule ESB

Connecting Google Spreadsheet APIs With Mule ESB

Google's API lets you communicate with their integration services. Learn to configure and connect Mule ESB with Google API, with code and a video tutorial.

By 
Jitendra Bafna
·
May. 02, 17 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
8.5K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

Google provides an Application Programming Interface which allows you to communicate with Google services and their integration services. It is useful for a third-party to take advantage of APIs and can even extend the functionalities of APIs. Examples of these include Search, YouTube, Google Spreadsheet, Google Maps, Google Contacts, etc. Google APIs require authentication and authorization using OAuth 2.0.

Mule ESB has capabilities to connect Google APIs and it provides various connectors to connect the Google APIs and perform the operations that you need. Below is a list of connectors available in Anypoint Exchange to connect Google APIs.

  • Google Spreadsheets Connector.

  • Google Contacts Connector.

  • Google Tasks Connector.

  • Google Calendar Connector.

  • Google Prediction Connector.

  • Google Contacts RAML.

  • Google Drive RAML.

Image title

In this article, you will see Google Spreadsheets Connector. Google Spreadsheets Connector provides instant API connectivity to Google Spreadsheets APIs, which allows you to create, modify, or access Google docs using OAuth 2.0 authentication. For more details on Google Spreadsheets API, click here.

By default, you will not find Google Spreadsheets Connector in your Anypoint Studio, so you can install the connector from Anypoint Exchange.

The first thing you need to do is authorize the operation to generate the token.

  <google-spreadsheets:config-with-oauth name="Google_Spreadsheets" consumerKey="${gs.clientid}" consumerSecret="${gs.clientsecret}" doc:name="Google Spreadsheets" scope="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://spreadsheets.google.com/feeds https://docs.google.com/feeds https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email">
        <google-spreadsheets:oauth-callback-config domain="${oauth.host}"   path="oauth2callback" async="true"/>
    </google-spreadsheets:config-with-oauth>
Fields Description
consumerKey The OAuth consumer key. It can obtain from the Google developer console.
consumerSecret

The OAuth consumer secret. It can obtain from the Google developer console.

scope

https://www.googleapis.com/auth/userinfo.profile

https://www.googleapis.com/auth/userinfo.email

https://spreadsheets.google.com/feeds

https://docs.google.com/feeds

https://www.googleapis.com/auth/spreadsheets.readonly

https://www.googleapis.com/auth/spreadsheets

Access Token URL

The URL defined by the Service Provider to obtain an access token.

Value: - https://accounts.google.com/o/oauth2/token

Authorization URL

The URL defined by the Service Provider where the resource owner will be redirected to grant authorization to the connector.

Value: - https://accounts.google.com/o/oauth2/auth

Callback URL It is made up of the domain, local port, remote port, and path. Example: http://localhost:3000/oauthcallback. 
This URL also needs to add under redirect URIs in the Google developer console.

Image title

Configuration Reference 

Image title

Authorizing the operation will return tokenID, and it can be read using flow variable  #[flowVars['OAuthAccessTokenId']] 

Once authorization is successful, you can use any operation to be performed depending on your requirement; make sure you are sending the token with every request to Google Spreadsheets APIs.

Image title

Image titleSometimes there can be a case when you need to use the authorized operation in one flow and another operation in other flow. In such a case, you need to use object store to store the tokenID generated during authorize operation to retrieve from the object store in other flow.

Code

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:ws="http://www.mulesoft.org/schema/mule/ws" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:context="http://www.springframework.org/schema/context" xmlns:google-spreadsheets="http://www.mulesoft.org/schema/mule/google-spreadsheets" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/google-spreaadsheets http://www.mulesoft.org/schema/mule/google-spreadsheets/current/mule-google-spreadsheets.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/google-spreadsheets http://www.mulesoft.org/schema/mule/google-spreadsheets/current/mule-google-spreadsheets.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <google-spreadsheets:config-with-oauth name="Google_Spreadsheets" consumerKey="${gs.clientid}" consumerSecret="${gs.clientsecret}" doc:name="Google Spreadsheets" scope="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://spreadsheets.google.com/feeds https://docs.google.com/feeds https://www.googleapis.com/auth/spreadsheets.readonly https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email">
        <google-spreadsheets:oauth-callback-config domain="${oauth.host}"   path="oauth2callback" async="true"/>
    </google-spreadsheets:config-with-oauth>a
    <flow name="google-spreadsheet-apiFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/authorize"  doc:name="HTTP" allowedMethods="GET"/>
        <google-spreadsheets:authorize config-ref="Google_Spreadsheets" doc:name="Google Spreadsheets" accessTokenUrl=" https://accounts.google.com/o/oauth2/token" authorizationUrl="https://accounts.google.com/o/oauth2/auth"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <google-spreadsheets:get-all-cells-as-csv config-ref="Google_Spreadsheets" lineSeparator="|" spreadsheet="Employee" worksheet="Employee" accessTokenId="#[flowVars['OAuthAccessTokenId']]" doc:name="Google Spreadsheets"/>
        <logger message="data fetched. #[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>


References

  • Google API Commons: https://github.com/mulesoft/google-api-commons
  • Google Calendar: https://github.com/mulesoft/google-calendar-connector
  • Google Contacts: https://github.com/mulesoft/google-contacts-connector
  • Google Cloud Messaging: https://github.com/mulesoft/google-cloud-messaging-connector
  • Google Drive: https://github.com/mulesoft/google-drive-connector
  • Gmail: https://github.com/mulesoft/gmail-connector
  • Google Prediction: https://github.com/mulesoft/google-prediction-connector
  • Google Spreadsheets: https://github.com/mulesoft/google-spreadsheets-connector
  • Google Tasks: https://github.com/mulesoft/google-tasks-connector

Now, you know how to connect Google APIs With Mule ESB.

Here is the video tutorial:


Google Contacts Enterprise service bus Connector (mathematics) Google APIs authentication

Opinions expressed by DZone contributors are their own.

Related

  • Understanding Salesforce Composite Connector With MuleSoft
  • Real-Time Risk Signals for AI Agent Authorization
  • The Trust Problem in Modern SaaS: Why Your Authentication Succeeded, and You Still Got Breached
  • Your API Authentication Isn’t Broken; It’s Quietly Failing in These 6 Ways

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook