Cloud Elements supports events via polling or webhooks depending on the API provider. For more information about our Events framework, see Events Overview.
Supported Events and Resources
Cloud Elements supports polling events for Gmail. After receiving an event, Cloud Elements standardizes the payload and sends an event to the configured callback URL of your authenticated element instance.
You can set up polling for the changed-messages
resource. You can also copy the changed-messages
configuration to poll other resources. See Configure Polling Through API for more information.
Configure Polling Through the UI
To configure polling through the UI, follow the same steps to authenticate an element instance, and then turn on events. Select the resources to poll, and then click Create Instance. For more information, see Authenticate an Element Instance with Events (UI) or the element-specific authentication topic.
Configure Polling Through API
Use the /instances
endpoint to authenticate with Google and create an element instance with polling enabled.
To authenticate an element instance with polling:
- Get an authorization grant code by completing the steps in Getting a redirect URL and Authenticating users and receiving the authorization grant code.
Construct a JSON body as shown below (see Parameters):
{ "element":{ "key":"gmail" }, "providerData":{ "code": "<AUTHORIZATION_GRANT_CODE>" }, "configuration":{ "oauth.api.key": "<Google app Client ID>", "oauth.api.secret": "<Google app Client secret>", "oauth.callback.url": "<Google app Authorized redirect URI>", "event.notification.enabled": true, "event.notification.callback.url": "http://mycoolapp.com", "event.poller.refresh_interval": "<minutes>", "event.poller.configuration":{ "/changed-messages": { "url": "/hubs/general/changed-message", "idField": "id" } } }, "tags":[ "<Add_Your_Tag>" ], "name":"<INSTANCE_NAME>" }
Call the following, including the JSON body you constructed in the previous step:
POST /instances
Note: Make sure that you include the User and Organization keys in the header. For more information, see Authorization Headers, Organization Secret, and User Secret.Locate the
token
andid
in the response and save them for all future requests using the element instance.
Example cURL with Polling
curl -X POST \
https://api.cloud-elements.com/elements/api-v2/instances \
-H 'authorization: User <USER_SECRET>, Organization <ORGANIZATION_SECRET>' \
-H 'content-type: application/json' \
-d '{
"element": {
"key": "gmail"
},
"providerData":{
"code": "<AUTHORIZATION_GRANT_CODE>"
},
"configuration": {
"oauth.api.key": "xxxxxxxxxxxxxxxxxx",
"oauth.api.secret": "xxxxxxxxxxxxxxxxxxxxxxxx",
"oauth.callback.url":"https://auth.mycoolapp.com/oauth",
"event.notification.enabled": true,
"event.notification.callback.url": "https://cloud-element.com/elements/api-v2/events/page.elementKey/",
"event.poller.refresh_interval": "15",
"event.poller.configuration":{
"changed-messages": {
"url": "/hubs/general/changed-messages",
"idField": "id"
}
}
},
"tags": [
"Docs"
],
"name": "API Instance with Polling"
}'
Parameters
API parameters not shown in Cloud Elements are in code formatting
.
Parameter | Description | Data Type |
---|---|---|
key | The element key. gmail | string |
code | The authorization grant code returned from the API provider in an OAuth 2.0 authentication workflow. Cloud Elements uses the code to retrieve the OAuth access and refresh tokens from the endpoint. | string |
Namename | The name of the element instance created during authentication. | Body |
oauth.api.key | The API key or client ID obtained from registering your app with the provider. This is the Client ID that you noted in API Provider Setup. | string |
oauth.api.secret | The client secret obtained from registering your app with the API provider. This is the Client secret that you noted in API Provider Setup. | string |
oauth.callback.url | The API key or client ID obtained from registering your app with the provider. This is the Authorized redirect URI that you noted in API Provider Setup. | string |
Events Enabledevent.notification.enabled | Optional. Identifies that events are enabled for the element instance. Default: false . | boolean |
Event Notification Callback URLevent.notification.callback.url | The URL where you want Cloud Elements to send the events. | string |
Event poller refresh interval (mins)event.poller.refresh_interval | A number in minutes to identify how often the poller should check for changes. | number |
Configure Pollingevent.poller.configuration | Optional. Configuration parameters for polling. | JSON object |
Resource to Poll | The polling event configuration of the resource that you will monitor. | JSON object |
URLurl | The url to query for updates to the resource. | String |
ID FieldidField | The field in the resource that is used to uniquely identify it. | String |
tags | Optional. User-defined tags to further identify the instance. | string |