Smart Action load hook - endpoints 404 error

Context

Hello,
I’m trying to use the load hook for a smart action called upload-assets. At the moment I’m just trying to log what is in the context object and returning the fields back like the docs suggest:

  hooks: {
      load: ({ fields, record }) => {
        console.log("FIELDS")
        console.log(fields)
        console.log("RECORD")
        console.log(record)
        return fields;
      },
    },

The problem is that as soon as I open the smart action from Forest Admin’s UI I see it trying to call two different endpoints:

  • /forest/actions/upload-assets/values
  • /forest/actions/upload-assets/hooks/load

and because they don’t exist I get a 404 (The route called on form load is not reachable) from express and the smart action doesn’t work (the load function is never called). I didn’t find in the docs anythining mentioning that I should implement these two endpoints. The only suggestion is the one to handle the smart action that I already have in place: /actions/upload-assets.
I’m kinda lost here and couldn’t find any direction in the docs or any issues mentioning this error. Could you please point me in any direction here?

Thanks and have a good day!

  • Package Version: 7.2.2
  • Express Version: 4.17.1
1 Like

Hi @nathanqueija and welcome to the ForestAdmin community,

I just tested the load hook on my end and it seems to work properly. There might be a bad configuration in the all smart action, could you please share the all action definition please?

For your concerns those two routes are called to prefill smart action fields with default values:

  • The /forest/actions/upload-assets/values is used to provide static default values and is not defined on your end, leading to a 404 error which is normal behavior here.
  • On the other hand, /forest/actions/upload-assets/hooks/load is used to provide dynamic default values and it looks properly defined on your end.

Hey @anon37102731 . Here’s the definition of the action within the file:

collection('templates', {
  actions: [{
    name: 'Upload Assets',
    type: 'single',
    hooks: {
      load: ({ fields, record }) => {
        console.log("FIELDS")
        console.log(fields)
        console.log("RECORD")
        console.log(record)
        return fields;
      },
    },
    fields: [
      {
        field: 'Name',
        description: 'Preview image',
        type: 'String',
      },
      {
        field: 'Poster',
        description: 'Preview image',
        type: 'File',
      }, {
        field: 'Video',
        description: 'Video preview',
        type: 'File',
      }
    ]
  },],
  fields: [
    { field: "id", type: "String" },
    { field: "name", type: "String" },
    { field: "description", type: "String" },
    { field: "creator", type: "String" },
    { field: "assetKey", type: "String" },
    { field: "slides", type: "String" },
    { field: "poster", type: "String" },
    { field: "video", type: "String" }
  ],
  segments: [],
})

@nathanqueija,

With the exact same smart action definition as yours and being on the exact same forest-express-sequelize version as yours, my load hook gets called properly.

Is the /forest/actions/upload-assets/hooks/load call still returning a 404 response? If so, could you try to stop and restart your API?

Thank you

Well, I just restarted the server and now I’m getting this error:

I didn’t change anything in the code :sweat:

This is what is being thrown in the console:

And also all of my settings for the fields are gone on Forest Admin :confused:

@nathanqueija could you try to log out and access the project again through the https://app.forestadmin.com/projects page?

@anon37102731 already did. Three times and the error persists. I can only see the data in the table view (with all the previous fields settings missing), but can’t see the details view.

@anon37102731 I discussed with @nathanqueija and we can now display the record detail by checking the option “allow record detail display” :+1:

But the issue with the smart action Hooks still persists.

:bulb: For info this action is defined on a smart collection (“templates”)

Hi @nathanqueija,

I’ve been able to reproduce your issue. It seems that our current hooks on smart action’s implementation is not supported on smart collection.

I created a bug entry for it. You can track its status here:

Hello @nathanqueija :wave:

We have juste released a new version of forest-express-sequelize :tada: for supporting this feature.
Could you try with the new 7.4.0 version please.

Let me know if everything is ok :slight_smile:

2 Likes

Hey @Guillaume_Cisco . Good news. I’ll give it a try. Thanks!

1 Like