Google Tag Manager

Forum Discussion

emily_wri's avatar
emily_wri
Supporter
2 months ago

WordPress API to Catalogs

Hi all, 

I'm trying to automate the process of getting our blog posts (on wordpress) updated to a catalog. Ideally, this would automatically create a new catalog item when a new blog was created and would update images and information when an existing blog post is updated. 

Does anyone have experience doing this and how was it accomplished? Is it working for you?

Thanks!

4 Replies

  • You could also do this purely in Braze using connected content and webhooks. e.g.

    PUT https://rest.iad-XX.braze.com/catalogs/events/items

    In your webhook body, get today's posts from Wordpress

    {% assign today_start = now | date: "%Y-%m-%dT00:00:00" %}
    {% assign today_end   = now | date: "%Y-%m-%dT23:59:59" %}
    {% connected_content
      https://your-site.com/wp-json/wp/v2/posts?status=publish&after={{ today_start | url_encode }}&before={{ today_end | url_encode }}&per_page=20&orderby=date&order=desc&_fields=id,title,link,date
      :method get
      :retry 1
      :save posts
    %}

    And then loop through the items if there are any e.g. 

    {% if posts and posts.size > 0 %}
    {
      "items": [
      {% for p in posts %}
    {
      "id": "{{p.id}}",
      "title": "{{p.title}}",
      "link": "{{p.link}}",
    }{% if forloop.last %}{% else %},{% endif %}
    {% endfor %}
      ]
    }
    {% endif %}

    Depending on how often you're updating the blog, schedule it to run a few times a day

  • Anna180's avatar
    Anna180
    Collaborator

    Hi Emily,

    Automating updates from WordPress to a catalog can definitely save a lot of time. One approach is to use automation tools that handle data syncing and updates efficiently. Some users combine these with scripts or APIs to create new catalog items automatically whenever a blog post is published or updated. It might take a bit of setup, but once configured, it can keep your catalog fully up to date without manual work.