0

Following the developer docs, I have attempted numerous variations trying to achieve this.

I would like to extract the label from the token payload, if not I can build it from the /me response body.

This is my latest attempt:

var jwtDecode = require('jwt-decode');

const getTokenFields = (z, bundle) => {
  var sub = jwtDecode(bundle.authData.token)['sub']
  console.log(sub)
  return sub;
};

const getLabelField = (z, bundle) => {
  var sub = jwtDecode(bundle.authData.token)['sub']['label']
  console.log(sub)
  return sub;
};

const authentication = {
    type: 'session',
    test: {
        url: '{{process.env.AP_HOST}}/me'
    },
    fields: [
        {
            key: 'token',
            type: 'string',
            required: true,
            helpText: 'See settings to get your token'
        }
    ],
    sessionConfig: {
        perform: getTokenFields
    },
    connectionLabel: {
        perform: getLabelField
    }
};

module.exports = authentication;

the only thing that I can get to work is: connectionLabel: "{{bundle.authData.token}}", but it looks terrible!

connectionLabel: "{{bundle.authData.responsefield}}" feels like it should be something that should work but it doesn't either

xavdid
  • 5,092
  • 3
  • 20
  • 32
smactive
  • 58
  • 1
  • 7

1 Answers1

0

David here, from the Zapier Platform team.

Instead of connectionLabel: {perform: getLabelField}, it should just be connectionLabel: getLabelField. You can also use a string that pulls from the bundle (like you're seeing) or any data that comes back from the designated test endpoint (see here).

There should be validation that prevents what you have (that'll error when you run zapier validate) but if that comes back clean then definitely let us know.

xavdid
  • 5,092
  • 3
  • 20
  • 32
  • Hi David, thanks for your suggestion. When I try the following, it does pass validation, however in Zapier it does not show the correct label, it generates "#2" as the label – smactive Aug 07 '18 at 00:32
  • `connectionLabel: getLabelFromToken` – smactive Aug 07 '18 at 00:33