HomeGuidesRecipesAPI EndpointsRelease NotesCommunity
Log In

Adding Connectors to Layar

❗️

Excludes Twitter Connectors

Please note that these instructions are for all connector types except Twitter connectors, which have their own endpoint. To add a Twitter connector, please see the page for Adding Twitter Connectors From The API.

Using the LiveSourceApi

In order to create and manage your connectors (excluding Twitter), we'll be using the LiveSourceApi. Ensure you've followed the setup instructions in the Getting Started Guide and then instantiate the LiveSourceApi as shown below.

connectors = layar_api.LiveSourceApi(layar_api.ApiClient(configuration))

Creating a New Connector Body

Before creating a new connector we will need to create an object to pass the connector type's required parameters. Create a body object and then find the required parameters for the connector type you would like to add below. If you would like to create a Twitter connector, please reference Adding Twitter Connectors From The API.

body = layar_api.Body4()

Website Connector

Website connectors are the simplest ones to set up. They require only a name and a URL, both as strings. You can also add an optional description. Add them to your body object as shown below.

body.liveSourceType = 'WEBSITE'
body.name = 'Website Name'
body.description = 'A brief description of the website.' #Optional
body.url = 'https://www.website.com'

RSS Connector

RSS Connectors also require a name and a URL with an option to add a description, but will also need to be provided a runMode which will tell Layar if you would like to scan the RSS feed once at the time of creation or continuously check for updates. runMode accepts a string of either "SCAN_ONCE" or "CONTINUOUS". Add the parameters to your body as shown below.

body.liveSourceType = 'RSS'
body.name= 'RSS Feed Name'
body.description = 'A brief description of the RSS Feed.' #Optional
body.url = 'https://www.website.com/path/to/feed.rss'
body.runMode = 'CONTINUOUS'

Google BigQuery Connector

In order to add a Google BigQuery connector, you will need your BigQuery project ID and GCP Service Account Key. To find this information please follow Google's Support Documentation. Once you have these parameters, add them to your body as shown below.

body.liveSourceType = 'GBQ_PROJECT'
body.name = 'bigquery-project-id'
body.description = 'A brief description of your BigQuery project.' #Optional
body.credentials = """
{
        "type": "service_account",
        "project_id": "project-id",
        "private_key_id": "key-id",
        "private_key": "--BEGIN PRIVATE KEY--\nprivate-key\n--END PRIVATE KEY--\n",
        "client_email": "service-account-email",
        "client_id": "client-id",
        "auth_uri": "https://accounts.google.com/o/oauth2/auth",
        "token_uri": "https://accounts.google.com/o/oauth2/token",
        "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
        "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/service-account-email"
}
"""
#Use triple quotes for multi-line strings (like your credentials) in Python

Adding The Connector

Once you have built out your bodyobject, you'll want to pass it to the create_feeds method in order to create your new connector as shown below. The method will return a response object containing a connectorId which you will need to make sure you store in a variable for when it's time for Managing Connectors.

new_connector = connectors.create_feeds(body)
connector_id = new_connector.connectorId
pprint(connector_id) #Optional