tutorial

  1. Home
  2. docs
  3. tutorial
  4. 27th Overview of existing Skyvva adapters
  5. 27.6 How to create REST interface using REST adapter?

27.6 How to create REST interface using REST adapter?

Learning Objective:

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

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

introduction

User create Rest adapter to callout data from Skyvva - Salesforce to other Skyvva Salesforce instance.

What is REST Adapter?

The Representational State Transfer (REST) adapter enables you to exchange messages between remote clients or web service servers and the Integration Server. It supports dynamic URLs, REST API polling, multiple operations per channel as well as XML and JSON data formats.

Rest adapter is used for data processing of both direction. I,e Inbound and outbound.

REST request-> Outbound interface

Rest response-> Inbound interface

What is REST request?

REST requires that a client make a request to the server in order to retrieve or modify data on the server. A request generally consists of: an HTTP verb, which defines what kind of operation to perform. a header, which allows the client to pass along information about the request.

What is Rest response?

When an XML String is sent to a REST service, you must set Content-Type HTTP header to be "application/xml". The REST service converts the XML input data to the JSON format that is accepted by REST services.

Resource Methods:
Other important thing associated with REST is resource methods to be used to perform the desired transition. A large number of people wrongly relate resource methods to HTTP GET/PUT/POST/DELETE methods.

SetUp:

Step one: Create Adaptor

  • First Insert Adaptor Record By giving prefer Name and select Type = REST
  • Now Insert PropertiesIf 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"

Click on Save button. It should navigate to:

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

Here we are creating metadata for message type. Metdata providers are plugins that do the actual metadata extraction from files. Metadata Provider tell the data processing layer of libmd which metadata fields (types) they can extract.

In Skyvva, when we create metadata, Name filed is only mandory field. On MetaData the Name cannot be duplicate.

Step3: Create Istructure repository

The term Repository is in fact to store data and structure of a message. The purpose of Istructure is An Interface for a structure that contains the metadata of a structure.

Step four: Create Message type

Now Create Message Types for IStructure Repository. Free define message type is a type and structure definition which is store in Repository. 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 five. 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).

Step six. Create Interface (Inbound/Outbound). Refer tutorial to create Interface.

6.1 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

Scroll down the page to the mapping section.

Target object Istructure is shown as tree structure. As we use JSON data to create message type, Istructure should display in three portion in

request

⇓⇒ URL

                   ⇓

       header

                   ⇓

body

So , when we get response and we will get both header and body so based on mapping we will perform DML operation for the data we got in response.

 

Now callout the data with developer console.

Go to developer console and enter this code to Execute Anonymous window.

skyvvasolutions.CallOutControl c = new skyvvasolutions.CallOutControl();
c.returnJSONComplete=true;
c.actionDoIntegrate=true;
c.isCreateMessage=true;
String[] ids= new String[]{‚0016F000033uIHKQA2‘};
skyvvasolutions.CallOutResponse r = skyvvasolutions.Iservices.invokeCallout2(‚Rest_adapter‘,’Outbound_Interface‘,ids,’SYNC‘,c);

Here In ids We have to insert Record id of Target Object and first parameter in method should pass Integration Name and second will be the interface name as we have here

Integration Name = 'Rest_adapter

Interface Name = 'Outbound_Interface'.

Execute the callout and check the result on message monitoring.

  • Go to Integration detail page -> click on Messages
  • Click on search button on message monitoring page and check the result.

Click on related to link to check the account contact relationship.

 

6.2 Create inbound Interface for response

We must fill this fields ..

  • Inbound 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 RESPONSE)
  • Source/Target Name : Select Any Object.

Save the Interface.

We have to link this inbound interface with our outbound interface which is response interface.

How to link request and response Interface?

Follow the given step to link request and response interface.

  1. Go to outbound interface. Scroll down the page to outbound setup section.
  2. Edit the response interface field and select inbound interface id.
  3. Save the changes.

Now go to our inbound interface -> scroll down the page to mapping section and map the fields with Skyvva mapping tool.

Create foreign key to link account and contact object.

Save the mapping.

  • To get response from endpoint you should have data at endpoint (Rest api which you called)

For example if you have data like:

{
„MyAccount“ : {
„Name“ : „Testing Name“,
„Description“ : „Testing Description“,
„MyContact“ : {
„FirstName“ : „Testing FirstName“,
„LastName“ : „Testing LastName“
}
}
}

  • Now callout the data with developer console.

Go to developer console and enter this code to Execute Anonymous window.

skyvvasolutions.CallOutControl c = new skyvvasolutions.CallOutControl();
c.returnJSONComplete=true;
c.actionDoIntegrate=true;
c.isCreateMessage=true;
String[] ids= new String[]{‚0016F000033uIHKQA2‘};
skyvvasolutions.CallOutResponse r = skyvvasolutions.Iservices.invokeCallout2(‚Rest_adapter‘,’Outbound_Interface‘,ids,’SYNC‘,c);

Here In ids We have to insert Record id of Target Object and first parameter in method should pass Integration Name and second will be the interface name as we have here

Integration Name = 'Rest_adapter

Interface Name = 'Outbound_Interface'.

  • Execute the callout and check the result on message monitoring.
  • Go to Integration detail page -> click on Messages

Click on related to link to check the result:

 

 

 

 

 

Was this article helpful to you? Yes No

How can we help?