Platform SDK gives You need to authenticate to be able to execute this request

1
*** ERROR *** Error: Request failed, POST '/v1/temporary-working-copies/' message: Response code 401 (Unauthorized) at createInformativeError (/Users/gerwin/Public/Projects/MendixSDKToolbox/node_modules/mendixplatformsdk/src/utils/RestConnector.js:153:26) at doRequest (/Users/gerwin/Public/Projects/MendixSDKToolbox/node_modules/mendixplatformsdk/src/utils/RestConnector.js:141:15) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async RestConnector.awaitTask (/Users/gerwin/Public/Projects/MendixSDKToolbox/node_modules/mendixplatformsdk/src/utils/RestConnector.js:85:24) at async workingCopyId.maxAttempts (/Users/gerwin/Public/Projects/MendixSDKToolbox/node_modules/mendixplatformsdk/src/clients/RepositoriesClient.js:31:30) at async retry (/Users/gerwin/Public/Projects/MendixSDKToolbox/node_modules/mendixplatformsdk/src/utils/retry.js:12:20) at async RepositoriesClient.createTemporaryWorkingCopy (/Users/gerwin/Public/Projects/MendixSDKToolbox/node_modules/mendixplatformsdk/src/clients/RepositoriesClient.js:30:31) at async App.createTemporaryWorkingCopy (/Users/gerwin/Public/Projects/MendixSDKToolbox/node_modules/mendixplatformsdk/src/object-api/App.js:31:31) at async main (/Users/gerwin/Public/Projects/MendixSDKToolbox/out/generate-delete-scripts.js:209:15) { responseData: '{"errorCode":"RS401","errorMessage":"You need to authenticate to be able to execute this request."}', responseStatus: 401 } I’m trying to implement the new SDK as described here: https://docs.mendix.com/apidocs-mxsdk/mxsdk/sdk-howtos/ I’ve created a Personal Access Token with the necessary scopes, but when I create a temporary working copy, I get the above error. I’ve added it to `terminal.integrated.env.osx` in the settings.json of my Visual Studio Code (if I don’t, it gives an error message that the environment variable MENDIX_TOKEN is missing – curiously it suggests to use this format: `[token] node script.js` but that doesn’t work either.              
asked
3 answers
1

Gerwin, check if the account you use to log in to the developer portal and that is associated with the PAT you generated requires SSO when you login to the portal. I found this issue myself, whereby I’ve actually created a Microsoft365 trial account just to sign up to Mendix with regular old username/password, invited myself with this new account to the app in question, generated a PAT with this account and overcome any authentication issues. I believe it’s accounts that are SSO-enabled that fail authentication with the repository services.

answered
0

I'm unsure if you've solved this one already but I was getting the same error. I followed the guide linked to in the mendix documentation for setting up a PAT https://docs.oracle.com/en/database/oracle/machine-learning/oml4r/1.5.1/oread/administrative-tasks-oracle-machine-learning-r.html#GUID-DD6F9982-60D5-48F6-8270-A27EC53807D0 and it still wasn't working. But after I closed VSC and opened it again it started working. Not sure if it just needed to be closed and re-opened to flush everything through but it works for me now. 

answered
-2

Hi,

  1. Make sure that the Personal Access Token you've generated has the necessary scopes. According to the Mendix documentation you linked, you need the "model" and "webservices" scopes for creating a temporary working copy. Double-check that you've included these scopes when creating the PAT.

  2. Since you mentioned adding the token to terminal.integrated.env.osx in the settings.json of Visual Studio Code, ensure that you've correctly set up the environment variable. It should be named MENDIX_TOKEN and its value should be your actual Personal Access Token

  3. It seems that you've tried different ways to use the token, including the [token] node script.js format. However, this format is not necessary if you've correctly set the environment variable. You can simply access the environment variable in your script using process.env.MENDIX_TOKEN.

  4. Verify that the token you're using is indeed associated with the user and the app that you are trying to access. Sometimes, generating a new token and ensuring it has the right scopes can help resolve issues like this.

answered