This blog is part of the series Visual Builder Cloud Service Learning Path. In this lesson, we will look at integrating a third party REST API that has no description document (Swagger or ADF Describe). We will integrate the Twitter API to fetch a list of tweets for a list celebrities stored in a custom Business Object.
Importing the Starter Project
We'll start the lesson with an application that already contains the Celebrities Business Object and mobile application with a list of celebrities and a details page for each one.
Click Request > URL Parameters. Add the following Dynamic Query Parameter:
screen_name – String
Click Test. Enter SFGiants as the screen_name and click Send. The response body appears in the Body area below. Click the Copy to Response Body button.
Click Create.
Consuming the Twitter API
Now let's drop a list into the Celebrity Detail page and populate it with a list of the celebrity's tweets.
Go to the Mobile Apps panel and click Tweets > flows > main > CelebrityDetail. The page opens but gives a 404 error as there is no cebrityId provided.
Click the button and enter 1 in the dialog box. The page renders with the Katy Parry information.
Drop a List View under the Twitter Feed header.
In the Property Inspector, click Add Data.
Under Twitter, select GET /user_timeline.json and click Next.
Choose the first template and click Next.
Add the created_at field to Field 2 and the and the text field to Field 4. Set the Primary Key to id. Click Next.
Map celebrity > twitterHandle on the left to uriParameters > screen_name on the right.
Click Finish.
Wrapping the Twitter Feed List in an oj-bind-if
If you run the app now you'll notice that the Twitter call isn't working. If you look at the REST call in the Chrome Developer Tools, you'll see it's passing undefined as the screen_name. That's because the page hasn't finished loading the celebrity details before it tries calling Twitter. We fix that by wrapping the list in an oj-bind-if and check that celebrity object is populated before we render the Twitter list.
Right-click the list in ContactDetail and choose Surround With > If
Right-click the list and choose Select Parent > If.
Note: In our database we know that twitterHandle will always have a value. In more complex cases, you'll have to create more complex logic to handle null, undefined, empty string values, and other situations.
Reload the page. The list of Tweets renders correctly.