UserNotFoundException thrown for an existing Relay API Key

When using defender-autotask-client to update an Autotask linked to a Relay from my terminal, I received the below error:

Failed to get a token for the API key redacted {
code: 'UserNotFoundException',
name: 'UserNotFoundException',
message: 'User does not exist.'
}

Upon going to the Relay terminal, I've confirmed several times that the API key and API secret do indeed match and it is active.

Thanks for any help! Love the product

:computer: Environment
Relay on Kovan
Autotask (fails to update code from defender-autotask-client)
MacOS 12.1
Bash

:1234: Code to reproduce

I answered my own question.

Defender API Key + Secret is used for remote usage

Team API Key is what is used for programmatically accessing various Defender admin capabilities, including Autotask code update.

Now I could delete this question to save face, but I'll leave it here in case someone else treads the same wrong path :wink:

2 Likes

Thanks @flaco_jones for leaving the Q&A here! I can tell you that you're not the first to run into this confusion. We'll make a note to make this difference clearer in Defender.

I think I'm running in the same confusion right now.

I understand how to obtain Team API-Key and Secret.

But what is a Defender-API-KEY and Secret? After creating a Relayer, I can get an API-KEY. But where can the Secret be found? I got only an address, a API Key and a private key.

There's a lot of functionality potential in Defender, so it's understandable to have some questions about which credentials point to what component!

Defender API Key/Secret and Team API Key/Secret refer to the same thing.

A Relayer can also have its own API key/secret.

You can create a Relayer and use it via an Autotask without ever creating credentials for that Relayer. The Autotask will have the Relayer's credentials securely/automatically available to it by specifying the Relayer's ID).

If, however, you would like to send/sign transactions with a Relayer (as when deploying a contract via Relayer, for one example), you need to use the relay-client package, supplying the Relayer's key/secret.

Following the steps in the link above will illustrate the necessary steps to make this happen:

  1. Supply your Team API key/secret to instantiate the relay-client
  2. Send a request via the client to create a Relayer
  3. Send a request via the client to create a key for that Relayer

Having finished those steps, you can then run ethers.js functions using the Relayer by specifying the Relayer object:

  const credentials = {apiKey: process.env.RELAYER_KEY, apiSecret: process.env.RELAYER_SECRET};
  const provider = new DefenderRelayProvider(credentials);
  const relaySigner = new DefenderRelaySigner(credentials, provider, { speed: 'fast' });
  
  const MyContract = await ethers.getContractFactory("SimpleRegistry");
  const myContract = await MyContract.connect(relaySigner).deploy().then(f => f.deployed());

Note that in this latter example, it's the Relayer key that is supplied.