Moralis auth request-message failing with bad request

Hi folks, could i get some help with the Moralis V2 Auth API request-message API call. When i call the emdpoint i get a request failed with status code 400 message. Please see below for full error message i have removed the wallet address on purpose:

Some help would be this would be great.

POST /request-message 400 0.800 ms - 44
MoralisError [Moralis SDK Core Error]: [C0006] Request failed, Bad Request(400): Unauthorized
at RequestController.makeError (/Users/davidjamison/lettsart/lettsartblockchain/node_modules/@moralisweb3/core/lib/controllers/RequestController/RequestController.js:119:20)
at RequestController. (/Users/davidjamison/lettsart/lettsartblockchain/node_modules/@moralisweb3/core/lib/controllers/RequestController/RequestController.js:100:38)
at step (/Users/davidjamison/lettsart/lettsartblockchain/node_modules/@moralisweb3/core/lib/controllers/RequestController/RequestController.js:44:23)
at Object.throw (/Users/davidjamison/lettsart/lettsartblockchain/node_modules/@moralisweb3/core/lib/controllers/RequestController/RequestController.js:25:53)
at rejected (/Users/davidjamison/lettsart/lettsartblockchain/node_modules/@moralisweb3/core/lib/controllers/RequestController/RequestController.js:17:65)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
isMoralisError: true,
code: ‘C0006’,
details: {
status: 400,
response: {
status: 400,
statusText: ‘Bad Request’,
headers: [Object],
config: [Object],
request: [ClientRequest],
data: [Object]
}
},
[cause]: [AxiosError: Request failed with status code 400] {
code: ‘ERR_BAD_REQUEST’,
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 10000,
xsrfCookieName: ‘XSRF-TOKEN’,
xsrfHeaderName: ‘X-XSRF-TOKEN’,
maxContentLength: -1,
maxBodyLength: -1,
env: [Object],
validateStatus: [Function: validateStatus],
headers: [Object],
url: ‘https://authapi.moralis.io/challenge/request/evm’,
params: {},
method: ‘post’,
data: ‘{“chainId”:“0x1”,“address”:“DIDNTWANTTOPOSTWALLETADDRESS”,“domain”:“app.lettsart”,“statement”:“Please sign this message to confirm your identity.”,“uri”:“http://localhost:4200/","timeout”:60}’
},
request: ClientRequest {
_events: [Object: null prototype],
_eventsCount: 7,
_maxListeners: undefined,
outputData: [],
outputSize: 0,
writable: true,
destroyed: false,
_last: true,
chunkedEncoding: false,
shouldKeepAlive: false,
maxRequestsOnConnectionReached: false,
_defaultKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: ‘’,
finished: true,
_headerSent: true,
_closed: false,
socket: [TLSSocket],
_header: ‘POST /challenge/request/evm HTTP/1.1\r\n’ +
‘Accept: application/json, text/plain, /\r\n’ +
‘Content-Type: application/json\r\n’ +
‘x-moralis-platform: JS SDK\r\n’ +
‘x-moralis-platform-version: 2.7.4\r\n’ +
‘x-moralis-build-target: node\r\n’ +
‘x-api-key: F\r\n’ +
‘User-Agent: axios/0.27.2\r\n’ +
‘Content-Length: 205\r\n’ +
‘Host: authapi.moralis.io\r\n’ +
‘Connection: close\r\n’ +
‘\r\n’,
_keepAliveTimeout: 0,
_onPendingData: [Function: nop],
agent: [Agent],
socketPath: undefined,
method: ‘POST’,
maxHeaderSize: undefined,
insecureHTTPParser: undefined,
path: ‘/challenge/request/evm’,
_ended: true,
res: [IncomingMessage],
aborted: false,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
reusedSocket: false,
host: ‘authapi.moralis.io’,
protocol: ‘https:’,
_redirectable: [Writable],
[Symbol(kCapture)]: false,
[Symbol(kNeedDrain)]: false,
[Symbol(corked)]: 0,
[Symbol(kOutHeaders)]: [Object: null prototype],
[Symbol(kUniqueHeaders)]: null
},
response: {
status: 400,
statusText: ‘Bad Request’,
headers: [Object],
config: [Object],
request: [ClientRequest],
data: [Object]
}
}
}

please see here how to post code on forum:

1 Like

also, try to remove the api key from the code that you post

1 Like

are you sure that you provided the right API key?

you can also test it here https://authapi.moralis.io/api-docs/

ah i didnt see that, removed now, thank you

@cryptokid Thanks for helping out with this, ive got the correct API Key. When i use the test swagger here: https://authapi.moralis.io/api-docs/ and enter our API key i still get a 400 unauthorised error.

Is there anyway that Moralis can see my requests hitting the platform to get a view whats happening here? Also is there a special why you need to setup the Moralis server to be able to use the auth API?

if you use your api key here then it works?

I checked your account and it has a totally different api key than what you had in the original code

you have to use the web3api key, not something else