Create a subscription

post

/rest/ofscCore/v1/events/subscriptions

This operation creates a subscription for Oracle Field Service events.

Events are generated when there is a change to one of the available events in the Oracle Field Service application (for example, activityCreated, activityCompleted, inventoryInstalled, and so on).

One or more event(s) should be specified in the request. A 'subscriptionId' that is returned when a subscription is created should be used in the 'Get events' operation to retrieve subscription data.

Subscriptions can be deleted using the Delete Subscription API. However, the subscriptions that are not used in the Get Events operation will expire after 36 hours.

Users can create a maximum of 100 subscriptions per environment simultaneously.

If more than 100 subscriptions are created then the response returns the 503 status code with the description "Too many subscriptions registered. Found 100." Also, if a user creates a duplicate subscription, then it points to the existing subscription.

For the list of events that can be subscribed, see Supported Events.

Create subscription request validation

The request will fail if the following conditions are met:

  • The user does not have the write permission for Core API events.
  • Neither the 'events' parameter is specified in the root of the request nor the 'subscriptionConfig' elements are specified in the request.
  • The 'events' parameter in the root of the request and the 'subscriptionConfig' elements are specified simultaneously.
  • Either the 'events' or the 'subscriptionConfig' parameter is empty.
  • The subscriptionConfig elements or IDs where each subscription config element needs to be checked.
  • subscriptionConfig elements/IDs/events
    • The Events parameter is an empty array or is not present.
    • Events contain events that do not exist, for example, the 'activityNompleted' event.
    • Events contain events for different entities along with additional fields such as fields, monitorChanges, filterExpression. For example: {"events": ["activityCreated", "inventoryCreated"], "fields" : "apptNumber" } is not valid, but {"events": ["activityCreated","inventoryCreated"]} is valid because there are no fields, monitorChanges, filterExpression elements.
  • subscriptionConfig elements/IDs/filterExpression string
    • filterExpression string is not a valid expression. (see 'filterExpression' field in the Subscription config request parameter).
    • filterExpression string contains fields or properties which do not exist "(doesNotExist == "something").
    • filterExpression string contains fields or properties for a wrong entity, for example, resource name in Activity event filter.
  • The subscriptionTitle is specified as an empty string or is longer than 255 characters.
  • 100 subscriptions are already active (either not deleted or expired).

Request

Body ()
Root Schema : Subscription
Type: object
Title: Subscription
The schema of the response body object for this operation.
Show Source
  • Subscription Config
    Title: Subscription Config
    The list of subscription config elements used to filter the required events.
  • Title: Subscription Title
    Minimum Length: 1
    Maximum Length: 255
    The title of the subscription. It can be used to distinguish a specific subscription from the other subscriptions. The field is optional and need not be unique.
Nested Schema : Subscription Config
Type: array
Title: Subscription Config
The list of subscription config elements used to filter the required events.
Show Source
  • Subscription Configuration Items
    Title: Subscription Configuration Items
    The array of subscription config item used to filter the events. For example, a config item can be used to filter activity events whereas another config item can be used to filter inventory events through the same subscription.
Nested Schema : Subscription Configuration Items
Type: object
Title: Subscription Configuration Items
The array of subscription config item used to filter the events. For example, a config item can be used to filter activity events whereas another config item can be used to filter inventory events through the same subscription.
Show Source
  • List of events
    Title: List of events
    The list of subscribed events.

    The following events are supported: activityCreated, activityUpdated, activityStarted, activityTravelStarted, activityTravelStopped, activitySuspended, activityCompleted, activityNotDone, activityCanceled, activityDeleted, activityDelayed, activityReopened, activityPreworkCreated, activityLinkCreated, activityLinkDeleted, resourcePreferenceCreated, resourcePreferenceDeleted, requiredInventoryCreated, requiredInventoryUpdated, requiredInventoryDeleted, inventoryInstalled, inventoryDeinstalled, customerInventoryCreated, customerInventoryUpdated, customerInventoryDeleted, inventoryUndoInstall, inventoryUndoDeinstall, activityMoved, routeCreated, routeUpdated, routeActivated, routeDeactivated, routeReactivated, customerRequestCreated, inventoryRequestCreated, resourceRequestCreated, chatMessageSent, chatUpdated, broadcastStatusUpdate, transactionUpdated, userCreated, userUpdated, userDeleted, resourceCreated, resourceUpdated, routingRun, formSubmitted.

  • Subscription Field List
    Title: Subscription Field List
    The list of fields and custom properties included in the event. The fields are added to the 'activityDetails' element for activity events, 'inventoryDetails' element for inventory events, and to the 'resourceDetails' element for the resource events.
    • The field names of the activity events are same as the field names retrieved from the 'Get activity' operation.
    • The field names of the inventory events are the same as the field names retrieved from the 'Get inventory' operation.
    • The field names of the resource events are the same as the field names retrieved from the 'Get resource' operation.
    • The field names of the user events are the same as the field names retrieved from the 'Get user' operation.

    Also, custom property labels can be specified along with the field names. Note that events API doesn't support file properties and has a limitation 5 kb for the maximum length of a custom property text. If some value exceeds this size and it should be present in the event, it will be truncated down to 5 kb and a warning message will be added at the end of the truncated value "TRUNCATED: Property value was > 5KB - too long to be published in full". Therefore, if no specific fields are specified, then by default only the changed and key fields are returned.

    The following events are supported:

    • Activity events
    • Inventory events
    • Resource events
    • User events

    The 'activityDeleted' event will not contain the specified 'country_code' field and the specified custom activity properties.

    Note: Please note that some events that are generated at the moment of the subscription creation (or up to a second after that) may be received for that subscription without the requested fields, as they might be generated just before the subscription configuration information is applied.

  • Title: Filter Expression

    The filter expression applied to the events. Only events matching the specified filter expression are added to the subscription.

    The following events are supported:

    • All activity events
    • All inventory events
    • All resource events
    • All user events

    Filter Expression Rules

    • Filter expression is specified as a single string.
    • It should evaluate to a boolean expression.
    • It should contain 1 or more comparison statements.
    • Syntax of comparison statements: field operator value, for example,activityDetails.activityType == 'Install'.
      • The order cannot be changed. Therefore, ('Install' == activityDetails.activityType) is not valid.
      • The comparison between fields, (A == B) or between values, (1 == 1) is also not valid.
      • The field has to be an alphanumeric identifier with no spaces or special characters, except underscore. Subfields are separated by dot (.) Examples:
        • activityDetails.activityType
        • activityDetails.X_MYPROP_10
        • user
        • field.subField
      • Comparison operators:
        • <
        • >
        • <=
        • >=
        • ==
        • !=
        • in
      • Value can either be a string literal, an integer literal, or an array literal of strings and integers.
        • String literals are delimited by single quotes, with escape character ~, for example:
          • str == 'My String'
          • str == 'My string with ~' a quote inside'
        • Integer literals are without quotes, may not contain dot, or leading zeroes. For example:
          • num == 0
          • num == 12345
          • num == -67/li>
        • Array literals should only contain strings or integers and should have square brackets. Empty arrays are not allowed. Arrays are only allowed after the "in" operator.
          • enum in [1,2,3]
          • enum in ['Abc','Def','Ghi']
      • String comparisons are valid:
        • date > '2015-06-02'
      • String comparisons are case-insensitive:
        • name == 'john.smith' is the same as name == 'JOHN.SMITH'
      • String to integer coercion is valid:
        • num == -123 is the same as num == '-123'
    • Multiple comparison statements have to be separated by logical operator and/or.
      • A == 1 and B == 2 or C == 3
      • A == 'xx' or A == 'yy'
    • Operator precedence:
      1. comparison operators: ==, !=, <, >, <=, >=, in
      2. 'not'
      3. 'and', 'or'
    • Logical operators ('and' / 'or') have the same precedence, so parentheses can be used to achieve precedence.
      • A == 1 and (B == 2 or C == 3)
    • Operators are also case-insensitive:
      • (num IN [1,2,3]) OR (num < 0)
    • Any statement can be preceded by "not" operator to negate it.
      • not (activityType in ['IN','TC','BR'])
      • A == 1 and not ( B == 2 or B == 3 )
    • Whitespace outside strings is ignored.

    • When the field being compared does not exist in the event or is null, then it evaluates to empty string. For example, expressions (non_existent_field == ''), (null_field == '').

  • Subscription Monitor Changes List
    Title: Subscription Monitor Changes List
    The list of fields for which the changes need to be tracked. If the 'monitorChanges' parameter is specified, then the event is only published to the subscription, if any of the fields listed in the parameter are changed. The valid values for the field depend on the value specified in the 'events' field.
    • If the activity events are specified in the 'events' field, then only the field names of the Activity object are returned.
    • If the inventory events are specified in the 'events' field, then only the field names of the Inventory object are returned.
    • If the resource events are specified in the 'events' field, then only the field names of the Resource object are returned.
    • If the user events are specified in the 'events' field, then only the field names of the User object are returned.
    • Custom property labels can also be specified along with the field names. Note that events API doesn't support file properties and has a limitation 5 kb for the maximum length of a custom property text. If some value exceeds this size and it should be present in the event, it will be truncated down to 5 kb and a warning message will be added at the end of the truncated value "TRUNCATED: Property value was > 5KB - too long to be published in full".

    The following events are supported:

    • Activity events
    • Inventory events
    • Resource events
    • User events
Nested Schema : List of events
Type: array
Title: List of events
The list of subscribed events.

The following events are supported: activityCreated, activityUpdated, activityStarted, activityTravelStarted, activityTravelStopped, activitySuspended, activityCompleted, activityNotDone, activityCanceled, activityDeleted, activityDelayed, activityReopened, activityPreworkCreated, activityLinkCreated, activityLinkDeleted, resourcePreferenceCreated, resourcePreferenceDeleted, requiredInventoryCreated, requiredInventoryUpdated, requiredInventoryDeleted, inventoryInstalled, inventoryDeinstalled, customerInventoryCreated, customerInventoryUpdated, customerInventoryDeleted, inventoryUndoInstall, inventoryUndoDeinstall, activityMoved, routeCreated, routeUpdated, routeActivated, routeDeactivated, routeReactivated, customerRequestCreated, inventoryRequestCreated, resourceRequestCreated, chatMessageSent, chatUpdated, broadcastStatusUpdate, transactionUpdated, userCreated, userUpdated, userDeleted, resourceCreated, resourceUpdated, routingRun, formSubmitted.

Show Source
  • Title: Event Type
    Allowed Values: [ "activityCreated", "activityUpdated", "activityStarted", "activityTravelStarted", "activityTravelStopped", "activitySuspended", "activityCompleted", "activityNotDone", "activityCanceled", "activityDeleted", "activityDelayed", "activityReopened", "activityPreworkCreated", "activityLinkCreated", "activityLinkDeleted", "resourcePreferenceCreated", "resourcePreferenceDeleted", "requiredInventoryCreated", "requiredInventoryUpdated", "requiredInventoryDeleted", "inventoryInstalled", "inventoryDeinstalled", "customerInventoryCreated", "customerInventoryUpdated", "customerInventoryDeleted", "inventoryUndoInstall", "inventoryUndoDeinstall", "activityMoved", "routeCreated", "routeUpdated", "routeActivated", "routeDeactivated", "routeReactivated", "customerRequestCreated", "inventoryRequestCreated", "resourceRequestCreated", "chatUpdated", "chatMessageSent", "userUpdated", "userCreated", "userDeleted", "resourceUpdated", "resourceCreated", "transactionUpdated", "resourceInventoryCreated", "resourceInventoryUpdated", "resourceInventoryDeleted", "routingRun", "broadcastStatusUpdate", "formSubmitted" ]
    The type of the event.
Nested Schema : Subscription Field List
Type: array
Title: Subscription Field List
The list of fields and custom properties included in the event. The fields are added to the 'activityDetails' element for activity events, 'inventoryDetails' element for inventory events, and to the 'resourceDetails' element for the resource events.
  • The field names of the activity events are same as the field names retrieved from the 'Get activity' operation.
  • The field names of the inventory events are the same as the field names retrieved from the 'Get inventory' operation.
  • The field names of the resource events are the same as the field names retrieved from the 'Get resource' operation.
  • The field names of the user events are the same as the field names retrieved from the 'Get user' operation.

Also, custom property labels can be specified along with the field names. Note that events API doesn't support file properties and has a limitation 5 kb for the maximum length of a custom property text. If some value exceeds this size and it should be present in the event, it will be truncated down to 5 kb and a warning message will be added at the end of the truncated value "TRUNCATED: Property value was > 5KB - too long to be published in full". Therefore, if no specific fields are specified, then by default only the changed and key fields are returned.

The following events are supported:

  • Activity events
  • Inventory events
  • Resource events
  • User events

The 'activityDeleted' event will not contain the specified 'country_code' field and the specified custom activity properties.

Note: Please note that some events that are generated at the moment of the subscription creation (or up to a second after that) may be received for that subscription without the requested fields, as they might be generated just before the subscription configuration information is applied.

Show Source
Nested Schema : Subscription Monitor Changes List
Type: array
Title: Subscription Monitor Changes List
The list of fields for which the changes need to be tracked. If the 'monitorChanges' parameter is specified, then the event is only published to the subscription, if any of the fields listed in the parameter are changed. The valid values for the field depend on the value specified in the 'events' field.
  • If the activity events are specified in the 'events' field, then only the field names of the Activity object are returned.
  • If the inventory events are specified in the 'events' field, then only the field names of the Inventory object are returned.
  • If the resource events are specified in the 'events' field, then only the field names of the Resource object are returned.
  • If the user events are specified in the 'events' field, then only the field names of the User object are returned.
  • Custom property labels can also be specified along with the field names. Note that events API doesn't support file properties and has a limitation 5 kb for the maximum length of a custom property text. If some value exceeds this size and it should be present in the event, it will be truncated down to 5 kb and a warning message will be added at the end of the truncated value "TRUNCATED: Property value was > 5KB - too long to be published in full".

The following events are supported:

  • Activity events
  • Inventory events
  • Resource events
  • User events
Show Source
Back to Top

Response

Supported Media Types

200 Response

Body ()
Root Schema : Subscription
Type: object
Title: Subscription
The subscription.
Show Source
  • Title: Next Page
    The next page identifier passed to the next request for obtaining the next series of events.

    There is no specification for the value format - it may be any string not longer than 48 characters.

  • Title: Subscription ID
    The identifier of the subscription.

Default Response

This section describes the default error response for this operation.
Body ()
Root Schema : Error
Type: object
Show Source
Back to Top

Examples

The following example shows how to create subscription by submitting a POST request on the REST resource.

Example of Request Header

The following shows an example of the resquest header.

POST /rest/ofscCore/v1/events/subscriptions HTTP/1.1
Connection: close
Accept-Encoding: gzip,deflate
Content-Type: application/json
Authorization: Basic bXlyb290QHFhNTUwMzox
Content-Length: 285
Host: <instance_name>.fs.ocs.oraclecloud.com
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

Example of Request Body

The following example shows the contents of the request body in JSON format.

{
    "subscriptionConfig":[
        {
            "events" : ["activityUpdated"],
            "filterExpression" : "(activityDetails.activityType in ['IN','TC','BR']) AND (user != 'my_integ') AND (activityDetails.customerName != '')",
            "monitorChanges" : [
                "DISPATCHER_COMMENTS",
                "WO_COMMENTS"
            ],
            "fields" : [
                "WO_COMMENTS",
                "DISPATCHER_COMMENTS",
                "timeSlot",
                "apptNumber",
                "resourceId",
                "resourceInternalId",
                "date",
                "status",
                "customerName",
                "streetAddress",
                "language",
                "masterActivityId"
            ]
        },
        {
            "events" : [
                "activityCompleted",
                "activityNotDone",
                "activityCanceled"
            ],
            "filterExpression" : "(activityDetails.activityType in ['IN','TC','BR']) AND (user != 'my_integ') AND (activityDetails.customerName != '')",
            "fields" : [
                "WO_COMMENTS",
                "DISPATCHER_COMMENTS",
                "apptNumber",
                "resourceId",
                "date",
                "status",
                "customerName",
                "streetAddress"
            ]
        }
    ]
}

Example of Response Header

The following shows an example of the response header.

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 25 Apr 2016 12:31:52 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: close

Example of Response Body

The following example shows the contents of the response body in JSON format.

{
    "subscriptionId": "4bbc02c8637e961ac88b4b0b38bbaad0f4401e17",
    "nextPage": "170725-3,0",
    "links": [
        {
            "rel": "describedby",
            "href": "https://<instance_name>.fs.ocs.oraclecloud.com/rest/ofscCore/v1/metadata-catalog/events"
        },
        {
            "rel": "canonical",
            "href": "https://<instance_name>.fs.ocs.oraclecloud.com/rest/ofscCore/v1/events/subscriptions/4bbc02c8637e961ac88b4b0b38bbaad0f4401e17"
        },
        {
            "rel": "data",
            "href": "https://<instance_name>.fs.ocs.oraclecloud.com/rest/ofscCore/v1/events/?subscriptionId=4bbc02c8637e961ac88b4b0b38bbaad0f4401e17&page=170725-3,0"
        }
    ]
}
Back to Top