Wordpress custom post types

Hi all, I’ve got N8N up and running!
I’m hoping to use it to do the following:
Each time a post is added, an object is created in HubSpot. I’ve got this working for traditional post, but my Wordpress uses custom post types. All of the json info is public at Best Website Builder | Create Websites Easy – Yoursite.com
Is it possible to get N8N to pull posts from this endpoint?

Welcome to the community.

Not sure if I understood well, but if you want to get that JSON into n8n, you can use the HTTP node.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "https://carenav.co.uk/wp-json/geodir/v2/norfolkandwaveney",
        "options": {}
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        550,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const data = items[0].json\n\nconst results = [];\n\nfor (const item of data) {\n    results.push({\n      json: item\n    })\n}\n\nreturn results;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        790,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Thanks @RicardoE105, really appreciate it!
Forgive my ignorance, I’m very new to api, and I’ve tried reading the n8n docs but I’m not sure where to use that code you’ve provided. I’ve used the http request node which provides the following (image)

All I need from here is the ‘title’ and ‘link’ to create a new object in Hubspot. Thanks again for your help!

No problem. Just copy the code I just provided and paste it in the workflow editor. Just add the hubspot node at the end and it should do it. Did not add it myself cuz I do not know how you wanted to save in hubspot.

Also so that you know, if you want to react every-time a post is added, you are gonna need a bit more work. If I were you I would add a plugin for webhooks in your wordpress instance, catch the event with a webhook node and then get that data into hubspot.

Thank you, it seems I’ve still got a lot to learn!

@RicardoE105 - please forgive me! I’m still unsure where to insert the code you’ve provided.
Also, the update doesn’t necessarily need to be instant. Would it be easier to run via cron or instantly via a webhook (using a wordpress plugin)?

please forgive me! I’m still unsure where to insert the code you’ve provided.

https://www.loom.com/share/5b92d213cecb4213a0d0069c5f6d60c9

Also, the update doesn’t necessarily need to be instant. Would it be easier to run via cron or instantly via a webhook (using a wordpress plugin)?

you could use the cron node to check for updates every x time, but it will be more difficult as you have to always check if there is new data. Using the webhook this is handled for you. btw I have not ever used a webhook plugin for WordPress, I’m just guessing that one must exist.

https://wordpress.org/plugins/search/webhooks/

1 Like

oh! As easy at that! Now I feel stupid!

you could use the cron node to check for updates every x time, but it will be more difficult as you have to always check if there is new data. Using the webhook this is handled for you. btw I have not ever used a webhook plugin for WordPress, I’m just guessing that one must exist.

Makes sense! Hubspot’s API is capable of checking for new posts, but a webhook would make more sense. This is very helpful, thank you so much!

1 Like

Hi @RicardoE105,
Just a note to say thank you again!
It’s working perfectly! Each new post sends a webhook to n8n, which works its magic and adds to hubspot just as I needed.

I’m running n8n through PM2 to keep it active. However, doing it this way doesn’t load any configuration, specifically my authentication. If I run n8n the usual way, the configuration loads fine (I’m using a config file), but I need n8n to always be running. Any thoughts?

EDIT for those experiencing similar: I was using a custom configuration file rather than a .env file. Since using a .env file all is working perfectly. Thanks again for an incredible app and supportive forum!

2 Likes