Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dylanyoung-dev/33bc41da5ebc7f64889fc34232d729e5 to your computer and use it in GitHub Desktop.
Save dylanyoung-dev/33bc41da5ebc7f64889fc34232d729e5 to your computer and use it in GitHub Desktop.
This is the collection used in my Discover Sitecore Stream APIs with Postman for triggering a web experience.
{
"info": {
"_postman_id": "a4a6f7d3-fd06-4e49-bc89-6f2819f7e1c7",
"name": "Trigger Flow - Stream APIs - Discover Sitecore",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "18869027"
},
"item": [
{
"name": "Stream APIs",
"item": [
{
"name": "Flow Execution",
"item": [
{
"name": "Run Experiment",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"var browserId = pm.environment.get(\"BrowserRef\");\r",
"var POS = pm.environment.get(\"POS\");\r",
"var clientKey = pm.environment.get(\"ClientKey\");\r",
"\r",
"let body = {\r",
" mode: 'raw',\r",
" raw: JSON.stringify({\r",
" \"channel\": \"WEB\",\r",
" \"language\": \"EN\",\r",
" \"currencyCode\": \"USD\",\r",
" \"pointOfSale\": POS,\r",
" \"browserId\": browserId,\r",
" \"clientKey\": clientKey,\r",
" \"friendlyId\":\"experimentwithpostman\"\r",
" }),\r",
" options: {\r",
" raw: {\r",
" language: 'json'\r",
" }\r",
" }\r",
"}\r",
"\r",
"pm.request.body.update(body);\r",
"console.log(pm.request.body);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{apiEndpoint}}/v2/callFlows",
"protocol": "https",
"host": [
"{{apiEndpoint}}"
],
"path": [
"v2",
"callFlows"
]
}
},
"response": []
}
]
},
{
"name": "Create Browser Reference",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);\r",
"pm.environment.set(\"BrowserRef\", jsonData.ref);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{apiEndpoint}}/v1.2/browser/create.json?client_key={{ClientKey}}&message=",
"protocol": "https",
"host": [
"{{apiEndpoint}}"
],
"path": [
"v1.2",
"browser",
"create.json"
],
"query": [
{
"key": "client_key",
"value": "{{ClientKey}}"
},
{
"key": "message",
"value": "",
"description": "The body of the message. Leave this empty for retrieving the `browserId` attribute."
}
]
}
},
"response": [
{
"name": "Create Browser Reference",
"originalRequest": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{apiEndpoint}}/v1.2/browser/create.json?client_key={{ClientKey}}&message=",
"protocol": "https",
"host": [
"{{apiEndpoint}}"
],
"path": [
"v1.2",
"browser",
"create.json"
],
"query": [
{
"key": "client_key",
"value": "{{ClientKey}}"
},
{
"key": "message",
"value": "",
"description": "The body of the message. Leave this empty for retrieving the `browserId` attribute."
}
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Date",
"value": "Mon, 29 Aug 2022 17:43:47 GMT"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "X-Robots-Tag",
"value": "noindex"
},
{
"key": "Content-Length",
"value": "178"
},
{
"key": "Connection",
"value": "keep-alive"
}
],
"cookie": [],
"body": "{\n \"status\": \"OK\",\n \"version\": \"1.2\",\n \"client_key\": \"psfu6uh05hsr9c34rptlr06dn864cqrx\",\n \"ref\": \"8be8b9d0-e34d-4f13-bcc3-5579f6862589\",\n \"customer_ref\": \"7d0faa2b-3f07-4f3b-afeb-75419317b569\"\n}"
}
]
},
{
"name": "Kill Session",
"event": [
{
"listen": "prerequest",
"script": {
"exec": [
"var browserId = pm.environment.get(\"BrowserRef\");\r",
"var POS = pm.environment.get(\"POS\");\r",
"var clientKey = pm.environment.get(\"ClientKey\");\r",
"var closeSessionRequest = {\r",
" channel: \"WEB\",\r",
" language: \"EN\",\r",
" currency: \"USD\",\r",
" pos: POS,\r",
" browser_id: browserId,\r",
" clientKey: clientKey,\r",
" type: \"FORCE_CLOSE\",\r",
" _bx_extended_message: \"1\"\r",
"};\r",
"\r",
"var messageAsString = JSON.stringify(closeSessionRequest);\r",
"var messageEncoded = encodeURI(messageAsString);\r",
"pm.environment.set(\"message\", messageEncoded);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{apiEndpoint}}/v1.2/event/create.json?client_key={{ClientKey}}&message={{message}}",
"protocol": "https",
"host": [
"{{apiEndpoint}}"
],
"path": [
"v1.2",
"event",
"create.json"
],
"query": [
{
"key": "client_key",
"value": "{{ClientKey}}"
},
{
"key": "message",
"value": "{{message}}"
}
]
}
},
"response": []
},
{
"name": "Track a Web VIEW Event",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"var browserId = pm.environment.get(\"BrowserRef\");\r",
"var POS = pm.environment.get(\"POS\");\r",
"var clientKey = pm.environment.get(\"ClientKey\");\r",
"var viewEvent = {\r",
" channel: \"WEB\",\r",
" language: \"EN\",\r",
" currency: \"USD\",\r",
" pos: POS,\r",
" page: \"/campaign\",\r",
" browser_id: browserId,\r",
" clientKey: clientKey,\r",
" type: \"VIEW\"\r",
"}\r",
"\r",
"var messageAsString = JSON.stringify(viewEvent);\r",
"var messageEncoded = encodeURI(messageAsString);\r",
"pm.environment.set(\"message\", messageEncoded);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{apiEndpoint}}/v1.2/event/create.json?client_key={{ClientKey}}&message={{message}}",
"protocol": "https",
"host": [
"{{apiEndpoint}}"
],
"path": [
"v1.2",
"event",
"create.json"
],
"query": [
{
"key": "client_key",
"value": "{{ClientKey}}"
},
{
"key": "message",
"value": "{{message}}",
"description": "The message container the event data"
}
]
}
},
"response": []
},
{
"name": "Track a Web Custom Event",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"var browserId = pm.environment.get(\"BrowserRef\");\r",
"var POS = pm.environment.get(\"POS\");\r",
"var clientKey = pm.environment.get(\"ClientKey\");\r",
"var viewEvent = {\r",
" channel: \"WEB\",\r",
" language: \"EN\",\r",
" currency: \"USD\",\r",
" pos: POS,\r",
" page: \"home\",\r",
" browser_id: browserId,\r",
" clientKey: clientKey,\r",
" type: \"VIDEO_VIEWED\"\r",
"}\r",
"\r",
"var messageAsString = JSON.stringify(viewEvent);\r",
"var messageEncoded = encodeURI(messageAsString);\r",
"pm.environment.set(\"message\", messageEncoded);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{apiEndpoint}}/v1.2/event/create.json?client_key={{ClientKey}}&message={{message}}",
"protocol": "https",
"host": [
"{{apiEndpoint}}"
],
"path": [
"v1.2",
"event",
"create.json"
],
"query": [
{
"key": "client_key",
"value": "{{ClientKey}}"
},
{
"key": "message",
"value": "{{message}}",
"description": "The message container the event data"
}
]
}
},
"response": []
},
{
"name": "Identity Web Event",
"event": [
{
"listen": "test",
"script": {
"exec": [
""
],
"type": "text/javascript"
}
},
{
"listen": "prerequest",
"script": {
"exec": [
"var browserId = pm.environment.get(\"BrowserRef\");\r",
"var POS = pm.environment.get(\"POS\");\r",
"var clientKey = pm.environment.get(\"ClientKey\");\r",
"var viewEvent = {\r",
" channel: \"WEB\",\r",
" language: \"EN\",\r",
" currency: \"USD\",\r",
" pos: POS,\r",
" page: \"home\",\r",
" browser_id: browserId,\r",
" clientKey: clientKey,\r",
" type: \"IDENTITY\"\r",
"}\r",
"\r",
"var messageAsString = JSON.stringify(viewEvent);\r",
"var messageEncoded = encodeURI(messageAsString);\r",
"pm.environment.set(\"message\", messageEncoded);"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://{{apiEndpoint}}/v1.2/event/create.json?client_key={{ClientKey}}&message={{message}}",
"protocol": "https",
"host": [
"{{apiEndpoint}}"
],
"path": [
"v1.2",
"event",
"create.json"
],
"query": [
{
"key": "client_key",
"value": "{{ClientKey}}"
},
{
"key": "message",
"value": "{{message}}",
"description": "The message container the event data"
}
]
}
},
"response": []
}
],
"auth": {
"type": "noauth"
},
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment