Tutorials

  1. Home
  2. Docs
  3. Tutorials
  4. 26. Overview of existing Skyvva adapters
  5. How to use the REST adapter to consume Google API?

How to use the REST adapter to consume Google API?

Learning Objective:

After completing this unit, you’ll be able to:

  • Describe what Rest Adapter is.
  • Comfortably use Rest Adapter.

Introduction

Representational State Transfer is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services, provide interoperability between computer systems on the Internet.

What is Google API?

Google APIs is a set of application programming interfaces (APIs) developed by Google which allow communication with Google Services and their integration to other services. … Another important example is an embedded Google map on a website, which can be achieved using the Static maps API, Places API or Google Earth API

OAuth 2.0 Playground: The OAuth 2.0 Playground will help you understand the OAuth authorization flows and show each step of the process of obtaining an access token

CONFIGURATION TO CONNECT SKYVVA REST API TO GOOGLE DRIVE

The Drive API allows you to create mobile, web, and desktop apps that that read, write, and sync files in Google Drive.  API is an interface that provides raw data for the public to use although many require some form of authentication. Google deal with the oAuth 2 authentication schema which is widely use with REST api.

Here we are giving the steps to link Skyvva rest api with google drive.

Step1: For oAuth2 authentication with google api we need to visit to developers.google.com. We should click on Link:-  https://developers.google.com/oauthplayground/. And Select Drive api v3 and click on Authorize API.

Note: We should have our google account, If not then create new google account.

Once we select drive API then Authorize it with our google account.

When refresh token and Access token are generated then copy it and paste to notepad. (we need it later)

Step2: Now we have to create project in the google developer console. So follow below step to do that.

To create new project we have to click on “Create project  link”.

Click on create button. Once project is created we have to set credentials to our project. Follow the given steps to set credentials.

  • Click on navigation menu.
  • Go to APIs& services.
  • Click credentials.

Click on create credentials button.

Select OAuth client Id from the list. Client ID : Is used to identify the application. … As per oAuth standard you need both Client ID & Client Secret along with user credentials to generate an access token. It’s the standard defined by OAuth.

  • Select Web application and give the name and click on create.

It will give client id and client secret. So just copy paste it to the notepad.

Step3:  To configure google drive api with rest adapter follow the given steps:

  • Go to our salesforce organisation and click on adapter tab.
  • Create new adapter:

– First Insert Adaptor Record By giving prefer Name and select Type = REST

-Now Insert Properties

If Need Authorization

-REST API Service Endpoint URL : “” , Insert Endpoint URL where Request will direct

-Username : “”, Your Endservice UserName

-Password : “”, Your Endservice Password

-Authentication : “BASIC”

-REST Operation : “POST”

               -Auto2o flow : “Refresh Token”

Click on save button. It should navigate to:

Now you can click on TEST Connection button and test the adaptor.

Step4: Create Metadata     Now , Insert METADATA record By giving prefer details.

Step5: Create Istructure repository and import file I have attached with it.

Step6: Create message type:

The message type can be resided in a WSDL, in SAP IDoc, SAP Bapi, etc… It can be stored in a file in csv, xml or other format.

For the Message Type , you have to use our defined Structure Defined Structure .

{
“REST API H”: {
“Request”: {
“URL”: {
“PATH Parameter”: {
“UId”: “”,
“SobjCode”: “”
},
“QUERY Parameter”: {
“RecId”: “”,
“UName”: “”
}
},
“Header”: {
“AuthPermission”: “”,
“AuthId”: “”
},
“Body”: {
“MyAccount”: {
“Name”: “”,
“Description”: “”,
“MyContact”: {
“FirstName”: “”,
“LastName”: “”
}
}
}
},
“REST Response”: {
“REST Response Header”: {
“AuthId”: “”,
“SobjId”: “”
},
“REST Response Body”: {
“MyAccount”: {
“Name”: “”,
“Description”: “”,
“MyContact”: {
“FirstName”: “”,
“LastName”: “”
}
}
}
}
}
}

  • Go to you Istructure repository and click on open editor button.

  • Select file type as JSON and give input to open text box as below:

  • Click on save button and check created massage type.

Note: Please check the type of your msg type. it should be same as shown in screen.

 Step 6:Create Integration. Refer  tutorial (How to create integration.)

  •  Link adaptor we created earlier
  • Max Number of Retry (This means number of time should we retry if request fails first time).

 

Step7: Create Interface.

Create outbound Interface for request

Must fill this fields of Outbound Interface :

–  Outbound Adaptor : Select we created earlier

– Metadata Provider : Select we created earlier

– IStructure Repository : Select created IStructure Repo.

– MessageTypes : Select MessageType (Selected MsgType TYPE should always be REST REQUEST)

– Source/Target Name :  Select Any Object

– Query : Query need to be insert and query should always include all fields we have mapped or going to map.

– Map Fields

 

Step8: Callout

So, After creating Record. We can callout using below code

CallOutControl c = new CallOutControl();

c.returnJSONComplete=true;

c.actionDoIntegrate=true;

c.isCreateMessage=true;

String[] ids= new String[]{‘0011x00000JeEgmAAF’};

CallOutResponse r = Iservices.invokeCallout2(‘Google Drive Integration’,’FileRequest’,ids,’SYNC’,c);

 

Here Ids : We have to insert Record id of Target Object.

Google Drive Integration : It is the Integration record Name

File Request : It is interface record Name

Then you can verify , Account and contact record will be inserted based on mapping of interface.

 

 

Was this article helpful to you? Yes No

How can we help?