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
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Understanding Salesforce Composite Connector With MuleSoft
  • Implementing NetSuite Saved Search With MuleSoft - Part 1
  • Building Resilient Identity Systems: Lessons from Securing Billions of Authentication Requests
  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals

Trending

  • Designing a Java Connector for Software Integrations
  • Memory-Optimized Tables: Implementation Strategies for SQL Server
  • Strategies for Securing E-Commerce Applications
  • When Airflow Tasks Get Stuck in Queued: A Real-World Debugging Story
  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 user avatar
Jitendra Bafna
DZone Core CORE ·
May. 02, 17 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
8.2K Views

Join the DZone community and get the full member experience.

Join For Free

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
  • Implementing NetSuite Saved Search With MuleSoft - Part 1
  • Building Resilient Identity Systems: Lessons from Securing Billions of Authentication Requests
  • Secure by Design: Modernizing Authentication With Centralized Access and Adaptive Signals

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!