I think I need "Code" here: planned workflow, newbie issues with JSON

It seems I have to learn basics of Javascript to get on with my given task.
Pls forgive my newbie questions.

Currently I want to manipulate data I get out of querying the Zammad DB into manageable objects (if that is the right term anyway :wink: )
some
See what I get so far:

[

{
"id":452,
"ticket_id":257,
"type_id":1,
"sender_id":2,
"from":"[email protected]",
"to":"'Ihr Team' <[email protected]>",
"subject":"Anfrage",

[..]

},
{
"id":456,
"ticket_id":257,
"type_id":1,
"sender_id":2,
"from":"[email protected]",
"to":"'Ihr Team' <[email protected]>",
"subject":"Anfrage 2",

[..]

},
{
"id":459,
"ticket_id":257,
"type_id":1,
"sender_id":2,
"from":"[email protected]",
"to":"'Ihr Team' <[email protected]>",
"subject":"Anfrage 3",

[..]
}
]

My goal is to “cut out” each of the articles (identified by “id”) into a separate object.
I am sure I can access that object by using the right syntax …

Each of these objects (called articles in Zammad terms) should be transformed into a HTML block, later with applied css.

Basically I want to rebuild the whole Zammad ticket:

a ticket with “ticket-id” contains of articles with “article-ids”, and articles may contain attachments with “attachment-ids”.

I think I have the 3 lists(?) as json already, now I look how I can build one large json containing all the necessary parts (at least I think this should be the way, correct me if I am wrong).

After having the large json I want to make HTML out of it, then pipe it into Gotenberg for getting a pretty pdf.

Is that a reasonable plan? help appreciated!

Looked at the json more closely.

Seems as if the field “body” inside of each article already contains HTML. So maybe picking this along the id etc might already do the trick.

And observation 2: if I paste that json in https://codebeautify.org/jsonviewer it tells me the json isn’t valid, although it comes out of the HTTP Request Node without obvious errors.

Searching for howtos now to learn things …

A bit of progress here: added the option “Split Into Items” in my HTTP Request: much better output, now I get the individual articles separated.

step by step

1 Like

Hi @sgw, the invalid JSON might be caused by n8n - the UI views don’t always present you with a fully valid structure. You can, however, copy the underlying data by first selecting the data block you want to copy (by clicking in the empty line next to it), then using the copy button appearing in the UI and picking “Copy Selection”:

The easiest way to convert data like the example structure you have shared into HTML would be through the Spreadsheet File node. This node can create HTML tables using the Write to File operation:

In a workflow this would look like so:

@MutedJam Thank you. Both tips work for me.

Once back to the question in I think I need "Code" here: planned workflow, newbie issues with JSON → as mentioned I will have to merge the output of several nodes in one place: building a ticket from its components. I am unsure if to do it in JSON or HTML. Maybe I could look things up in Zammad’s repo :wink: they do exactly the same thing when generating the HTML5 code for the view in the web application. I am no web designer at all unfortunately.

Maybe it’s more elegant to generate HTML out of the separate parts (ticket-articles etc) and merge them in a last step. Hints welcome.

Maybe I should set up some mock data, and share my small workflow.

Tbh, I am not a web designer either so wouldn’t know how to make this “nice” :see_no_evil:

If the HTML generated by the Spreadsheet File node isn’t suitable for you could consider an approach as suggested here to build a custom HTML structure. This example workflow is using Google Sheets as the data source, but the basic approach should work for other sources as well of course.