Smart collection hooks routes

I’ve created a smart collection based on a API call.

const { collection } = require('forest-express-sequelize');

collection('sageProviders', {
  actions: [{
    name: 'Générer un ODS',
    type: 'single',
    fields: [{
      field: 'Copropriétaire',
      type: 'Enum',
      enums: []
    }, {
      field: 'Type ODS',
      type: 'Enum',
      enums: [
        'Avec devis',
        'Sans devis',
        'Demande de devis'
      ]
    }, {
      field: 'Descriptif intervention',
      type: 'String'
    }, {
      field: 'Date intervention souhaitée',
      type: 'Date'
    }, {
      field: 'Informations détaillées pour le fournisseur',
      type: 'String'
    }],
    hooks: {
      load: ({ fields, record }) => {
        console.log('record: ', record);
        return fields;
      }
    },
  }],
  fields: [{
    field: 'id',
    type: 'String',
    get: record => record.matricule
  }, {
    field: 'matricule',
    type: 'String',
  }, {
    field: 'siret',
    type: 'String'
  }, {
    field: 'raison_sociale',
    type: 'String'
  }, {
    field: 'site_adresse',
    type: 'String'
  }, {
    field: 'site_ville',
    type: 'String'
  }, {
    field: 'site_codepostal',
    type: 'String'
  }, {
    field: 'telephone',
    type: 'String'
  }, {
    field: 'email',
    type: 'String'
  }, {
    field: 'bic',
    type: 'String'
  }, {
    field: 'iban',
    type: 'String'
  }, {
    field: 'street_number',
    type: 'String'
  }, {
    field: 'street',
    type: 'String'
  }]
});

routes/

// Get a list of sageProviders
router.get('/sageProviders', permissionMiddlewareCreator.list(), (request, response, next) => {
  const recordSerializer = new RecordSerializer({ name: 'sageProviders' });
  const params = {
    provider_name: '',
    siret: '',
    matricule: ''
  };

  axios.get(
    `${API_URL}/forest_admin/sage_providers`, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
      'X-CURRENT-USER-EMAIL': request.user.email
    },
    params
  }).then(async res => {
    response.send({
      ...(await recordSerializer.serialize(res.data)),
      meta: {
        count: res.data.length
      }
    });
  }).catch(err => {
    response.status(400).send({ error: err.response.data.error.message });
  });
});

///////////////////////////////////////////////////////////////////////////////

// Get a sageProvider
router.get('/sageProviders/:matricule', permissionMiddlewareCreator.details(), (request, response, next) => {
  const recordSerializer = new RecordSerializer({ name: 'sageProviders' });
  const matricule = request.params.matricule;
  const params = {
    provider_name: '',
    siret: '',
    matricule
  };

  axios.get(
    `${API_URL}/forest_admin/sage_providers`, {
    headers: {
      'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
      'X-CURRENT-USER-EMAIL': request.user.email
    },
    params
  }).then(async res => {
    response.send({
      ...(await recordSerializer.serialize(res.data[0])),
      meta: {
        count: res.data.length
      }
    });
  }).catch(err => {
    response.status(400).send({ error: err.response.data.error.message });
  });
});

when I open my smart action, I get
POST /forest/actions/generer-un-ods/values 404 176 - 26.590 ms
POST /forest/actions/generer-un-ods/hooks/load 404 180 - 19.146 ms

I guess I need to recreate these routes but I have no idea how to do it.

Hi @JeremyV,

Smart Actions hooks on Smart Collections is, I think, something we support on the recent agent versions.
v7.4.0 of forest-express-sequelize npm package for instance.

Can you share with us, which agent version you are using so far?

indeed i am in v6.7.1. Updating now…

Edit :

npm update forest-express-sequelize

updated it to v6.7.11. What am I missing ?

My dependencies are :

    "axios": "^0.21.1",
    "axios-curlirize": "^1.3.7",
    "body-parser": "1.19.0",
    "chalk": "~1.1.3",
    "cookie-parser": "1.4.4",
    "cors": "2.8.5",
    "custom-env": "^2.0.1",
    "date-fns": "^2.16.1",
    "debug": "~4.0.1",
    "dotenv": "~6.1.0",
    "express": "~4.16.3",
    "express-jwt": "5.3.1",
    "forest-express": "^7.9.4",
    "forest-express-sequelize": "^6.7.11",
    "moment": "^2.29.1",
    "morgan": "1.9.1",
    "nodemon": "^2.0.7",
    "pg": "~8.2.2",
    "require-all": "^3.0.0",
    "sequelize": "~5.15.1"

Hey @JeremyV !

You need to run npm i forest-express-sequelize@7.4.0 to update to the version mentioned by @arnaud .

Be careful as there are some breaking changes for the v7 upgrade. An upgrade note detailing those is available here.

Hope this helps!