API Key not working in Powershell Step

We have a powershell script that uses the Octopus.Client.dll that runs fine when we run it from the powershell command line, but if we create an Octopus Script Step and include the powershell in a deployment (using the same API Key), we receive the message:

“You must be logged in to request this resource or provide a valid API key. Your account may have been disabled, please contact your Octopus administrator.”

If we run the script immediately after from the powershell command line, it works fine, so we know the account has not been disabled.

Any suggestions welcome… or can’t this be done?

Thanks
Jason

Hi Jason,

Sorry for the delay in responding here. Are you still experiencing this issue?

If you are, would you be able to attach a full raw deployment logs where you experience this issue?

It may also help if you could provide the API script which is failing in Octopus.

If the script is working manually outside of Octopus, it could suggest an issue with the account running the Octopus service on the target machine. Deployments from Octopus use the targets Octopus service account to execute scripts and the deployment. If this account is not able to execute this API script, you can run into these kind of issues.

Can you try manually running the failing script as the user which is running the Octopus service account?

Again, sorry for the delay in getting back to you here.

Best regards,
Daniel