Help Webhoock parsing

Hello there :slight_smile:

I’m receiving the following webhoock, but can’t parse the data in order to map the data in the body > notif .

I tried with item list and some example found in code node to try to acces the data without succes.


[
{
"headers":
{
"x-real-ip":
"185.88.104.167",
"x-forwarded-for":
"185.88.104.167",
"host":
"6nyy9zv8ep4pma3w584kvjh1.hooks.n8n.cloud",
"x-forwarded-proto":
"https",
"x-nginx-proxy":
"true",
"connection":
"close",
"content-length":
173,
"user-agent":
"Sellsy Webhook v2.0 - curl",
"x-powered-by":
"Sellsy Software",
"accept":
"*/*",
"accept-encoding":
"gzip",
"tracestate":
"[email protected]=0-0-1045615-170427675-dd5bb969da3850c0-6c093028170c458d-1-1.486727-1669295145814",
"newrelic":
"eyJ2IjpbMCwxXSwiZCI6eyJ0eSI6IkFwcCIsImFjIjoiMTA0NTYxNSIsImFwIjoiMTcwNDI3Njc1IiwiaWQiOiJkZDViYjk2OWRhMzg1MGMwIiwidHIiOiI2YzA5MzAyODE3MGM0NThkIiwidHgiOiI2YzA5MzAyODE3MGM0NThkIiwicHIiOjEuNDg2NzMsInNhIjp0cnVlLCJ0aSI6MTY2OTI5NTE0NTgxNH19",
"traceparent":
"00-00000000000000006c093028170c458d-dd5bb969da3850c0-01",
"content-type":
"application/x-www-form-urlencoded"
},
"params":
{
},
"query":
{
},
"body":
{
"notif":
"{"eventType":"docslog","timestamp":"1669295144","event":"step","relatedid":"35484253","relatedtype":"estimate","ownerid":"155492","ownertype":"staff","corpid":"70575"}"
}
}
]

I’m trying to map and be able to work withe the eventType, timestamp, …

Thanks

I tried to use the code node with item.entries = JSON.parse(item.query.entries);
return item;
but getting an error ( I’m totally beginner in JS)

Welcome to the community @NicolasC!

You can use:

JSON.parse($input.first().body.notif)

or in a Code-Node:

return [
  {
    json: JSON.parse($input.first().body.notif)
  }
]

Thanks for your answer @jan,
still getting an error with the code-node but will test around in order to get it :slight_smile:

Problem in node ‘Code2‘

I’m testing in desktop on mac.
Cannot read properties of undefined (reading ‘notif’) [line 2]

TypeError: Cannot read properties of undefined (reading 'notif')
    at /private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code:2:40
    at /private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code:5:2
    at VM2 Wrapper.apply (/private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/vm2/lib/bridge.js:485:11)
    at Sandbox.run (/private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/vm2/lib/nodevm.js:426:23)
    at Sandbox.runCodeAllItems (/private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code/Sandbox.js:53:42)
    at Sandbox.runCode (/private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code/Sandbox.js:30:62)
    at Object.execute (/private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/n8n-nodes-base/dist/nodes/Code/Code.node.js:74:39)
    at Workflow.runNode (/private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/n8n-workflow/dist/src/Workflow.js:645:51)
    at /private/var/folders/9k/5j8f1sl97zdblz5yqzrs89wc0000gn/T/AppTranslocation/8C8026CD-0A55-429A-80C1-3C0DF51C26E0/d/n8n.app/Contents/Resources/app/node_modules/n8n-core/dist/src/WorkflowExecute.js:562:68

Hi @NicolasC, could you try using the snippet below instead? I believe there might have been a .json missing along the way:

return [
  {
    json: JSON.parse($input.first().json.body.notif)
  }
]

Or as a full workflow:

This works fine on the current version of the desktop app for me:

2 Likes

Thanks a lot :slight_smile: work perfectly ( and sorry for not understanding this directly , I need to read and learn JS, it will be usefull :wink: )

1 Like

Awesome, glad to hear this helps! And yes, things can be a bit tricky. Though hopefully you won’t need JS too often when using n8n :smiley:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.