Test notification setup

You're viewing Apigee Edge documentation.
Go to the Apigee X documentation.
info

Introduction

Monetization provides a set of APIs that you can use to test your notification setup. Specifically, you can:

Testing webhooks

A webhook defines an HTTP callback handler that is triggered by an event. For information about setting up webhooks, see Set up notifications using webhooks.

You can test your webhooks by performing the following steps:

  1. View the available webhook notification trigger types
  2. View a sample request payload for webhook notification testing
  3. Test the execution of a webhook

Viewing the available webhook notification trigger types

View the available webhook notification trigger types by issuing a GET request to the following resource:

/organizations/{org_name}/webhooks/{webhook_id}/test/{developer_email_or_id}/{app_id}/{product_id}/{rateplan_id}

Where:

  • {org_name} specifies the name of the organization.
  • {webhook_id} specifies the ID of the webhook. To view a list of webhooks and obtain the webhook ID, see Viewing all webhooks using the API.
  • {developer_email_or_id} specifies the ID of the developer. To view a list of developers, see List Developers.
  • {app_id} specifies the ID of the application for which you are testing webhook triggering. To list the app IDs in your organization, see List App IDs in an Organization.
  • {product_id} specifies the ID of the API product for which you are testing webhook triggering. To view a list of API products for an organization, see List API Products.
  • {rateplan_id} specifies the ID of the rate plan for which you are testing webhook triggering. The rate plan ID is different from the display name. To view rate plan details including the ID, see Exploring the rate plans page.

For example, the following cURL call returns RATEPLANQUOTAUSAGE as the webhook notification trigger type.

curl -H "Content-Type: application/json" -X GET \ 
"https://api.enterprise.apigee.com/v1/mint/organizations/myorg/webhooks/0a07eb1f-f485-4539-8beb-01be449699b3/test/joe@example.com/e759c119-510c-49a8-886c-f184091944bd/myproduct/mypackage_anrp" \ 
-u email:password

The following provides an example of the response:

[
  "RATEPLANQUOTAUSAGE"
]

Next, you need to determine the schema for the request payload for the webhook notification trigger type.

Viewing a sample request payload for webhook notification testing

View a sample request payload that you can use for webhook notification testing by issuing a GET request to the following resource:

/organizations/{org_name}/webhooks/{webhook_id}/test/{developer_email_or_id}/{app_id}/{product_id}/{rateplan_id}/{trigger_type}

Where:

  • {org_name} specifies the name of the organization.
  • {webhook_id} specifies the ID of the webhook. To view a list of webhooks and obtain the webhook ID, see Viewing all webhooks using the API.
  • {developer_email_or_id} specifies the ID of the developer. To view a list of developers, see List Developers.
  • {app_id} specifies the ID of the application for which you are testing webhook triggering. To list the app IDs in your organization, see List App IDs in an Organization.
  • {product_id} specifies the ID of the API product for which you are testing webhook triggering. To view a list of API products for an organization, see List API Products.
  • {rateplan_id} specifies the ID of the rate plan for which you are testing webhook triggering. The rate plan ID is different from the display name. To view rate plan details including the ID, see Exploring the rate plans page.
  • {trigger_type} specifies the name of the webhook notification trigger type returned in the previous step (List the available webhook notification trigger types).

For example, the following cURL call returns a sample request payload for the RATEPLANQUOTAUSAGE webhook notification trigger type:

curl -H "Content-Type: application/json" -X GET \ 
"https://api.enterprise.apigee.com/v1/mint/organizations/myorg/webhooks/0a07eb1f-f485-4539-8beb-01be449699b3/test/joe@example.com/e759c119-510c-49a8-886c-f184091944bd/myproduct/mypackage_anrp/RATEPLANQUOTAUSAGE" \ 
-u email:password

The following provides a sample request payload:

{
   "eventTriggerReason": "RATEPLANQUOTAUSAGE",
   "properties": [
   {
        "key": "quotaPercentUsed",
        "value": "100"
   }
   ]
}

Next, you modify the sample request payload returned, as desired, and use it to test the execution of the webhook.

Testing the execution of a webhook

Test the execution of a webhook by issuing a POST request to the following resource:

/organizations/{org_name}/webhooks/{webhook_id}/test/{developer_email_or_id}/{app_id}/{product_id}/{rateplan_id}.

Where:

  • {org_name} specifies the name of the organization.
  • {webhook_id} specifies the ID of the webhook. To view a list of webhooks and obtain the webhook ID, see Viewing all webhooks using the API.
  • {developer_email_or_id} specifies the ID of the developer. To view a list of developers, see List Developers.
  • {app_id} specifies the ID of the application for which you are testing webhook triggering. To list the app IDs in your organization, see List App IDs in an Organization.
  • {product_id} specifies the ID of the API product for which you are testing webhook triggering. To view a list of API products for an organization, see List API Products.
  • {rateplan_id} specifies the ID of the rate plan for which you are testing webhook triggering. The rate plan ID is different from the display name. To view rate plan details including the ID, see Exploring the rate plans page.

Modify the sample request payload returned in the previous step (View a sample request payload for webhook notification testing) as desired, and pass it in the request payload.

For example, the following cURL call tests the execution of the specified webhook:

curl -H "Content-Type: application/json" -X POST -d \
'{
  "eventTriggerReason": "RATEPLANQUOTAUSAGE",
  "properties": [
    {
      "key": "quotaPercentUsed",
      "value": "120"
    }
  ]
}' \
"https://api.enterprise.apigee.com/v1/mint/organizations/myorg/webhooks/0a07eb1f-f485-4539-8beb-01be449699b3/test/joe@example.com/e759c119-510c-49a8-886c-f184091944bd/myproduct/mypackage_anrp" \ 
-u email:password

The following provides an example of the response indicating that the notification was sent successfully to the webhook:

{
  "original": {
    "createdDate": 1463619959930,
    "createdTimeStamp": 1463616000000,
    "notificationType": "WEBHOOK",
    "orgId": "myorg",
    "rawMessage": "{\"orgName\":\"myorg\",\"developerEmail\":\"joe@example.com\",\"developerFirstName\":\"Joe\",\"developerLastName\":\"Smith\",\"applicationName\":\"myapp\",\"packageName\":\"MyPackage\",\"packageId\":\"mypackage\",\"ratePlanId\":\"mypackage_anrp\",\"ratePlanName\":\"anrp\",\"ratePlanType\":\"STANDARD\",\"developerRatePlanQuotaTarget\":200,\"quotaPercentUsed\":\"120\",\"ratePlanStartDate\":1463616000000,\"ratePlanEndDate\":null,\"nextBillingCycleStartDate\":null,\"products\":[\"myproduct\"],\"developerCustomAttributes\":[]\"triggerTime\":1463619959929,\"triggerReason\":\"RATEPLANQUOTAUSAGE\",\"developerQuotaResetDate\":null}",
    "retryCount": 0,
    "retryStatuses": [],
    "source": "MailTo: [36112720-1304-4e0b-9b17-991f5e121ebb], Org: [myorg], TransactionId: [], LimitId: [], Key: []",
    "toEmail": "http://123.45.67.89/webhook",
    "updatedDate": 1463619959930
  },
  "raw": "This is the response",
  "responseCode": 200,
  "status": "NOTIFICATION_SENT"
}

Viewing and reprocessing notifications

Monetization enables you to set up notifications that are triggered by specific events. For information about setting up notifications, see Set up notifications

For each notification sent, the following information is stored:

  • Retry count
  • Response code
  • Response header
  • Response content (first 1000 characters only)

You can view and reprocess notifications by performing the following steps:

  1. View the notifications that have been sent
  2. View details for a notification
  3. Reprocess a notification

Viewing the notifications sent

View the notifications that have been sent for an organization by issuing a GET request to the following resource:

/organizations/{org_name}/notification-service-items

Where {org_name} specifies the name of the organization.

Optionally, you can specify one or more of the following query parameters to filter the list of notifications returned in the response:

Query Parameter Description
startdate Start date in the format YYYY-MM-DD HH:mm:ss.
enddate End date in the format YYYY-MM-DD HH:mm:ss.
status Status of the notifications. Valid values include:
  • BLANK_MESSAGE
  • DUPLICATE
  • FAILED
  • NOTIFICATION_SENT
  • OPT_OUT
  • QUEUED
  • TEMPLATE_NOT_FOUND
toemail Email ID or webhook to which the notification was sent.

A maximum of 1000 notifications are returned.

In the response, the hasMoreItems flag indicates whether the number of notifications in the specified list amounts to more than 1000. If hasMoreItems is true, indicating that there are more notifications than could be displayed, and you would like to view the remaining notifications, you need to refine your query parameter filters to process smaller groups of notifications per request. For example, you might make multiple requests using several smaller date ranges, or return notifications with only certain status values.

For example, the following cURL call lists the notifications that FAILED for the specified webhook within the specified range of dates:

curl -H "Content-Type: application/json" -X GET \ 
"https://api.enterprise.apigee.com/v1/mint/organizations/myorg/notification-service-items?enddate=2016-05-19 12:00:00&startdate=2016-05-18 12:00:00&status=FAILED&toemail=http://123.45.6789:8000/webhook" \ 
-u email:password 

The following provides an example of the response:

 {
   "hasMoreItems": false,
   "notifications": [
   { 
      "createdDate": 1463626865974, 
      "createdTimeStamp": 1463616000000, 
      "id": "9d87c6ea-1394-495b-bfb7-1d2e7ef3f837", 
      "notificationType": "WEBHOOK", 
      "orgId": "Org_d40f6c2e-1d6d-11e6-a4ed-af8444f24e4f", 
      "rawMessage": "{\"orgName\":\"Org_d40f6c2e-1d6d-11e6-a4ed-af8444f24e4f\",\"developerEmail\":\"joe@example.com\",\"developerFirstName\":\"Joe\",\"developerLastName\":\"Smith\",\"applicationName\":\"MyApp\",
\"packageName\":\"test-package\",\"packageId\":\"myorg@@@test-package-9ubo\",\"ratePlanId\":\"myorg@@@test-package-9ubo_anrp\",\"ratePlanName\":\"anrp\",\"ratePlanType\":\"STANDARD\",
\"developerRatePlanQuotaTarget\":10,\"quotaPercentUsed\":\"20\",\"ratePlanStartDate\":1463616000000,\"ratePlanEndDate\":null,\"nextBillingCycleStartDate\":1464739200000,\"products\":[\"product1\"],
\"developerCustomAttributes\":[],\"triggerTime\":1463626865907,\"triggerReason\":\"RatePlanQuotaUsage\",\"developerQuotaResetDate\":\"1464810145000\"}", 
      "retryCount": 3, 
      "retryStatuses": [ 
      { 
         "responseCode": 500, 
         "responseMessage": "{\"Headers\":\"[{\"name\":\"Content-length\",\"buffer\":{\"empty\":false,\"full\":false},\"valuePos\":15,\"value\":\"20\",\"elements\":[{\"name\":\"20\",\"value\":null,\"parameters\":[],\"parameterCount\":0}]},{\"name\":\"Date\",\"buffer\":{\"empty\":false,\"full\":false},\"valuePos\":5,\"value\":\"Thu, 19 May 2016 03:01:09 GMT\",\"elements\":[{\"name\":\"Thu\",\"value\":null,\"parameters\":[],\"parameterCount\":0},{\"name\":\"19 May 2016 03:01:09 GMT\",\"value\":null,\"parameters\":[],\"parameterCount\":0}]}]\",\"StatusCode\":\"500\",\"Content : \":\"This is the response\"}", 
         "retriedAt": 1463626869184,
         "retryAttempt": 1 
      }, 
      { 
         "responseCode": 500, 
         "responseMessage": "{\"Headers\":\"[{\"name\":\"Content-length\",\"buffer\":{\"empty\":false,\"full\":false},\"valuePos\":15,\"value\":\"20\",\"elements\":[{\"name\":\"20\",\"value\":null,\"parameters\":[],\"parameterCount\":0}]},{\"name\":\"Date\",\"buffer\":{\"empty\":false,\"full\":false},\"valuePos\":5,\"value\":\"Thu, 19 May 2016 03:01:09 GMT\",\"elements\":[{\"name\":\"Thu\",\"value\":null,\"parameters\":[],\"parameterCount\":0},{\"name\":\"19 May 2016 03:01:09 GMT\",\"value\":null,\"parameters\":[],\"parameterCount\":0}]}]\",\"StatusCode\":\"500\",\"Content : \":\"This is the response\"}", 
         "retriedAt": 1463626869318, 
         "retryAttempt": 2 
      }, 
      { 
         "responseCode": 500, 
         "responseMessage": "{\"Headers\":\"[{\"name\":\"Content-length\",\"buffer\":{\"empty\":false,\"full\":false},\"valuePos\":15,\"value\":\"20\",\"elements\":[{\"name\":\"20\",\"value\":null,\"parameters\":[],\"parameterCount\":0}]},{\"name\":\"Date\",\"buffer\":{\"empty\":false,\"full\":false},\"valuePos\":5,\"value\":\"Thu, 19 May 2016 03:01:09 GMT\",\"elements\":[{\"name\":\"Thu\",\"value\":null,\"parameters\":[],\"parameterCount\":0},{\"name\":\"19 May 2016 03:01:09 GMT\",\"value\":null,\"parameters\":[],\"parameterCount\":0}]}]\",\"StatusCode\":\"500\",\"Content : \":\"This is the response\"}", 
         "retriedAt": 1463626869378, 
         "retryAttempt": 3 
      } 
      ], 
      "source": "MailTo: [6c3cde37-a8f1-4077-adbe-e9f6605a7299], Org: [myorg], TransactionId: [b8d763be-7185-450d-b421-df38c870fabd], LimitId: [RatePlan-Limit:myorg@@@test-package-9ubo_anrp], Key: [myorg@@@kjGSxEGtZeekBEyI~myorg@@@test-package-9ubo_anrp~Transactions~Calls~20]", 
      "status": "FAILED", 
      "toEmail": "http://123.45.67.89:8000/webhook", 
      "updatedDate": 1463626865974 
   } 
   ] 
}

Viewing details for a notification

View the details for a specific notification by issuing a GET request to the following resource:

/organizations/{org_name}/notification-service-items/{notification_id}

Where:

  • {org_name} specifies the name of the organization.
  • {notification_id} specifies the ID of the notification for which you want to display details. You can obtain the notification ID from the response output when viewing the notifications sent.

For example, the following cURL call lists details for the notification with the ID 4b3dfadf-3a96-4a92-9512-1feff22f74f3:

curl -H "Content-Type: application/json" -X GET \ 
"https://api.enterprise.apigee.com/v1/mint/organizations/myorg/notification-service-items/faa8e6a8-754e-40e8-9e0c-4dee6c9aca23" \ 
-u email:password
 

The following provides an example of the response:

 {
  "createdDate": 1461062402871,
  "createdTimeStamp": 1461024000000,
  "id": "faa8e6a8-754e-40e8-9e0c-4dee6c9aca23",
  "notificationType": "WEBHOOK",
  "orgId": "myorg",
  "rawMessage": "{\"orgName\":\"myorg\",\"developerEmail\":\"joe@example.com\",\"developerFirstName\":\"Joe\",\"developerLastName\":\"Smith\",\"applicationName\":\"myapp\",\"packageName\":\"mypackage\",\"ratePlanName\":\"anrp\",\"ratePlanType\":\"STANDARD\",\"developerRatePlanQuotaTarget\":54000,\"quotaPercentUsed\":\"1\",\"ratePlanStartDate\":1460419200000,\"ratePlanEndDate\":null,\"nextBillingCycleStartDate\":null,\"products\":[\"myproduct\"],\"developerCustomAttributes\":[],\"triggerTime\":1461062395966,\"triggerReason\":\"RatePlanQuotaUsage\"}",
  "retryCount": 0,
  "retryStatuses": [],
  "source": "MailTo: [c9e42fcd-9632-4376-b92d-0fa27f178a3b], Org: [myorg], TransactionId: [0352e568-2724-42d9-a264-1b62586d5948], LimitId: [RatePlan-Limit:amyorg@@@mypackage-a0y9_anrp], Key: [myorg@@@PPXsQbkyO1bBhQOh~myorg@@@mypackage-a0y9_anrp~Transactions~Calls~1]",
  "status": "NOTIFICATION_SENT",
  "toEmail": "http://123.45.67.89:8000/webhook",
  "updatedDate": 1461062402871
}

Reprocessing a notification

Reprocess a notification by issuing a POST request to the following resource:

/organizations/{org_name}/notification-service-items/{notification_id}/reprocess

Where:

  • {org_name} specifies the name of the organization.
  • {notification_id} specifies the ID of the notification item for which you want to display details. You can obtain the notification ID from the response output when viewing the notifications sent.

For example, the following cURL call reprocesses the notification with ID 4b3dfadf-3a96-4a92-9512-1feff22f74f3:

curl -H "Content-Type: application/json" -X POST \ 
"https://api.enterprise.apigee.com/v1/mint/organizations/myorg/notification-service-items/faa8e6a8-754e-40e8-9e0c-4dee6c9aca23/reprocess" \ 
-u email:password
 
{
  "createdDate": 1461062402871,
  "createdTimeStamp": 1461024000000,
  "id": "faa8e6a8-754e-40e8-9e0c-4dee6c9aca23",
  "notificationType": "WEBHOOK",
  "orgId": "myorg",
  "rawMessage": "{\"orgName\":\"myorg\",\"developerEmail\":\"joe@example.com\",\"developerFirstName\":\"Joe\",\"developerLastName\":\"Smith\",\"applicationName\":\"myapp\",\"packageName\":\"mypackage\",\"ratePlanName\":\"anrp\",\"ratePlanType\":\"STANDARD\",\"developerRatePlanQuotaTarget\":54000,\"quotaPercentUsed\":\"1\",\"ratePlanStartDate\":1460419200000,\"ratePlanEndDate\":null,\"nextBillingCycleStartDate\":null,\"products\":[\"myproduct\"],\"developerCustomAttributes\":[],\"triggerTime\":1461062395966,\"triggerReason\":\"RatePlanQuotaUsage\"}",
  "retryCount": 0,
  "retryStatuses": [
    {
      "responseCode": 200,
      "responseMessage": "{\"Headers\":\"[{\"name\":\"Accept-Encoding\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":16,\"elements\":[{\"name\":\"gzip\",\"value\":null,\"parameters\":[],\"parameterCount\":0},{\"name\":\"deflate\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"gzip,deflate\"},{\"name\":\"Content-Type\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":13,\"elements\":[{\"name\":\"application/json\",\"value\":null,\"parameters\":[{\"name\":\"charset\",\"value\":\"UTF-8\"}],\"parameterCount\":1}],\"value\":\"application/json; charset=UTF-8\"},{\"name\":\"Date\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":5,\"elements\":[{\"name\":\"Mon\",\"value\":null,\"parameters\":[],\"parameterCount\":0},{\"name\":\"23 May 2016 21:46:37 GMT\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"Mon, 23 May 2016 21:46:37 GMT\"},{\"name\":\"Server\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":7,\"elements\":[{\"name\":\"Apigee Router\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"Apigee Router\"},{\"name\":\"User-Agent\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":11,\"elements\":[{\"name\":\"Apache-HttpClient/4.3.5 (java 1.5)\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"Apache-HttpClient/4.3.5 (java 1.5)\"},{\"name\":\"X-Forwarded-For\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":16,\"elements\":[{\"name\":\"54.200.58.80\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"54.200.58.80\"},{\"name\":\"X-Forwarded-Port\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":17,\"elements\":[{\"name\":\"80\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"80\"},{\"name\":\"X-Forwarded-Proto\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":18,\"elements\":[{\"name\":\"http\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"http\"},{\"name\":\"Content-Length\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":15,\"elements\":[{\"name\":\"1173\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"1173\"},{\"name\":\"Connection\",\"buffer\":{\"full\":false,\"empty\":false},\"valuePos\":11,\"elements\":[{\"name\":\"keep-alive\",\"value\":null,\"parameters\":[],\"parameterCount\":0}],\"value\":\"keep-alive\"}]\",\"StatusCode\":\"200\",\"Content : \":\"{\"orgName\":\"myorg\",\"developerEmail\":\"joe@example.com\",\"developerFirstName\":\"Joe\",\"developerLastName\":\"Smith\",\"applicationName\":\"MyApp\",\"packageName\":\"mypackage\",\"ratePlanName\":\"anrp\",\"ratePlanType\":\"STANDARD\",\"developerRatePlanQuotaTarget\":54000,\"quotaPercentUsed\":\"1\",\"ratePlanStartDate\":1460419200000,\"ratePlanEndDate\":null,\"nextBillingCycleStartDate\":null,\"products\":[\"product1\"],\"developerCustomAttributes\":[],
  "source": "MailTo: [c9e42fcd-9632-4376-b92d-0fa27f178a3b], Org: [myorg], TransactionId: [0352e568-2724-42d9-a264-1b62586d5948], LimitId: [RatePlan-Limit:amyorg@@@mypackage-a0y9_anrp], Key: [myorg@@@PPXsQbkyO1bBhQOh~myorg@@@mypackage-a0y9_anrp~Transactions~Calls~1]",
  "status": "NOTIFICATION_SENT",
  "toEmail": "http://123.45.67.89:8000/webhook",
  "updatedDate": 1461062402871
}