Dolibarr API

Hello !

This subflow is use to make request to a Dolibarr API. You can pass all properties of this subflow to the message. That will override what you set in the subflow panel.

You can find in the subflow a documentation.

Enjoy !

[{"id":"54526e03f83ee9e5","type":"subflow","name":"Set API key header","info":"","category":"Dolibarr","in":[{"x":220,"y":280,"wires":[{"id":"f0cc08cda04f90a8"}]}],"out":[{"x":1420,"y":280,"wires":[{"id":"762646999dea5e9f","port":0},{"id":"a11e0bdac5ddb9e6","port":1}]}],"env":[{"name":"apiKey","type":"cred","ui":{"icon":"font-awesome/fa-key"}},{"name":"clearHeaders","type":"bool","value":"true","ui":{"icon":"font-awesome/fa-trash-o","type":"checkbox"}},{"name":"eraseKey","type":"bool","value":"true","ui":{"icon":"font-awesome/fa-trash-o","type":"checkbox"}}],"meta":{},"color":"rgb(85, 165, 155)","outputLabels":["msg with header"],"icon":"font-awesome/fa-key"},{"id":"27635e708f5d05b0","type":"function","z":"54526e03f83ee9e5","name":"Set Header","func":"if (msg.headers === null || msg.headers === undefined || msg.clearHeaders){\n    msg.headers = {};\n}\nmsg.headers['DOLAPIKEY'] = msg.apiKey;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":750,"y":280,"wires":[["a11e0bdac5ddb9e6"]]},{"id":"85dbe078bc70e1fa","type":"comment","z":"54526e03f83ee9e5","name":"Set API key in header","info":"","x":680,"y":140,"wires":[]},{"id":"762646999dea5e9f","type":"change","z":"54526e03f83ee9e5","name":"","rules":[{"t":"delete","p":"apiKey","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1150,"y":240,"wires":[[]]},{"id":"f0cc08cda04f90a8","type":"function","z":"54526e03f83ee9e5","name":"Set priority of msg value","func":"var list = ['apiKey', 'clearHeaders', 'eraseKey']\nfor (let index = 0; index < list.length; index++) {\n    const element = list[index];\n    if (msg[element] === undefined && (env.get(element) !== '' || env.get(element) !== null || env.get(element) !== undefined)) {\n        msg[element] = env.get(element)\n    } else {\n        if (msg[element] === undefined || msg[element] === null) {\n            node.warn(\"You have to configure the node in the panel editor or via msg property\");\n        }\n    }\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":280,"wires":[["27635e708f5d05b0"]]},{"id":"a11e0bdac5ddb9e6","type":"switch","z":"54526e03f83ee9e5","name":"","property":"eraseKey","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":970,"y":300,"wires":[["762646999dea5e9f"],[]]},{"id":"e0b88d23ec56febb","type":"subflow","name":"Dolibarr API","info":"## **Editor properties to use for each object type**\n\n- **global properties :**\n    - sortField\n    - sortOrder\n    - limit\n    - page\n    - category\n    - sqlFilters\n        - From Dolibarr documentation :  \n            - Other criteria to filter answers separated by a comma. Syntax example \"(t.tobuy:=:0) and (t.tosell:=:1)\"\n        - From this subflow :  \n            - Use a array with one object for each filter like this one\n                <code>msg.sqlFilters: [  \n                            {  \n                                \"attribute\": \"ref\",  \n                                \"compare\": \"=\",  \n                                \"value\": 18  \n                            },  \n                        {  \n                            \"operation\": \"and\",  \n                            \"attribute\": \"ref\",  \n                            \"compare\": \"=\", \n                            \"value\": 18  \n                        }  \n                ]</code>\n            - Note the presence of a additional attribute for the second message\n            - You can still pass the Dolibarr default syntax if you pass a string instead of an array   \n&nbsp;\n    - **No supplementary field for :**\n        - bankAccounts\n        - boms\n        - category  \n&nbsp;\n    - **The following properties IS NOT CONTAIN the following type :**  \n        - category\n            - boms\n            - documents\n            - invoices\n            - knowledgeManagement\n            - mos\n            - orders\n            - recruitment/candidature\n            - recruitment/jobPosition\n            - shipments\n            - stockMovements\n            - supplierOrders\n            - supplierInvoices\n            - tasks  \n&nbsp;\n    - **The following types DO NOT CONTAIN the following properties :**\n        - documents\n            - limit\n            - page\n            - sqlFilters  \n&nbsp;\n- **agendaEvents :**\n    - userIds\n        - User ids filter field (owners of event). Example: '1' or '1,2,3'  \n&nbsp;\n- **categories**\n    - type\n        - From Dolibarr documentation :\n            - Type of category ('member', 'customer', 'supplier', 'product', 'contact')\n        - For this subflow by techsc.fr :\n            For this subflow by techsc.fr : \n            - You can pass an array of int like that :  \n            <code>\n            [1,2,9]\n            </code>\n            - You **CAN NOT PASS** the string like the Dolibarr documentation say **BECAUSE THIS WAY IS BETTER**.\n            Dolibarr filter with an sql filter on the column \"type\" in the database. So i do that directly. Below you \n            can this the mapping:\n                - 0: service\n                - 1: product\n                - 2: client/prospect\n                - 3: member\n                - 4: contact\n                - 5: bank\n                - 6: project\n                - 7: user\n                - 8: I guess it correspond with the table categorie_lang but i didn't find where add that categorie\n                - 9: warehouse\n                - 10: event\n                - 11: website page\n            \n\n&nbsp;\n- **contacts :**\n    - thirdpartyIds\n        - From Dolibarr documentation :\n            - Thirdparty ids to filter contacts of (example '1' or '1,2,3')\n        - For this subflow by techsc.fr : \n            - You can pass an array of int like that :  \n            <code>\n            [1,2,9]\n            </code>\n            - You can pass the string like the Dolibarr documentation say.\n    - includeCount\n        - From Dolibarr documentation :\n            - Count and return also number of elements the contact is used as a link for\n    - includeRole  \n&nbsp;\n- **documents :**\n    - modulePart\n    - id\n    - ref  \n&nbsp;\n- **invoices :**\n    - thirdpartyIds\n    - status\n        - From Dolibarr documentation :\n            - Filter by invoice status : draft | unpaid | paid | cancelled  \n&nbsp;\n- **orders :**\n    - thirdpartyIds  \n&nbsp;\n- **products :**\n    - mode\n        - From Dolibarr documentation :\n            - Use this param to filter list (0 for all, 1 for only product, 2 for only service)\n    - variantFilter\n        - From Dolibarr documentation :\n            - Use this param to filter list (0 = all, 1=products without variants, 2=parent of variants, 3=variants only)  \n    - idsOnly\n    - paginationData\n    - includeStockData\n&nbsp;\n- **projects :**\n    - thirdpartyIds  \n&nbsp;\n- **proposals :**\n    - thirdpartyIds  \n&nbsp;\n- **supplierInvoices :**\n    - thirdpartyIds\n    - status\n        - From Dolibarr documentation :\n            - Filter by invoice status : draft | unpaid | paid | cancelled  \n&nbsp;\n- **supplierOrders :**\n    - thirdpartyIds\n    - status\n        - From Dolibarr documentation :\n            - Filter by order status : draft | validated | approved | running | received_start | received_end | cancelled | refused\n    - productIds\n        - From Dolibarr documentation :\n            - Thirdparty ids to filter orders of (example '1' or '1,2,3')\n        - For this subflow by techsc.fr : \n            - You can pass an array of int like that :  \n            <code>\n            [1,2,9]\n            </code>\n            - You can pass the string like the Dolibarr documentation say.  \n&nbsp;\n- **thirdparties**\n    - mode\n        - From Dolibarr documentation :\n            - Set to 1 to show only customers Set to 2 to show only prospects Set to 3 to show only those are not customer neither prospect Set to 4 to show only suppliers  \n\n\n","category":"Dolibarr","in":[{"x":40,"y":80,"wires":[{"id":"d6cf05a3596154b7"},{"id":"e9c33ced9f42dc2d"}]}],"out":[{"x":2020,"y":360,"wires":[{"id":"5c0e995677254bcd","port":0}]}],"env":[{"name":"protocol","type":"str","value":"https","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"HTTP"},"v":"http"},{"l":{"en-US":"HTTPS"},"v":"https"}]}}},{"name":"host","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","env"]}}},{"name":"port","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","env"]}}},{"name":"apiKey","type":"cred"},{"name":"clearHeaders","type":"bool","value":"true","ui":{"type":"input","opts":{"types":["bool","env"]}}},{"name":"objectName","type":"str","value":"products","ui":{"label":{"en-US":"objectName (API path)"},"type":"input","opts":{"types":["str","env"]}}},{"name":"sortField","type":"str","value":"ref","ui":{"type":"input","opts":{"types":["str","env"]}}},{"name":"sortOrder","type":"str","value":"ASC","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"Ascendant"},"v":"ASC"},{"l":{"en-US":"Descendant"},"v":"DESC"}]}}},{"name":"limit","type":"num","value":"100","ui":{"type":"input","opts":{"types":["num","env"]}}},{"name":"page","type":"num","value":"0","ui":{"type":"input","opts":{"types":["num","env"]}}},{"name":"sqlFilters","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","json","env"]}}},{"name":"category","type":"num","value":"0","ui":{"label":{"en-US":"category (id)"},"type":"input","opts":{"types":["num","env"]}}},{"name":"thirdpartyIds","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","json","env"]}}},{"name":"mode","type":"str","value":"","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"PROD - Products & Services"},"v":"0"},{"l":{"en-US":"PROD - Products"},"v":"1"},{"l":{"en-US":"PROD - Services"},"v":"2"},{"l":{"en-US":"3rdP - Customers"},"v":"1"},{"l":{"en-US":"3rdP - Suppliers"},"v":"4"},{"l":{"en-US":"3rdP - Prospects"},"v":"2"},{"l":{"en-US":"3rdP - Neither customers | suppliers"},"v":"3"}]}}},{"name":"status","type":"str","value":"","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"draft"},"v":"draft"},{"l":{"en-US":"unpaid"},"v":"unpaid"},{"l":{"en-US":"paid"},"v":"paid"},{"l":{"en-US":"cancelled"},"v":"cancelled"},{"l":{"en-US":"validated"},"v":"validated"},{"l":{"en-US":"approved"},"v":"approved"},{"l":{"en-US":"running"},"v":"running"},{"l":{"en-US":"receivedStart"},"v":"receiveStart"},{"l":{"en-US":"receivedEnd"},"v":"receivedEnd"},{"l":{"en-US":"refused"},"v":"refused"}]}}},{"name":"productIds","type":"str","value":"","ui":{"label":{"en-US":"productIds"},"type":"input","opts":{"types":["str","json","env"]}}},{"name":"variantFilter","type":"str","value":"0","ui":{"label":{"en-US":"variantFilter"},"type":"select","opts":{"opts":[{"l":{"en-US":"All"},"v":"0"},{"l":{"en-US":"Product without variants"},"v":"1"},{"l":{"en-US":"Parent of variants"},"v":"2"},{"l":{"en-US":"Variants only"},"v":"3"}]}}},{"name":"idsOnly","type":"bool","value":"false","ui":{"type":"input","opts":{"types":["bool","env"]}}},{"name":"paginationData","type":"bool","value":"false","ui":{"type":"input","opts":{"types":["bool","env"]}}},{"name":"includeStockData","type":"bool","value":"false","ui":{"type":"input","opts":{"types":["bool","env"]}}},{"name":"includeCount","type":"bool","value":"false","ui":{"type":"input","opts":{"types":["bool","env"]}}},{"name":"includeRole","type":"bool","value":"false","ui":{"type":"input","opts":{"types":["bool","env"]}}},{"name":"type","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","json"]}}},{"name":"id","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","json","env"]}}},{"name":"method","type":"str","value":"","ui":{"type":"select","opts":{"opts":[{"l":{"en-US":"GET"},"v":"get"},{"l":{"en-US":"POST"},"v":"post"},{"l":{"en-US":"PUT"},"v":"put"},{"l":{"en-US":"DELETE"},"v":"delete"}]}}}],"meta":{},"credentials":{"apiKey":""},"color":"rgb(85, 165, 155)","inputLabels":["List of object type name"]},{"id":"66e5a712699560fe","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":780,"wires":[]},{"id":"a783024a8314ff4e","type":"function","z":"e0b88d23ec56febb","name":"Get dolibarr API object rootPaths","func":"var dolibarrObjectTypeList = []\nfor (var path in msg.payload.paths) {\n    if (msg.payload.paths.hasOwnProperty(path)) {\n        path = path.slice(1)\n        if(path.includes('/')){\n            var rootPath = path.slice(0, path.indexOf('/'))\n        }else{\n            rootPath = path\n        }\n        dolibarrObjectTypeList.push(rootPath)\n    }\n}\nmsg.dolibarrObjectTypeList = [...new Set(dolibarrObjectTypeList)]\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":300,"wires":[["2b317408bce6e542"]]},{"id":"770be6beb8328773","type":"http request","z":"e0b88d23ec56febb","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":550,"y":260,"wires":[["a783024a8314ff4e"]]},{"id":"167db7777642b7c5","type":"split","z":"e0b88d23ec56febb","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":1550,"y":300,"wires":[["3b9fa8df3cc40f13"]]},{"id":"4d0f70846a304a25","type":"http request","z":"e0b88d23ec56febb","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":670,"y":540,"wires":[["66e5a712699560fe","085349cfe37516db"]]},{"id":"085349cfe37516db","type":"switch","z":"e0b88d23ec56febb","name":"Handle errors","property":"statusCode","propertyType":"msg","rules":[{"t":"eq","v":"404","vt":"num"},{"t":"eq","v":"503","vt":"num"},{"t":"eq","v":"400","vt":"num"},{"t":"eq","v":"200","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":5,"x":960,"y":540,"wires":[["af5490ba85caccc6"],["2df03207650839fb"],["03686734cc7e053f"],["50d86c4d971e0331"],["ac25e51276cc6d90"]]},{"id":"391fe18b05530468","type":"debug","z":"e0b88d23ec56febb","name":"","active":false,"tosidebar":false,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1490,"y":480,"wires":[]},{"id":"69f3b6f6f36d5258","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1930,"y":520,"wires":[]},{"id":"1299a97669f73268","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":false,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1510,"y":560,"wires":[]},{"id":"a8cc649ab5c458dd","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":false,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1510,"y":600,"wires":[]},{"id":"76de7163c10af77f","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1510,"y":640,"wires":[]},{"id":"2df03207650839fb","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"fornow","pt":"msg","to":"work to do","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":520,"wires":[["ec2d574e6fc6afa0"]]},{"id":"af5490ba85caccc6","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"fornow","pt":"msg","to":"No object found","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":480,"wires":[["391fe18b05530468","2c94da3074594fd1"]]},{"id":"03686734cc7e053f","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"fornow","pt":"msg","to":"api call wrong parameter","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":560,"wires":[["1299a97669f73268","2c94da3074594fd1"]]},{"id":"ec2d574e6fc6afa0","type":"switch","z":"e0b88d23ec56febb","name":"","property":"payload.error.message","propertyType":"msg","rules":[{"t":"cont","v":"'t.rowid' in 'order clause'","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1750,"y":520,"wires":[["bb46dd8bab5bb1aa"],["69f3b6f6f36d5258"]]},{"id":"bb46dd8bab5bb1aa","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"change","p":"url","pt":"msg","from":"rowid","fromt":"str","to":"id","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1960,"y":460,"wires":[[]]},{"id":"0add92ae320a3779","type":"http request","z":"e0b88d23ec56febb","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":2370,"y":460,"wires":[["d92fc3314f8c70a9"]]},{"id":"d92fc3314f8c70a9","type":"link out","z":"e0b88d23ec56febb","name":"","mode":"link","links":["4ff19ac399a0f899"],"x":2505,"y":460,"wires":[]},{"id":"4ff19ac399a0f899","type":"link in","z":"e0b88d23ec56febb","name":"check error way","links":["d92fc3314f8c70a9"],"x":625,"y":640,"wires":[["085349cfe37516db"]]},{"id":"50d86c4d971e0331","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{dolibarrObjectTypeList[$$.parts.index] : payload[0]}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":600,"wires":[["2c94da3074594fd1","a8cc649ab5c458dd"]]},{"id":"2b317408bce6e542","type":"function","z":"e0b88d23ec56febb","name":"Remove elememt ","func":"msg.dolibarrObjectTypeList.slice(msg.dolibarrObjectTypeList.indexOf(msg.payload),1)\nvar valToRemove = ['login', 'documents', 'setup', 'status']\nfor (let index = 0; index < valToRemove.length; index++) {\n    const element = valToRemove[index];\n    if (msg.dolibarrObjectTypeList.includes(element)){\n        msg.dolibarrObjectTypeList.splice(msg.dolibarrObjectTypeList.indexOf(element), 1)\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1130,"y":300,"wires":[["b99afed8e7639d9f"]]},{"id":"b99afed8e7639d9f","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"dolibarrObjectTypeList","tot":"msg"},{"t":"set","p":"dolibarrObjects","pt":"msg","to":"[]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1360,"y":300,"wires":[["167db7777642b7c5"]]},{"id":"3b9fa8df3cc40f13","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"'http://192.168.1.18:8200/api/index.php/' & payload & '?sortfield=t.rowid&sortorder=ASC&limit=1'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":210,"y":540,"wires":[["4d0f70846a304a25","1f6de9ab648fec22","3829fe4d1978f0e3"]]},{"id":"2c94da3074594fd1","type":"join","z":"e0b88d23ec56febb","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":2450,"y":80,"wires":[["7f4e8f215b3c90a5"]]},{"id":"7f4e8f215b3c90a5","type":"function","z":"e0b88d23ec56febb","name":"Remove elememt with error","func":"var dolibarrObjects = []\nfor (let index = 0; index < msg.payload.length; index++) {\n    const element = msg.payload[index];\n    if (!element.hasOwnProperty('error')) {\n        dolibarrObjects.push(msg.payload[index])\n    }\n}\nmsg.dolibarrObjects = dolibarrObjects\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2680,"y":80,"wires":[["0c77d02d05c60bcf"]]},{"id":"ac25e51276cc6d90","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"fornow","pt":"msg","to":"this case is not handled","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":640,"wires":[["76de7163c10af77f"]]},{"id":"d6cf05a3596154b7","type":"function","z":"e0b88d23ec56febb","name":"Set priority of msg value","func":"var list = [\n    'protocol',\n    'host',\n    'port',\n    'path',\n    'apiKey',\n    'clearHeaders',\n    'objectName',\n    'sortField',\n    'sortOrder',\n    'limit',\n    'page',\n    'sqlFilters',\n    'category',\n    'thirdparties',\n    'mode',\n    'status',\n    'productIds',\n    'variantFilter',\n    'idsOnly',\n    'paginationData',\n    'includeStockData',\n    'includeCount',\n    'includeRole',\n    'type']\nfor (let index = 0; index < list.length; index++) {\n    const element = list[index];\n    if (msg[element] === undefined && (env.get(element) !== '' || env.get(element) !== null || env.get(element) !== undefined)){\n        msg[element] = env.get(element)\n    }else{\n        if (msg[element] === undefined || msg[element] === null){\n            node.warn(\"You have to configure the node in the panel editor or via msg property\");\n        }\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":80,"wires":[["82018866575fba41"]]},{"id":"6877cb437a61bf10","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"delete","p":"apiKey","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3090,"y":40,"wires":[[]]},{"id":"0c77d02d05c60bcf","type":"switch","z":"e0b88d23ec56febb","name":"","property":"eraseKey","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":2890,"y":120,"wires":[["6877cb437a61bf10"],[]]},{"id":"82018866575fba41","type":"subflow:54526e03f83ee9e5","z":"e0b88d23ec56febb","name":"","env":[{"name":"apiKey","type":"cred"},{"name":"clearHeaders","type":"bool","value":"false"},{"name":"eraseKey","type":"bool","value":"false"}],"x":490,"y":80,"wires":[["52c90dec905d5b6c"]]},{"id":"1f6de9ab648fec22","type":"subflow:54526e03f83ee9e5","z":"e0b88d23ec56febb","name":"","env":[{"name":"apiKey","type":"cred"}],"x":450,"y":480,"wires":[["8c598d4bd7834c04"]]},{"id":"8c598d4bd7834c04","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":460,"wires":[]},{"id":"3829fe4d1978f0e3","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":580,"wires":[]},{"id":"81474ab224fe0e13","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"protocol & '://' & host & ':' & port & '/api/slots' & (path != '' ? '/'&path : '')","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":200,"wires":[["770be6beb8328773"]]},{"id":"52c90dec905d5b6c","type":"change","z":"e0b88d23ec56febb","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"protocol & '://' & host  & (port ? ':' & port : '')  & '/api/index.php/' & objectName & '?'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":140,"wires":[["7df5b6af6b3b9f32","1348a42ec4b03de9"]]},{"id":"881f30591bb19ec3","type":"function","z":"e0b88d23ec56febb","name":"Add parametter global parameter to URL","func":"//sortField\nif(msg.sortField !== \"\"){\n    msg.url += 'sortfield=t.' + msg.sortField\n}\n//sortOrder\nif (msg.sortOrder !== \"\") {\n    msg.url += '&sortorder=' + msg.sortOrder\n}\n//limit\nif (msg.limit !== \"\") {\n    msg.url += '&limit=' + msg.limit\n}\n//page\nif (msg.page !== 0) {\n    msg.url += '&page=' + msg.page\n}\n//sqlFilters\nif (typeof msg.sqlFilters === 'string' && msg.sqlFilters !== ''){\n    msg.url += '&sqlfilters=' + msg.sqlFilters\n}\nif (typeof msg.sqlFilters === 'object' && msg.sqlFilters !== []){\n    let sqlFilters = ''\n    for (let i = 0; i < msg.sqlFilters.length; i++) {\n        if(i !== 0){\n            sqlFilters += ' ' + msg.sqlFilters[i].operation +' '\n        }\n        sqlFilters += '(' + msg.sqlFilters[i].attribute\n        sqlFilters += ':' + msg.sqlFilters[i].compare + ':'\n        sqlFilters += msg.sqlFilters[i].value + ')'\n    }\n    msg.url += '&sqlfilters=(' + sqlFilters + ')'\n    \n}\n//varianFilter\nif (msg.variantFilter !== 0) {\n    msg.url += '&variant_filter=' + msg.variantFilter\n}\n//idsOnly\nif (msg.idsOnly !== false) {\n    msg.url += '&ids_only=' + msg.idsOnly\n}\n//paginationData\nif (msg.paginationData !== false) {\n    msg.url += '&pagination_data=' + msg.paginationData\n}\n//mode\nif (msg.mode !== \"null\") {\n    msg.url += '&mode=' + msg.mode\n}\n//status\nif (msg.status !== \"null\") {\n    msg.url += '&mode=' + msg.status\n}\n//includeStockData\nif (msg.includeStockData !== false) {\n    msg.url += '&includestockdata=' + msg.includeStockData\n}\n//includeCount\nif (msg.includeCount !== false) {\n    msg.url += '&includecount=' + msg.includeCount\n}\n//includeRole\nif (msg.includeRole !== false) {\n    msg.url += '&includerole=' + msg.includeRole\n}\n//type\nif (msg.type !== \"\") {\n    msg.url += '&type=' + msg.type\n}\n//thirdpartyIds\n//if (msg.thirdpartyIds !== '' || msg.sqlFilters !== []) {\n//    if (typeof msg.sqlFilters === 'string') {\n//        msg.url += '&sqlfilters=' + msg.sqlFilters\n//    }\n//    if (typeof msg.sqlFilters === 'object') {\n//        let sqlFilters = ''\n//        for (let i = 0; i < msg.sqlFilters.length; i++) {\n//            if (i !== 0) {\n//                sqlFilters += ' ' + msg.sqlFilters[i].operation\n//            }\n//            sqlFilters += '(' + msg.sqlFilters[i].attribute\n//            sqlFilters += ':' + msg.sqlFilters[i].compare + ':'\n//            sqlFilters += msg.sqlFilters[i].value + ')'\n//        }\n//    }\n//}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1320,"y":80,"wires":[["796f7157d12daf87","5c0e995677254bcd"]]},{"id":"e9c33ced9f42dc2d","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":140,"wires":[]},{"id":"7df5b6af6b3b9f32","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1110,"y":180,"wires":[]},{"id":"5c0e995677254bcd","type":"http request","z":"e0b88d23ec56febb","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":1730,"y":200,"wires":[["c5214b76499a0c16"]]},{"id":"796f7157d12daf87","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1290,"y":160,"wires":[]},{"id":"c5214b76499a0c16","type":"debug","z":"e0b88d23ec56febb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1970,"y":40,"wires":[]},{"id":"1348a42ec4b03de9","type":"function","z":"e0b88d23ec56febb","name":"Handle special  case of \"type\" field ","func":"if(msg.objectName === 'categories'){\n    if(typeof msg.type === 'string' || msg.type !== ''){\n        //if ((typeof msg.sqlFilters === 'string' && msg.sqlFilters !== '')){\n        //    msg.sqlFilters += 'and(type:=:' + msg.type + ')'\n        //}\n        //if ((typeof msg.sqlFilters === 'string' && msg.sqlFilters === '')) {\n        //    msg.sqlFilters += '(type:=:' + msg.type + ')'\n        //}\n        if ((typeof msg.sqlFilters === 'object' && msg.sqlFilters !== [])){\n            let sqlFilter = {\n                'operation': 'and',\n                'comparate': '=',\n                'attribute': 'type',\n                'value': msg.type\n            }\n            msg.sqlFilters.push(sqlFilter)\n        }\n    }\n    if (typeof msg.type === 'object') {\n        if (msg.type.length === 0){\n\n        }else{\n            if (typeof msg.sqlFilters === 'string') {\n                for (let i = 0; i < msg.type.length; i++) {\n                    if (i === 0 && msg.sqlFilters === '') {\n                        msg.sqlFilters += '(type:=:' + msg.type[i] + ')';\n                    } else {\n                        msg.sqlFilters += 'and(type:=:' + msg.type[i] + ')';\n                    }\n                }\n            }\n        }\n        if ((typeof msg.sqlFilters === 'object' && msg.sqlFilters !== [])) {\n            for (let i = 0; i < msg.type.length; i++) {  \n                let sqlFilter = {\n                    'operation': 'and',\n                    'comparate': '=',\n                    'attribute': 'type',\n                    'value': msg.type[i]\n                }\n                msg.sqlFilters.push(sqlFilter)\n            }\n        }\n    }\n    msg.type = ''\n}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":980,"y":80,"wires":[["881f30591bb19ec3"]]},{"id":"51c5f776dee99f1c","type":"subflow:e0b88d23ec56febb","z":"9829dd4e1bc70eb2","name":"","env":[{"name":"protocol","value":"http","type":"str"},{"name":"host","value":"192.168.1.18","type":"str"},{"name":"port","value":"8300","type":"str"},{"name":"apiKey","type":"cred"},{"name":"objectName","value":"thirdparties","type":"str"},{"name":"sortField","value":"rowid","type":"str"},{"name":"sqlFilters","value":"[{\"attribute\":\"rowid\",\"compare\":\"=\",\"value\":1},{\"operation\":\"or\",\"attribute\":\"rowid\",\"compare\":\"=\",\"value\":2}]","type":"json"},{"name":"mode","value":null,"type":"str"},{"name":"status","value":null,"type":"str"},{"name":"method","value":null,"type":"str"}],"x":570,"y":140,"wires":[["441ad99fd381e879"]]}]

Flow Info

Created 2 years, 5 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x12)
  • comment (x1)
  • debug (x12)
  • function (x8)
  • http request (x4)
  • join (x1)
  • link in (x1)
  • link out (x1)
  • split (x1)
  • switch (x4)
Other
  • subflow (x2)
  • subflow:54526e03f83ee9e5 (x2)
  • subflow:e0b88d23ec56febb (x1)

Tags

  • Dolibarr
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option