Roket
1
It is required to create the following JSON file structure from a similar database template:
{
"action": "create_post",
"post_title": "<< [post_title] >>",
"post_status": "<< [post_status] >>",
"post_type": "<< [post_type] >>",
"tax_input": "tax_input 1, value_1; tax_input 2, value_2; tax_input N, value_N",
"meta_input":
{
"meta_input 1": "value_1",
"meta_input 2": "value_2",
"meta_input 3": "value_3",
"meta_input N": "value_N"
}
}
Hey, @Roket
Is it you database google sheets? If so could please share the sprite sheet?
Roket
3
What is the sprite sheet?
Yes, sheet created by me.
I meant the sheet. But don’t worry I’m already putting it together.
ok @Roket, this should do it. Keep me posted.
{
"nodes": [
{
"parameters": {},
"name": "Start",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
250,
300
]
},
{
"parameters": {
"functionCode": "return [\n {\n json: {\n post_title: \"testing\",\n post_status: \"status\",\n post_type: \"type\",\n tax_input: '',\n \"tax_input 1\": 'tax_input value 1',\n \"tax_input 2\": 'tax_input value 2',\n meta_input: '',\n \"meta_input 1\": 'meta_input value 1',\n \"meta_input 2\": 'meta_input value 2',\n }\n }\n]"
},
"name": "Function",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
460,
300
]
},
{
"parameters": {
"functionCode": "const result = [];\nfor (const item of items) {\n const json = item.json;\n let taxInputs = [];\n let metaInputs = {};\n for (const key of Object.keys(json)) {\n if (key.includes('tax_input') && key !== 'tax_input') {\n taxInputs.push(`${key}, ${json[key]}`);\n }\n if (key.includes('meta_input') && key !== 'meta_input') {\n metaInputs[key] = json[key];\n }\n }\n result.push({\n json: {\n action: \"create_post\",\n post_title: json['post_title'],\n post_status: json['post_status'],\n post_type: json['post_type'],\n tax_input: taxInputs.join(';'),\n meta_input: metaInputs,\n }\n })\n taxInputs = [];\n metaInputs = {};\n return result\n}"
},
"name": "Function1",
"type": "n8n-nodes-base.function",
"typeVersion": 1,
"position": [
660,
300
]
}
],
"connections": {
"Start": {
"main": [
[
{
"node": "Function",
"type": "main",
"index": 0
}
]
]
},
"Function": {
"main": [
[
{
"node": "Function1",
"type": "main",
"index": 0
}
]
]
}
}
}
2 Likes
Roket
6
Thanks again RicardoE105!
Of course. As always, let us know any further questions.