auto-invoice-leeto/node_red_data/flows.json

952 lines
24 KiB
JSON

[
{
"id": "e79fd0e1.60f55",
"type": "tab",
"label": "Get last Netflix Invoice and convert it as PDF",
"disabled": false,
"info": ""
},
{
"id": "34256184.7e2b8e",
"type": "tab",
"label": "Post a invoice on Leeto",
"disabled": false,
"info": ""
},
{
"id": "fdd2168a.835ab8",
"type": "subflow",
"name": "Netflix HTTP Auth",
"info": "",
"category": "",
"in": [
{
"x": 20,
"y": 80,
"wires": [
{
"id": "bf25f228.3c6a5"
}
]
}
],
"out": [
{
"x": 600,
"y": 80,
"wires": [
{
"id": "6d4fb2bd.73cc2c",
"port": 0
}
]
}
],
"env": [],
"color": "#DDAA99"
},
{
"id": "6d4fb2bd.73cc2c",
"type": "function",
"z": "fdd2168a.835ab8",
"name": "HTTP Headers for Netflix",
"func": "msg.headers = {};\nmsg.headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0';\nmsg.headers['Accept-Language'] = 'fr-FR,fr;q=0.5';\nmsg.headers['Cookie'] = [\n 'SecureNetflixId=' + msg.secureNetflixId,\n 'NetflixId=' + msg.netflixId,\n].join(';');\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 410,
"y": 80,
"wires": [
[]
]
},
{
"id": "bf25f228.3c6a5",
"type": "credentials",
"z": "fdd2168a.835ab8",
"name": "Netflix Credentials",
"props": [
{
"value": "netflixId",
"type": "msg"
},
{
"value": "secureNetflixId",
"type": "msg"
}
],
"x": 190,
"y": 80,
"wires": [
[
"6d4fb2bd.73cc2c"
]
]
},
{
"id": "f120e3b1.f67b38",
"type": "inject",
"z": "e79fd0e1.60f55",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 100,
"y": 40,
"wires": [
[
"2d46da6b.8dc806"
]
]
},
{
"id": "a9e0512d.6cdd7",
"type": "http request",
"z": "e79fd0e1.60f55",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "https://www.netflix.com/BillingActivity",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 350,
"y": 100,
"wires": [
[
"41d7704e.4f4a48"
]
],
"info": "Get invoice page from Netflix"
},
{
"id": "7ddcb19f.58034",
"type": "http request",
"z": "e79fd0e1.60f55",
"name": "",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 350,
"y": 160,
"wires": [
[
"b03fda42.1373b",
"690170f6.3fab38",
"174093e7.8794e4"
]
]
},
{
"id": "b03fda42.1373b",
"type": "file",
"z": "e79fd0e1.60f55",
"name": "Save last invoice",
"filename": "/data/lastInvoice.html",
"appendNewline": false,
"createDir": false,
"overwriteFile": "true",
"encoding": "utf8",
"x": 590,
"y": 160,
"wires": [
[]
]
},
{
"id": "6d08e306.82ab1c",
"type": "file",
"z": "e79fd0e1.60f55",
"name": "Save last invoice as a pdf",
"filename": "/data/lastInvoice.pdf",
"appendNewline": false,
"createDir": false,
"overwriteFile": "true",
"encoding": "none",
"x": 1030,
"y": 400,
"wires": [
[]
]
},
{
"id": "5dab3bc3.1f8edc",
"type": "http request",
"z": "e79fd0e1.60f55",
"name": "Api Call for converting to PDF",
"method": "POST",
"ret": "bin",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 1030,
"y": 300,
"wires": [
[
"6d08e306.82ab1c",
"d2bf2b71.93482"
]
]
},
{
"id": "eb861026.5c287",
"type": "function",
"z": "e79fd0e1.60f55",
"name": "Config for url-to-pdf-api",
"func": "msg.headers = {};\nmsg.headers['Content-Type'] = 'text/html';\nmsg.headers['X-Api-Key'] = msg.apiToken;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 770,
"y": 300,
"wires": [
[
"5dab3bc3.1f8edc"
]
]
},
{
"id": "690170f6.3fab38",
"type": "credentials",
"z": "e79fd0e1.60f55",
"name": "url-to-pdf-api Credentials",
"props": [
{
"value": "apiToken",
"type": "msg"
},
{
"value": "url",
"type": "msg"
}
],
"x": 530,
"y": 300,
"wires": [
[
"eb861026.5c287"
]
]
},
{
"id": "4c6af2dc.2504bc",
"type": "link out",
"z": "e79fd0e1.60f55",
"name": "Last Netflix Invoice as PDF",
"mode": "link",
"links": [
"848ba398.23bef8"
],
"x": 635,
"y": 540,
"wires": []
},
{
"id": "174093e7.8794e4",
"type": "html",
"z": "e79fd0e1.60f55",
"name": "",
"property": "payload",
"outproperty": "payload",
"tag": ".invoiceFooter dd",
"ret": "text",
"as": "single",
"x": 170,
"y": 400,
"wires": [
[
"5f5a3dc9.eab71c"
]
]
},
{
"id": "d2bf2b71.93482",
"type": "change",
"z": "e79fd0e1.60f55",
"name": "Move as payload.file",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "payload.file",
"tot": "msg"
},
{
"t": "set",
"p": "payload.filename",
"pt": "msg",
"to": "netflix-invoice.pdf",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 660,
"y": 400,
"wires": [
[
"97cde9aaf371b9ac"
]
]
},
{
"id": "73c55749.b6bf7",
"type": "debug",
"z": "e79fd0e1.60f55",
"name": "Tap payload",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 690,
"y": 480,
"wires": []
},
{
"id": "8e61a051.3430c8",
"type": "debug",
"z": "e79fd0e1.60f55",
"d": true,
"name": "Last invoice url",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "url",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 800,
"y": 100,
"wires": []
},
{
"id": "5f5a3dc9.eab71c",
"type": "change",
"z": "e79fd0e1.60f55",
"name": "parse amount",
"rules": [
{
"t": "move",
"p": "payload[0]",
"pt": "msg",
"to": "textAmount",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{}",
"tot": "json"
},
{
"t": "set",
"p": "payload.amount",
"pt": "msg",
"to": "$number($replace($match(textAmount, /[0-9\\,]+/, 1).match, ',', '.'))",
"tot": "jsonata"
},
{
"t": "set",
"p": "payload.name",
"pt": "msg",
"to": "Netflix",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 360,
"y": 400,
"wires": [
[
"97cde9aaf371b9ac"
]
]
},
{
"id": "643c6d17.cec784",
"type": "function",
"z": "e79fd0e1.60f55",
"name": "Cleaning payload",
"func": "return {payload: msg.payload};",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 470,
"y": 500,
"wires": [
[
"73c55749.b6bf7",
"4c6af2dc.2504bc"
]
]
},
{
"id": "2d46da6b.8dc806",
"type": "subflow:fdd2168a.835ab8",
"z": "e79fd0e1.60f55",
"name": "Netflix HTTP Auth",
"env": [],
"x": 170,
"y": 100,
"wires": [
[
"a9e0512d.6cdd7"
]
]
},
{
"id": "797b306d.21639",
"type": "subflow:fdd2168a.835ab8",
"z": "e79fd0e1.60f55",
"name": "Netflix HTTP Auth",
"env": [],
"x": 170,
"y": 160,
"wires": [
[
"7ddcb19f.58034"
]
]
},
{
"id": "41d7704e.4f4a48",
"type": "change",
"z": "e79fd0e1.60f55",
"name": "Extract last invoice url",
"rules": [
{
"t": "set",
"p": "url",
"pt": "msg",
"to": "$join([\t 'https://www.netflix.com',\t $lookup($match(payload, /\\/invoice\\/print\\/[^\"]*/), 'match')[0]\t])",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 540,
"y": 100,
"wires": [
[
"8e61a051.3430c8",
"797b306d.21639"
]
]
},
{
"id": "97cde9aaf371b9ac",
"type": "join",
"z": "e79fd0e1.60f55",
"name": "",
"mode": "custom",
"build": "merged",
"property": "payload",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"accumulate": false,
"timeout": "",
"count": "3",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 260,
"y": 520,
"wires": [
[
"643c6d17.cec784"
]
],
"info": "NOTE : How the fuck this join require 3 as number of messages and not 2 as expected."
},
{
"id": "debc0868.c889a",
"type": "inject",
"z": "34256184.7e2b8e",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 120,
"y": 40,
"wires": [
[
"ac7c6734.52f8f"
]
]
},
{
"id": "cfd9259a.79e2a8",
"type": "credentials",
"z": "34256184.7e2b8e",
"name": "Leeto Credentials",
"props": [
{
"value": "email",
"type": "msg"
},
{
"value": "password",
"type": "msg"
}
],
"x": 150,
"y": 220,
"wires": [
[
"e1a3a869.cb50a8"
]
]
},
{
"id": "e1a3a869.cb50a8",
"type": "function",
"z": "34256184.7e2b8e",
"name": "Leeto payload for Login",
"func": "msg.headers = {};\nmsg.headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0';\nmsg.headers['Content-Type'] = 'application/json';\nmsg.headers['Accept'] = 'application/json, text/plain, */*';\nmsg.headers['Accept-Language'] = 'fr-FR,fr;q=0.5';\nmsg.payload = {\n user: {\n email: msg.email,\n password: msg.password\n }\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 370,
"y": 220,
"wires": [
[
"38582789.81bb28"
]
]
},
{
"id": "38582789.81bb28",
"type": "http request",
"z": "34256184.7e2b8e",
"name": "Connect to Leeto",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://api.leeto.co/api/v2/users/sign_in?locale=fr",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 590,
"y": 220,
"wires": [
[
"8a8f2737.aa3d"
]
]
},
{
"id": "ac7c6734.52f8f",
"type": "file in",
"z": "34256184.7e2b8e",
"name": "Test invoice",
"filename": "/data/test.pdf",
"format": "",
"chunk": false,
"sendError": false,
"encoding": "none",
"x": 270,
"y": 40,
"wires": [
[
"ee1a1e10.8655a8"
]
]
},
{
"id": "f5429dca.a2783",
"type": "http request",
"z": "34256184.7e2b8e",
"name": "Leeto Reimbursement Request",
"method": "POST",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 650,
"y": 440,
"wires": [
[
"337393c6.282844"
]
]
},
{
"id": "5571d225.8e12dc",
"type": "function",
"z": "34256184.7e2b8e",
"name": "Leeto payload for reimbursement",
"func": "msg.headers = {};\nmsg.headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0';\nmsg.headers['Content-Type'] = 'multipart/form-data';\nmsg.headers['Accept'] = 'application/json, text/plain, */*';\nmsg.headers['Accept-Language'] = 'fr-FR,fr;q=0.5';\nmsg.headers['Authorization'] = 'Bearer ' + msg.leetoUser.token;\n\nmsg.payload = {\n 'reimbursement_request[user_id]': msg.leetoUser.id,\n 'reimbursement_request[grantable_id]': msg.leetoUser.id,\n 'reimbursement_request[grantable_type]': 'User',\n 'reimbursement_request[quotum_id]': msg.benefit.data[0].quotumId,\n 'reimbursement_request[purchases][][generate_certificate_of_honour]': false,\n // 'reimbursement_request[purchases][][comments_attributes][][user_id]': msg.leetoUser.id,\n // 'reimbursement_request[purchases][][comments_attributes][][organisation_id]': msg.leetoUser.organisation.id,\n // 'reimbursement_request[purchases][][comments_attributes][][body]': 'This a comment',\n 'reimbursement_request[purchases][][purchase_name]': msg.invoice.name,\n 'reimbursement_request[purchases][][amount]': (msg.benefit.data[0].remainingAmount < msg.invoice.amount) ? msg.benefit.data[0].remainingAmount : msg.invoice.amount,\n 'reimbursement_request[purchases][][requested_amount]': msg.invoice.amount,\n 'reimbursement_request[purchases][][receipts_attributes][][image]': {\n value: msg.invoice.file,\n options: {\n filename: msg.invoice.filename,\n contentType: msg.invoice.contentType,\n }\n }\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 340,
"y": 440,
"wires": [
[
"f5429dca.a2783",
"a689e897.689f68"
]
]
},
{
"id": "337393c6.282844",
"type": "debug",
"z": "34256184.7e2b8e",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 910,
"y": 440,
"wires": []
},
{
"id": "38445ef0.73a4ca",
"type": "http request",
"z": "34256184.7e2b8e",
"name": "Leeto get benefit",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 550,
"y": 320,
"wires": [
[
"9eb06fc.6d8cb1"
]
]
},
{
"id": "c63deac6.d6ff18",
"type": "function",
"z": "34256184.7e2b8e",
"name": "Leeto payload for get Benefit",
"func": "msg.headers = {};\nmsg.headers['User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:82.0) Gecko/20100101 Firefox/82.0';\nmsg.headers['Content-Type'] = 'multipart/form-data';\nmsg.headers['Accept'] = 'application/json, text/plain, */*';\nmsg.headers['Accept-Language'] = 'fr-FR,fr;q=0.5';\nmsg.headers['Authorization'] = 'Bearer ' + msg.leetoUser.token;\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 320,
"y": 320,
"wires": [
[
"38445ef0.73a4ca"
]
]
},
{
"id": "8e087080.9c07c8",
"type": "template",
"z": "34256184.7e2b8e",
"name": "Build URL",
"field": "url",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "https://api.leeto.co/api/v2/organisations/{{leetoUser.organisationId}}/users/{{leetoUser.id}}/quotum_usages?filter[by_state]=active&locale=fr",
"output": "str",
"x": 120,
"y": 320,
"wires": [
[
"c63deac6.d6ff18"
]
]
},
{
"id": "17d03aa5.9a232d",
"type": "template",
"z": "34256184.7e2b8e",
"name": "Build URL",
"field": "url",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "https://api.leeto.co/api/v2/organisations/{{leetoUser.organisationId}}/reimbursement_requests/bulk_create?locale=fr",
"output": "str",
"x": 120,
"y": 440,
"wires": [
[
"5571d225.8e12dc"
]
]
},
{
"id": "848ba398.23bef8",
"type": "link in",
"z": "34256184.7e2b8e",
"name": "Trigged from Netflix Last Invoice",
"links": [
"4c6af2dc.2504bc"
],
"x": 475,
"y": 120,
"wires": [
[
"8a75e7ed.ee7658"
]
]
},
{
"id": "ee1a1e10.8655a8",
"type": "change",
"z": "34256184.7e2b8e",
"name": "Test payload",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "file",
"tot": "msg"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{}",
"tot": "json"
},
{
"t": "set",
"p": "payload.file",
"pt": "msg",
"to": "file",
"tot": "msg"
},
{
"t": "set",
"p": "payload.filename",
"pt": "msg",
"to": "test.pdf",
"tot": "str"
},
{
"t": "set",
"p": "payload.amount",
"pt": "msg",
"to": "0",
"tot": "num"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 430,
"y": 40,
"wires": [
[
"8a75e7ed.ee7658"
]
]
},
{
"id": "8a75e7ed.ee7658",
"type": "change",
"z": "34256184.7e2b8e",
"name": "add invoice as message context",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "invoice",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 710,
"y": 120,
"wires": [
[
"cfd9259a.79e2a8"
]
]
},
{
"id": "8a8f2737.aa3d",
"type": "change",
"z": "34256184.7e2b8e",
"name": "set leetoUser as message context",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "leetoUser",
"tot": "msg"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 840,
"y": 220,
"wires": [
[
"8e087080.9c07c8"
]
]
},
{
"id": "9eb06fc.6d8cb1",
"type": "change",
"z": "34256184.7e2b8e",
"name": "set benefit as message context",
"rules": [
{
"t": "move",
"p": "payload",
"pt": "msg",
"to": "benefit",
"tot": "msg"
},
{
"t": "set",
"p": "parts.id",
"pt": "msg",
"to": "leeto-infos",
"tot": "str"
},
{
"t": "set",
"p": "parts.index",
"pt": "msg",
"to": "0",
"tot": "str"
},
{
"t": "set",
"p": "parts.count",
"pt": "msg",
"to": "2",
"tot": "str"
},
{
"t": "set",
"p": "parts.type",
"pt": "msg",
"to": "object",
"tot": "str"
},
{
"t": "set",
"p": "parts.key",
"pt": "msg",
"to": "benefit",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 790,
"y": 320,
"wires": [
[
"17d03aa5.9a232d"
]
]
},
{
"id": "a689e897.689f68",
"type": "debug",
"z": "34256184.7e2b8e",
"name": "Payload for leeto",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 770,
"y": 580,
"wires": []
}
]