Subscriptions Api Calls
[PUT] Manage Subscriptions - Create subscriptions
This request creates a new subscription in a project with a PUT request
Request
PUT /v1/projects/{project_name}/subscriptions/{subscription_name}
Where
- Project_name: Name of the project to create
- subscription_name: The subscription name to create
Example request
curl -X PUT -H "Content-Type: application/json" -H "x-api-key: S3CR3T" -d 'PUTBODY'
"https://{URL}/v1/projects/BRAND_NEW/subscriptions/alert_engine"
PUT BODY
{
"topic": "projects/BRAND_NEW/topics/monitoring",
"ackDeadlineSeconds": 10
}
Responses
Success Response
200 OK
{
"name": "projects/BRAND_NEW/subscriptions/alert_engine",
"topic": "projects/BRAND_NEW/topics/monitoring",
"ackDeadlineSeconds": 10,
"createdOn": "2020-11-19T00:00:00Z"
}
Push Enabled Subscriptions
Whenever a subscription is created with a valid push configuration, the service will also generate a unique hash that should be later used to validate the ownership of the registered push endpoint, and will mark the subscription as unverified.
The type
field specifies what kind of push subscription the service will handle.
The http_endpoint
type is about subscriptions that will forward their messages
to remote http endpoints. The mattermost
type is about subscriptions that will
forward their messages to mattermost channels through a mattermost webhook.
The maxMessages
field declares the number of messages that should be sent per
push action. The default value is 1
. If maxMessages
holds a value of 1
your
push endpoint should expect a request body with the following schema:
The base64Decode
field indicates that the push mechanism should
decode each message before sending it to the remote destination.
{
"message": {
"attributes": {
"key": "value"
},
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
If the maxMessages
field holds a value of greater than 1
your push endpoint
should expect a request body with the following schema:
{
"messages": [
{
"message": {
"attributes": {
"key": "value"
},
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
},
{
"message": {
"attributes": {
"key": "value"
},
"data": "SGVsbG8gQ2xvdWQgUHViL1N1YiEgSGVyZSBpcyBteSBtZXNzYWdlIQ==",
"messageId": "136969346945"
},
"subscription": "projects/myproject/subscriptions/mysubscription"
}
]
}
Request to create Push Enabled Subscription for http_endpoint
{
"topic": "projects/BRAND_NEW/topics/monitoring",
"ackDeadlineSeconds": 10,
"pushConfig": {
"type": "http_endpoint",
"pushEndpoint": "https://127.0.0.1:5000/receive_here",
"maxMessages": 3,
"retryPolicy": {
"type": "linear",
"period": 1000
}
}
}
Response
{
"name": "projects/BRAND_NEW/subscriptions/alert_engine",
"topic": "projects/BRAND_NEW/topics/monitoring",
"ackDeadlineSeconds": 10,
"pushConfig": {
"pushEndpoint": "https://127.0.0.1:5000/receive_here",
"maxMessages": 3,
"authorizationHeader": {
"type": "autogen",
"value": "4551h9j7f7dde380a5f8bc4fdb4fe980c565b67b"
},
"retryPolicy": {
"type": "linear",
"period": 1000
},
"verificationHash": "9d5189f7f758e380a5f8bc4fdb4fe980c565b67b",
"verified": false,
"mattermostUrl": "",
"mattermostUsername": "",
"mattermostChannel": ""
},
"createdOn": "2020-11-19T00:00:00Z"
}
Request to create Push Enabled Subscription for mattermost
{
"topic": "projects/BRAND_NEW/topics/monitoring",
"ackDeadlineSeconds": 10,
"pushConfig": {
"type": "mattermost",
"mattermostUrl": "webhook.com",
"mattermostUsername": "mattermost",
"mattermostChannel": "channel",
"retryPolicy": {
"type": "linear",
"period": 1000
}
}
}
Response
{
"name": "projects/BRAND_NEW/subscriptions/alert_engine",
"topic": "projects/BRAND_NEW/topics/monitoring",
"ackDeadlineSeconds": 10,
"pushConfig": {
"pushEndpoint": "",
"maxMessages": 1,
"retryPolicy": {
"type": "linear",
"period": 1000
},
"verificationHash": "",
"verified": true,
"mattermostUrl": "webhook.com",
"mattermostUsername": "mattermost",
"mattermostChannel": "channel"
},
"createdOn": "2020-11-19T00:00:00Z"
}
Authorization headers
Specify an authorization header
value and how it is going to be generated,
to be included in the outgoing push request with each message, to the remote
push endpoint.
autogen(default)
: The authorization header value will be automatically generated by the service itself.disabled
: No authorization header will be provided with the outgoing push requests.
Different Retry Policies
Creating a push enabled subscription with a linear
retry policy and a period
of 3000 means that you will be
receiving
message(s) every 3000ms
.
If you decide to choose a retry policy of slowstart
, you will be receiving messages with dynamic internals.
The slowstart
retry policy starts by pushing the first message(s) and then deciding the time that should elapse
before the next push action.
-
IF
the message(s) are delivered successfully the elapsed time until the next push request will be halved, until it reaches the lower limit of300ms
. -
IF
the message(s) are not delivered successfully the elapsed time until the next push request will be doubled, until it reached the upper limit of1day
.
So for example, the first push action will have by default a 1 second
interval. If it successful the next push re
request will
happen in 0.5 seconds
. If it is unsuccessful the next push request will happen in 2 seconds
.
Errors
Please refer to section Errors to see all possible Errors
[POST] Manage Subscriptions - Verify ownership of a push endpoint
This request triggers the process of verifying the ownership of a registered push endpoint
Request
POST /v1/projects/{project_name}/subscriptions/{subscription_name}:verifyPushEndpoint
Where
- Project_name: Name of the project
- subscription_name: The subscription name
Example request
curl -X POST -H "x-api-key: S3CR3T"
"https://{URL}/v1/projects/BRAND_NEW/subscriptions/alert_engine:verifyPushEndpoint"`
Whenever a subscription is created with a valid push configuration, the service will also generate a unique hash that should be later used to validate the ownership of the registered push endpoint, and will mark the subscription as unverified.
The owner of the push endpoint needs to execute the following steps in order to verify the ownership of the registered endpoint.
-
Open an api call with a path of
/ams_verificationHash
. The service will try to access this path using thehost:port
of the push endpoint. For example, if the push endpoint ishttps://example.com:8443/receive_here
, the push endpoint should also support the api route ofhttps://example.com:8443/ams_verificationHash
. -
The api route of
https://example.com:8443/ams_verificationHash
should support the httpGET
method. -
A
GET
request tohttps://example.com:8443/ams_verificationHash
should return a response body with only theverificationHash
that is found inside the subscriptions push configuration, astatus code
of200
and the headerContent-type: plain/text
.
Errors
Please refer to section Errors to see all possible Errors
[GET] Manage Subscriptions - List All Subscriptions under a specific Topic
This request lists all available subscriptions under a specific topic in the service.
Request
GET /v1/projects/{project_name}/topics/{topic_name}/subscriptions
Where
- Project_name: Name of the project the topic belongs to
- Topic_name: Name of the topic
Example request
curl -X GET -H "Content-Type: application/json" -H "x-api-key: S3CR3T"
"https://{URL}/v1/projects/p1/topics/t1/subscriptions"
Success Response
200 OK
{
"subscriptions": [
"/projects/p1/subscriptions/sub1",
"/projects/p1/subscriptions/sub2"
]
}
Errors
Please refer to section Errors to see all possible Errors
[GET] Manage Subscriptions - List All Subscriptions
This request lists all available subscriptions under a specific project in the service using pagination
If the USER
making the request has only consumer
role for the respective project, it will load
only the subscriptions that he has access to(being present in a subscriptions's acl).
It is important to note that if there are no results to return the service will return the following:
Success Response
200 OK
{
"subscriptions": [],
"nextPageToken": "",
"totalSize": 0
}
Also the default value for pageSize = 0
and pageToken = "
.
Pagesize = 0
returns all the results.