Context.values.get for secret return undefined

Hello,
I have and secret “sendgrid_api_key” defined in Realm UI!
Screenshot 2020-12-07 at 00.17.35|690x282
When I try to get this value inside the function it returns undefined.

exports = async (username, tokenId, token) => {

  console.log("sendgrid_api_key", context.values.get("sendgrid_api_key"));

  const body = {
    personalizations: [{ to: [{ email: username }] }],
    from: { email: "test@test.com" },
    subject: `Hi ${username} reset email`,
    content: [
      {
        type: "text/plain",
        value: "test",
      },
    ],
  };

  return context.http.post({
    url: "https://api.sendgrid.com/v3/mail/send",
    headers: {
      Authorization: [`Bearer ${context.values.get("sendgrid_api_key")}`],
    },
    body: JSON.stringify(body),
    encodeBodyAsJSON: true,
  });
};

Executing this function logs sendgrid_api_key undefined
What am I doing wrong?

1 Like

Ok, nevermind I just found solution in docs

You cannot directly read the value of a Secret after defining it. Instead, you link to the Secret by name in authentication provider and service configurations. If you need to access the Secret from a Function or Rule, you can link the Secret to a Value.

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.