Data Synchronization

TMDB provides GET /discover API to fetch details of movies by popularity. We shall use it to demonstrate how to build data connector which can bring data into CRM.

GET /discover Usage

curl --request GET \
     --url 'https://api.themoviedb.org/3/discover/movie?include_adult=false&sort_by=popularity.desc' \
     --header 'Authorization: Bearer api_read_only_token' \
     --header 'accept: application/json'
{
  "page": 1,
  "results": [
    {
      "adult": boolean,
      "backdrop_path": string,
      "genre_ids": array,
      "id": number,
      "original_language": string,
      "original_title": string,
      "overview": string,
      "popularity": decimal,
      "poster_path": string,
      "release_date": date,
      "title": string,
      "video": boolean,
      "vote_average": float,
      "vote_count": number
    },
}

Build Connector

To build data sync connector for Movies module in CRM.

Navigate to Main Menu > Platform > Module Designer

  1. Choose Movies
  2. Click on + Connector

Fill details of connector. Click Save

Here is the connector VADL code which enables you to get user-configuration, make-request and map-response to CRM records easily.

<?xml version='1.0'?>
<connector for="Sync">
    <!-- configuration field to accept details during connector setup. -->
    <config>
        <fields>
            <field name="tmdb_api_token" type="text" required="true" />
        </fields>
    </config>
    <!-- synchronization strategy global to CRM -->
    <synctype>app</synctype>

    <!-- Definition to pull data from external service. -->
    <service>
        <url>https://api.themoviedb.org</url>
    </service>
    <pull>
        <request method="get">
            <url>/3/discover/movie</url>
            <headers>
                <header name="content-type" value="application/json" />
                <header name="Authorization" value="$config.$fields.tmdb_api_token" />
            </headers>
            <parameters>
                <parameter name="include_adult" value="false" />
                <parameter name="sort_by" value="popularity.desc" />
            </parameters>
        </request>
        <response format="xml|json">
            <code use="200" />  <!-- expected response code -->
            <error use="errorIdentifier" />
            <records use="results" />
            <recordid use="id" />
        </response>
    </pull>
    
    <!-- Map external data to CRM data -->
    <modules>
        <!-- 
            servicemodule: short-identifier of target service 
            vtigermodule : target module of CRM
        -->
        <module servicemodule="TMDB" vtigermodule="vtcmmovies"></module>
    </modules>
    <fieldmapping>
        <vtcmmovies>
            <!-- map each row of (pull > records) to module record.  -->
            <field vtigerfield="fld_vtcmmoviesname" servicefield="original_title" />
            <field vtigerfield="fld_releasedon" servicefield="release_date" />
        </vtcmmovies>
    </fieldmapping>
</connector>

You can copy-and-paste code in IDE. Save and Publish.

It will now be ready for use.

Use Connector

Sync button will appear on Movies module as we have published TMDB Connector.

We have to activate as first step.

Click Settings and Save with default option.

Login to TMDB. Navigate to Settings > API > Copy API Read Access Token

Update Sync Settings > tmdb_api_token

With Bearer API-Read-Access-Token

Click Save. We are ready to Sync Now

With Sync Now success you will be able to check the Sync Log

Popular movies will appear in the Movies ListView.

You can learn more about Data Sync connector.

To stay focused now let us proceed with API Integration