{ "nodes": [ { "name": "On clicking 'execute'", "type": "n8n-nodes-base.manualTrigger", "position": [ 270, 340 ], "parameters": {}, "typeVersion": 1, "id": "publish-reddit-post-and-comment-0" }, { "name": "Set post details", "type": "n8n-nodes-base.code", "typeVersion": 2, "parameters": { "mode": "runOnceForAllItems", "jsCode": "function input({subreddit,title,text,comment}){if(typeof subreddit!=='string'||!/^[A-Za-z0-9_]+$/.test(subreddit)||typeof title!=='string'||!title.trim()||[...title].length>300||typeof text!=='string'||!text.trim()||typeof comment!=='string'||!comment.trim())throw Error('Enter a subreddit without r/, a title, post text and comment');return {subreddit,title,text,comment}}\n\nreturn [{json:input({subreddit:'',title:'',text:'',comment:''})}];" }, "id": "publish-reddit-post-and-comment-1" }, { "name": "Reddit", "type": "n8n-nodes-base.reddit", "position": [ 470, 340 ], "parameters": { "resource": "post", "operation": "create", "kind": "self", "subreddit": "={{ $('Set post details').first().json.subreddit }}", "title": "={{ $('Set post details').first().json.title }}", "text": "={{ $('Set post details').first().json.text }}" }, "typeVersion": 1, "id": "publish-reddit-post-and-comment-2" }, { "name": "Confirm post creation", "type": "n8n-nodes-base.code", "typeVersion": 2, "parameters": { "mode": "runOnceForAllItems", "jsCode": "const id=$input.first().json.id;if(typeof id!=='string'||!/^[a-z0-9]+$/.test(id))throw Error('Post creation was not confirmed');return [{json:{id}}];" }, "id": "publish-reddit-post-and-comment-3" }, { "name": "Reddit1", "type": "n8n-nodes-base.reddit", "position": [ 670, 340 ], "parameters": { "resource": "post", "operation": "get", "subreddit": "={{ $('Set post details').first().json.subreddit }}", "postId": "={{ $json.id }}" }, "typeVersion": 1, "id": "publish-reddit-post-and-comment-4" }, { "name": "Confirm post identity", "type": "n8n-nodes-base.code", "typeVersion": 2, "parameters": { "mode": "runOnceForAllItems", "jsCode": "const p=$input.first().json,id=$('Confirm post creation').first().json.id,s=$('Set post details').first().json.subreddit;if(p.id!==id||typeof p.subreddit!=='string'||p.subreddit.toLowerCase()!==s.toLowerCase())throw Error('The created post could not be confirmed');return [{json:{id}}];" }, "id": "publish-reddit-post-and-comment-5" }, { "name": "Reddit2", "type": "n8n-nodes-base.reddit", "position": [ 870, 340 ], "parameters": { "resource": "postComment", "operation": "create", "postId": "={{ $json.id }}", "commentText": "={{ $('Set post details').first().json.comment }}" }, "typeVersion": 1, "id": "publish-reddit-post-and-comment-6" }, { "name": "Confirm comment", "type": "n8n-nodes-base.code", "typeVersion": 2, "parameters": { "mode": "runOnceForAllItems", "jsCode": "const c=$input.first().json,id=$('Confirm post creation').first().json.id;if(typeof c.name!=='string'||!/^t1_[a-z0-9]+$/.test(c.name)||c.parent_id!=='t3_'+id)throw Error('Comment creation was not confirmed');return [{json:c}];" }, "id": "publish-reddit-post-and-comment-7" } ], "connections": { "On clicking 'execute'": { "main": [ [ { "node": "Set post details", "type": "main", "index": 0 } ] ] }, "Set post details": { "main": [ [ { "node": "Reddit", "type": "main", "index": 0 } ] ] }, "Reddit": { "main": [ [ { "node": "Confirm post creation", "type": "main", "index": 0 } ] ] }, "Confirm post creation": { "main": [ [ { "node": "Reddit1", "type": "main", "index": 0 } ] ] }, "Reddit1": { "main": [ [ { "node": "Confirm post identity", "type": "main", "index": 0 } ] ] }, "Confirm post identity": { "main": [ [ { "node": "Reddit2", "type": "main", "index": 0 } ] ] }, "Reddit2": { "main": [ [ { "node": "Confirm comment", "type": "main", "index": 0 } ] ] } }, "name": "Publish a Reddit Post and Comment", "active": false, "settings": { "executionOrder": "v1" }, "pinData": {} }