Last active
April 14, 2021 14:27
-
-
Save lbrenman/50421d1310aed9686616592e83658eac to your computer and use it in GitHub Desktop.
AMPLIFY Central Connected Gateway Custom API Subscription Approval Flow - CRM Contact Check Flow (Assets)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": 43284, | |
"name": "AMPLIFY Central SFDC Contact Exists Check Subscription Flow", | |
"debugLoggingExpires": "2021-01-19T23:21:47Z", | |
"userId": 21107, | |
"accountId": 18281, | |
"createdDate": "2021-01-15T18:19:33Z", | |
"steps": [{ | |
"id": 467026, | |
"onSuccess": ["loopSubscriptions"], | |
"onFailure": [], | |
"name": "addCRMUserNote", | |
"type": "elementRequest", | |
"properties": { | |
"body": "${steps.prepareAddCRMUserNote.body}", | |
"api": "/${steps.prepareAddCRMUserNote.url}", | |
"elementInstanceId": "${config.crm}", | |
"method": "POST" | |
} | |
}, { | |
"id": 467566, | |
"onSuccess": ["prepareAddCRMUserNote"], | |
"onFailure": ["loopSubscriptions"], | |
"name": "contactExists", | |
"type": "filter", | |
"properties": { | |
"body": "let contactExists = steps.getCRMUser.response.body.length>0;\n\ndone(contactExists);" | |
} | |
}, { | |
"id": 466702, | |
"onSuccess": ["prepareUpdateSubscriptionRequest"], | |
"onFailure": ["prepareSendToTeams"], | |
"name": "contactExistsOrIsWhitelisted", | |
"type": "filter", | |
"properties": { | |
"body": "let contactExists = steps.getCRMUser.response.body.length>0;\n\nlet isWhitelisted = config.whitelist.includes(steps.getUser.response.body.result.email.split('@')[1])\n\ndone(contactExists || isWhitelisted);" | |
} | |
}, { | |
"id": 466627, | |
"onSuccess": ["prepareGetRequestedSubscriptions"], | |
"onFailure": [], | |
"name": "defineGlobals", | |
"type": "script", | |
"properties": { | |
"body": "let apicentralUrl = config.apiCentralUrl ? config.apiCentralUrl : 'https://apicentral.axway.com';\n\nconfig.apiCentralUrl = apicentralUrl;\n\nlet apiServerHeaders = {\n 'Authorization': `Bearer ${steps.getAxwayAccessToken.response.body.access_token}`,\n 'Content-Type': 'application/json'\n}\n\n// config.apiServerHeaders = apiServerHeaders;\n\nlet globalVars = {\n apiServerHeaders: apiServerHeaders\n}\n\ndone({globalVars});" | |
} | |
}, { | |
"id": 466622, | |
"onSuccess": ["defineGlobals"], | |
"onFailure": [], | |
"name": "getAxwayAccessToken", | |
"type": "httpRequest", | |
"properties": { | |
"body": "${steps.prepAxwayAccessTokenRequest.form}", | |
"headers": "${steps.prepAxwayAccessTokenRequest.headers}", | |
"method": "POST", | |
"url": "https://login.axway.com/auth/realms/Broker/protocol/openid-connect/token" | |
} | |
}, { | |
"id": 466708, | |
"onSuccess": ["prepareGetUser"], | |
"onFailure": [], | |
"name": "getCatalogItem", | |
"type": "httpRequest", | |
"properties": { | |
"headers": "${steps. defineGlobals.globalVars.apiServerHeaders}", | |
"method": "GET", | |
"url": "${steps.prepareGetCatalogItem.url}" | |
} | |
}, { | |
"id": 466637, | |
"onSuccess": ["contactExistsOrIsWhitelisted"], | |
"onFailure": [], | |
"name": "getCRMUser", | |
"type": "elementRequest", | |
"properties": { | |
"api": "/${steps.prepareGetCRMUser.url}", | |
"query": "", | |
"elementInstanceId": "${config.crm}", | |
"method": "GET" | |
} | |
}, { | |
"id": 466628, | |
"onSuccess": ["loopSubscriptions"], | |
"onFailure": [], | |
"name": "getRequestedSubscriptions", | |
"type": "httpRequest", | |
"properties": { | |
"headers": "${steps. defineGlobals.globalVars.apiServerHeaders}", | |
"method": "GET", | |
"url": "${steps.prepareGetRequestedSubscriptions.url}" | |
} | |
}, { | |
"id": 466633, | |
"onSuccess": ["prepareGetCRMUser"], | |
"onFailure": [], | |
"name": "getUser", | |
"type": "httpRequest", | |
"properties": { | |
"headers": "${steps. defineGlobals.globalVars.apiServerHeaders}", | |
"method": "GET", | |
"url": "${steps.prepareGetUser.url}" | |
} | |
}, { | |
"id": 466630, | |
"onSuccess": ["prepareGetCatalogItem"], | |
"onFailure": [], | |
"name": "loopSubscriptions", | |
"type": "loop", | |
"properties": { | |
"list": "${steps.getRequestedSubscriptions.response.body}" | |
} | |
}, { | |
"id": 467025, | |
"onSuccess": ["addCRMUserNote"], | |
"onFailure": [], | |
"name": "prepareAddCRMUserNote", | |
"type": "script", | |
"properties": { | |
"body": "// console.log(steps.getCRMUser.response.body);\n\nlet url = 'contacts/'+steps.getCRMUser.response.body[0].Id+'/notes';\n\nlet bodyText = 'Subscription request, \"'+steps.loopSubscriptions.entry.name+'\" for API: '+steps.getCatalogItem.response.body.name+' was approved via subscription flow. The subscription can be viewed here: \\n\\n'+config.apiCentralUrl+'/catalog/'+steps.loopSubscriptions.entry.catalogItemId+'/subscriptions/'+steps.loopSubscriptions.entry.id;\n\nconsole.log(bodyText);\n\nlet body = {\n Title: 'API Subscription Approved',\n Body: bodyText\n};\n\ndone({url:url, body:body});" | |
} | |
}, { | |
"id": 466707, | |
"onSuccess": ["getCatalogItem"], | |
"onFailure": [], | |
"name": "prepareGetCatalogItem", | |
"type": "script", | |
"properties": { | |
"body": "let url = config.apiCentralUrl+'/api/unifiedCatalog/v1/catalogItems/'+steps.loopSubscriptions.entry.catalogItemId;\n\ndone({url:url});" | |
} | |
}, { | |
"id": 466636, | |
"onSuccess": ["getCRMUser"], | |
"onFailure": [], | |
"name": "prepareGetCRMUser", | |
"type": "script", | |
"properties": { | |
"body": "let url = \"contacts?where=Email='\"+steps.getUser.response.body.result.email+\"'\";\n\n\n\ndone({url:url});" | |
} | |
}, { | |
"id": 466629, | |
"onSuccess": ["getRequestedSubscriptions"], | |
"onFailure": [], | |
"name": "prepareGetRequestedSubscriptions", | |
"type": "script", | |
"properties": { | |
"body": "let url = config.apiCentralUrl+'/api/unifiedCatalog/v1/subscriptions?query=state==REQUESTED' // REQUESTED\n\ndone({url:url})" | |
} | |
}, { | |
"id": 466635, | |
"onSuccess": ["getUser"], | |
"onFailure": [], | |
"name": "prepareGetUser", | |
"type": "script", | |
"properties": { | |
"body": "done({url:'https://platform.axway.com/api/v1/user/'+steps.loopSubscriptions.entry.metadata.createUserId});" | |
} | |
}, { | |
"id": 466703, | |
"onSuccess": ["sendToTeams"], | |
"onFailure": [], | |
"name": "prepareSendToTeams", | |
"type": "script", | |
"properties": { | |
"body": "let url = config.msTeamsWebhookURL;\n\nlet subscriptionUrl = config.apiCentralUrl+'/catalog/'+steps.loopSubscriptions.entry.catalogItemId+'/subscriptions/'+steps.loopSubscriptions.entry.id;\n\nlet body = {\n \"@type\": \"MessageCard\",\n \"@context\": \"http://schema.org/extensions\",\n \"themeColor\": \"0076D7\",\n \"summary\": \"API Subscription Request\",\n \"sections\": [{\n \"activityTitle\": \"[\"+steps.loopSubscriptions.entry.name+\"](\"+subscriptionUrl+\")\",\n \"activitySubtitle\": \"API: \"+steps.getCatalogItem.response.body.name,\n \"facts\": [{\n \"name\": \"Name:\",\n \"value\": steps.getUser.response.body.result.firstname + ' ' + steps.getUser.response.body.result.lastname\n },{\n \"name\": \"Email:\",\n \"value\": steps.getUser.response.body.result.email\n }],\n \"text\": \"API subscriber not found in Salesforce Contacts. Please add the following subscriber to [Salesforce](https://www.salesforce.com) and the API subscription request will be approved.\",\n \"markdown\": true\n }],\n \"potentialAction\": [\n {\n \t\t\t\"@type\": \"OpenUri\",\n \t\t\t\"name\": \"View Subscription\",\n \t\t\t\"targets\": [\n \t\t\t\t{\n \t\t\t\t\t\"os\": \"default\",\n \t\t\t\t\t\"uri\": subscriptionUrl\n \t\t\t\t}\n \t\t\t]\n \t\t}\n ]\n}\n\nconsole.log(config)\nconsole.log(url)\n\ndone({body: body, url: url});" | |
} | |
}, { | |
"id": 466623, | |
"onSuccess": ["updateSubscriptionRequest"], | |
"onFailure": [], | |
"name": "prepareUpdateSubscriptionRequest", | |
"type": "script", | |
"properties": { | |
"body": "let url = config.apiCentralUrl + '/api/unifiedCatalog/v1/catalogItems/'+steps.loopSubscriptions.entry.catalogItemId+'/subscriptions/'+steps.loopSubscriptions.entry.id+'/states';\n\nconst body = {\n \"description\": \"Approved via Custom Subsription Flow\",\n \"state\": \"APPROVED\"\n}\n\ndone({url:url, body:body});" | |
} | |
}, { | |
"id": 466624, | |
"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": 466704, | |
"onSuccess": ["loopSubscriptions"], | |
"onFailure": [], | |
"name": "sendToTeams", | |
"type": "httpRequest", | |
"properties": { | |
"body": "${steps.prepareSendToTeams.body}", | |
"method": "POST", | |
"url": "${steps.prepareSendToTeams.url}" | |
} | |
}, { | |
"id": 466626, | |
"onSuccess": ["contactExists"], | |
"onFailure": [], | |
"name": "updateSubscriptionRequest", | |
"type": "httpRequest", | |
"properties": { | |
"retry": "false", | |
"body": "${steps.prepareUpdateSubscriptionRequest.body}", | |
"headers": "${steps. defineGlobals.globalVars.apiServerHeaders}", | |
"retryAttempts": "1", | |
"retryDelay": "500", | |
"method": "POST", | |
"url": "${steps.prepareUpdateSubscriptionRequest.url}", | |
"form": "" | |
} | |
}], | |
"triggers": [{ | |
"id": 39376, | |
"onSuccess": ["prepAxwayAccessTokenRequest"], | |
"onFailure": [], | |
"type": "scheduled", | |
"async": true, | |
"active": true, | |
"name": "trigger", | |
"properties": { | |
"cron": "${config.cron}" | |
} | |
}], | |
"engine": "v3", | |
"active": true, | |
"debugLoggingEnabled": false, | |
"singleThreaded": false, | |
"configuration": [{ | |
"id": 84085, | |
"key": "apiCentralUrl", | |
"name": "apiCentralUrl", | |
"type": "value", | |
"required": false | |
}, { | |
"id": 84086, | |
"key": "axwayClientId", | |
"name": "axwayClientId", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 84087, | |
"key": "axwayClientSecret", | |
"name": "axwayClientSecret", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 84088, | |
"key": "crm", | |
"name": "crm", | |
"type": "elementInstance", | |
"required": true | |
}, { | |
"id": 84120, | |
"key": "cron", | |
"name": "cron", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 84121, | |
"key": "msTeamsWebhookURL", | |
"name": "msTeamsWebhookURL", | |
"type": "value", | |
"required": true | |
}, { | |
"id": 84089, | |
"key": "orgId", | |
"name": "orgId", | |
"type": "value", | |
"description": "Organization ID", | |
"required": true | |
}, { | |
"id": 84125, | |
"key": "whitelist", | |
"name": "whitelist", | |
"type": "value", | |
"required": true | |
}] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment