Skip to content

Instantly share code, notes, and snippets.

@lbrenman
Last active April 14, 2021 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lbrenman/971fc7913de97e15bd0072dc9ede4eb4 to your computer and use it in GitHub Desktop.
Save lbrenman/971fc7913de97e15bd0072dc9ede4eb4 to your computer and use it in GitHub Desktop.
Amplify Central Integration Webhooks - Subscriber Notifier (assets)
{
"id": 49201,
"name": "AMPLIFY Central API Subscriber Emailer v2",
"debugLoggingExpires": "2021-04-06T03:45:57Z",
"userId": 21107,
"accountId": 18281,
"createdDate": "2021-04-05T19:39:34Z",
"steps": [{
"id": 508700,
"onSuccess": ["shouldProcess"],
"onFailure": [],
"name": "consoleLog",
"type": "script",
"properties": {
"body": "console.log(trigger);\n\ndone({});"
}
}, {
"id": 508701,
"onSuccess": ["setGlobals"],
"onFailure": [],
"name": "getAxwayAccessToken",
"type": "httpRequest",
"properties": {
"body": "${steps.prepAxwayAccessTokenRequest.form}",
"headers": "${steps.prepAxwayAccessTokenRequest.headers}",
"url": "https://login.axway.com/auth/realms/Broker/protocol/openid-connect/token",
"method": "POST"
}
}, {
"id": 508702,
"onSuccess": ["prepareGetSubscriptionsForCatalogItem"],
"onFailure": [],
"name": "getCatalogItemDetails",
"type": "httpRequest",
"properties": {
"headers": "${steps.setGlobals.globals.apiServerHeaders}",
"method": "GET",
"url": "${steps.prepareGetCatalogItemDetails.url}"
}
}, {
"id": 508703,
"onSuccess": ["loopOverCatalogItems"],
"onFailure": [],
"name": "getCatalogItems",
"type": "httpRequest",
"properties": {
"retry": "false",
"body": "${steps.prepareGetConsumerInstances.body}",
"headers": "${steps.setGlobals.globals.apiServerHeaders}",
"retryAttempts": "1",
"retryDelay": "500",
"url": "${steps.prepareGetCatalogItems.url}",
"method": "GET",
"form": ""
}
}, {
"id": 508704,
"onSuccess": ["prepareSendEmail"],
"onFailure": [],
"name": "getSubscriberDetails",
"type": "httpRequest",
"properties": {
"headers": "${steps.setGlobals.globals.apiServerHeaders}",
"method": "GET",
"url": "${steps.prepareGetSubscriberDetails.url}"
}
}, {
"id": 508705,
"onSuccess": ["loopOverSubscriptions"],
"onFailure": [],
"name": "getSubscriptionsForCatalogItem",
"type": "httpRequest",
"properties": {
"headers": "${steps.setGlobals.globals.apiServerHeaders}",
"method": "GET",
"url": "${steps.prepareGetSubscriptionsForCatalogItem.url}"
}
}, {
"id": 508706,
"onSuccess": ["prepareGetSubscriptionsForCatalogItem"],
"onFailure": [],
"name": "loopOverCatalogItems",
"type": "loop",
"properties": {
"list": "${steps.getCatalogItems.response.body}"
}
}, {
"id": 508707,
"onSuccess": ["prepareGetSubscriberDetails"],
"onFailure": ["loopOverCatalogItems"],
"name": "loopOverSubscriptions",
"type": "loop",
"properties": {
"list": "${steps.getSubscriptionsForCatalogItem.response.body}"
}
}, {
"id": 508708,
"onSuccess": ["getCatalogItemDetails"],
"onFailure": [],
"name": "prepareGetCatalogItemDetails",
"type": "script",
"properties": {
"body": "const url = steps.setGlobals.globals.apicentralUrl + '/api/unifiedCatalog/v1/catalogItems?pageSize=500&query=relationships.type==API_SERVER_CONSUMER_INSTANCE_ID;relationships.value=='+steps.loopOverCatalogItems.entry.metadata.id\n\ndone({url:url});"
}
}, {
"id": 508709,
"onSuccess": ["getCatalogItems"],
"onFailure": [],
"name": "prepareGetCatalogItems",
"type": "script",
"properties": {
"body": "const url = steps.setGlobals.globals.apicentralUrl + '/api/unifiedCatalog/v1/catalogItems?pageSize=500&query=relationships.type==API_SERVER_SERVICE_INSTANCE_ID;relationships.value=='+trigger.args.payload.metadata.id\n\ndone({url:url});"
}
}, {
"id": 508710,
"onSuccess": ["getSubscriberDetails"],
"onFailure": [],
"name": "prepareGetSubscriberDetails",
"type": "script",
"properties": {
"body": " const url = 'https://platform.axway.com/api/v1/user/'+steps.loopOverSubscriptions.entry.metadata.createUserId\n\ndone({url:url});"
}
}, {
"id": 508711,
"onSuccess": ["getSubscriptionsForCatalogItem"],
"onFailure": [],
"name": "prepareGetSubscriptionsForCatalogItem",
"type": "script",
"properties": {
"body": "const url = steps.setGlobals.globals.apicentralUrl + '/api/unifiedCatalog/v1/catalogItems/'+steps.loopOverCatalogItems.entry.id+'/subscriptions';\n\ndone({url:url});"
}
}, {
"id": 508712,
"onSuccess": ["sendEmail"],
"onFailure": [],
"name": "prepareSendEmail",
"type": "script",
"properties": {
"body": "let url = 'messages'\n\nlet message = '<p>Hi '+steps.getSubscriberDetails.response.body.result.firstname+',<br><br>Catalog Item <b><a href=\"'+steps.setGlobals.globals.apicentralUrl+'/catalog/explore/'+steps.loopOverCatalogItems.entry.id+'\"> '+steps.loopOverCatalogItems.entry.name+'</a></b> was updated for your subscription: <b><a href=\"'+steps.setGlobals.globals.apicentralUrl+'/catalog/'+steps.loopOverCatalogItems.entry.id+'/subscriptions/'+steps.loopOverSubscriptions.entry.id+'\"> '+steps.loopOverSubscriptions.entry.name+'</a>.</b><br><br>Best Regards,<br><a href=\"https://platform.axway.com\">Axway Amplify Platform</a>';\n\nlet body = {\n \"Subject\":\"Catalog item \"+steps.loopOverCatalogItems.entry.name+\" was updated\",\n \"Importance\":\"Normal\",\n \"Body\":{\n \"ContentType\":\"HTML\",\n \"Content\": message\n },\n \"ToRecipients\":[\n {\n \"EmailAddress\":{\n \"Address\":steps.getSubscriberDetails.response.body.result.email\n }\n }\n ]\n}\n\ndone({url:url, body:body})"
}
}, {
"id": 508713,
"onSuccess": ["getAxwayAccessToken"],
"onFailure": [],
"name": "prepAxwayAccessTokenRequest",
"type": "script",
"properties": {
"body": "\ndone({\n 'headers': { \n Authorization: 'Basic ' + CE.b64(config.axwayClientId + ':' + config.axwayClientSecret),\n 'Content-Type': 'application/x-www-form-urlencoded'\n },\n form: 'grant_type=client_credentials'\n});\n"
}
}, {
"id": 508714,
"onSuccess": ["loopOverSubscriptions"],
"onFailure": [],
"name": "sendEmail",
"type": "elementRequest",
"properties": {
"body": "${steps.prepareSendEmail.body}",
"api": "/${steps.prepareSendEmail.url}",
"elementInstanceId": "${config.email}",
"method": "POST"
}
}, {
"id": 508715,
"onSuccess": ["prepareGetCatalogItems"],
"onFailure": [],
"name": "setGlobals",
"type": "script",
"properties": {
"body": "let apiServerHeaders = {\n 'Authorization': `Bearer ${steps.getAxwayAccessToken.response.body.access_token}`,\n 'Content-Type': 'application/json'\n}\n\nlet apicentralUrl = config.apiCentralUrl ? config.apiCentralUrl : 'https://apicentral.axway.com';\n\nlet globals = {\n apicentralUrl: apicentralUrl,\n apiServerHeaders: apiServerHeaders\n}\n\ndone({globals});"
}
}, {
"id": 508716,
"onSuccess": ["prepAxwayAccessTokenRequest"],
"onFailure": [],
"name": "shouldProcess",
"type": "filter",
"properties": {
"body": "done(trigger.args.payload.kind === 'APIServiceInstance');"
}
}],
"triggers": [{
"id": 43726,
"onSuccess": ["shouldProcess"],
"onFailure": [],
"type": "manual",
"async": true,
"active": true,
"name": "trigger",
"properties": {}
}],
"engine": "v3",
"active": true,
"debugLoggingEnabled": false,
"singleThreaded": false,
"configuration": [{
"id": 89918,
"key": "apiCentralUrl",
"name": "apiCentralUrl",
"type": "value",
"required": false
}, {
"id": 89919,
"key": "axwayClientId",
"name": "axwayClientId",
"type": "value",
"required": true
}, {
"id": 89920,
"key": "axwayClientSecret",
"name": "axwayClientSecret",
"type": "value",
"required": true
}, {
"id": 89921,
"key": "email",
"name": "email",
"type": "elementInstance",
"required": true
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment