Documentation
Feedback
Guides
App Development

App Development
Services
Receiving Catalog Changes on VTEX IO

Recipe

  1. Clone the app https://github.com/vtex-apps/events-example

    • This example app also exports some service routes, but we're not gonna use it. Feel free to remove it, or integrate just the events section into another app. Every IO app is able to handle events with a node service.
  2. On node/service.json, change the event handler name and the keys. You can ditch the sender field as well. The final events section should be like so:


    _10
    "events": {
    _10
    "skuChange": {
    _10
    "keys": ["broadcaster.notification"]
    _10
    }
    _10
    },

    • The name skuChange you're free to change as well. This will be used to create the code to handle that event later on.
  3. After saving the node/service.json, let's edit the node/index.ts file, creating the handler function for our event. We are gonna use the key skuChange to that.


    _27
    export default new Service<IOClients, State, ParamsContext>({
    _27
    clients: {
    _27
    options: {
    _27
    events: {
    _27
    exponentialTimeoutCoefficient: 2,
    _27
    exponentialBackoffCoefficient: 2,
    _27
    initialBackoffDelay: 50,
    _27
    retries: 1,
    _27
    timeout: TREE_SECONDS_MS,
    _27
    concurrency: CONCURRENCY,
    _27
    },
    _27
    },
    _27
    },
    _27
    events: {
    _27
    skuChange: (ctx: any) => {
    _27
    console.log('Received SKU changed event')
    _27
    console.log(ctx.body)
    _27
    },
    _27
    },
    _27
    routes: {
    _27
    hcheck: (ctx: any) => {
    _27
    setCacheContext(ctx)
    _27
    ctx.status = 200
    _27
    ctx.body = 'ok'
    _27
    },
    _27
    },
    _27
    })

  4. Now, to test it on a workspace, follow the steps here

Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page