{"record":{"id":"bcbd9a650e664885","repo":"juspay/hyperswitch","slug":"api-key-create-call-failed-with-status-response","errorCode":null,"errorMessage":"API Key create call failed with status ${response.status} and message: \"${response.body.error.message}\"","messagePattern":"API Key create call failed with status (.+?) and message: \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cypress-tests/cypress/support/commands.js","lineNumber":1383,"sourceCode":"\n    cy.wrap(response).then(() => {\n      if (response.status === 200) {\n        expect(response.body.merchant_id).to.equal(merchantId);\n        expect(response.body.description).to.equal(\n          apiKeyCreateBody.description\n        );\n\n        // API Key assertions are intentionally excluded to avoid being exposed in the logs\n        expect(response.body).to.have.property(keyIdType).and.to.include(keyId)\n          .and.to.not.be.empty;\n\n        globalState.set(\"apiKeyId\", response.body.key_id);\n        globalState.set(\"apiKey\", response.body.api_key);\n\n        cy.task(\"setGlobalState\", globalState.data);\n      } else {\n        // to be updated\n        throw new Error(\n          `API Key create call failed with status ${response.status} and message: \"${response.body.error.message}\"`\n        );\n      }\n    });\n  });\n});\n\nCypress.Commands.add(\"apiKeyUpdateCall\", (apiKeyUpdateBody, globalState) => {\n  const merchantId = globalState.get(\"merchantId\");\n  const apiKeyId = globalState.get(\"apiKeyId\");\n  // We do not want to keep API Key forever,\n  // so we set the expiry to tomorrow as new merchant accounts are created with every run\n  const expiry = isoTimeTomorrow();\n\n  // Update request body\n  apiKeyUpdateBody.expiration = expiry;\n\n  cy.request({","sourceCodeStart":1365,"sourceCodeEnd":1401,"githubUrl":"https://github.com/juspay/hyperswitch/blob/9b8b89dc378b62c9a6feda647bad4719d2de7699/cypress-tests/cypress/support/commands.js#L1365-L1401","documentation":"Thrown by the apiKeyCreateTest command (cypress-tests/cypress/support/commands.js:1383) when POST {baseUrl}/api_keys/{merchantId} returns non-200. The call authenticates with globalState.get('adminApiKey') (the admin key, not the merchant key), sets expiration to tomorrow via isoTimeTomorrow(), and on success stores apiKeyId/api_key into globalState — so this failure cascades into every later command that needs a merchant api-key.","triggerScenarios":"Invalid or expired adminApiKey (401); merchantId missing or deleted so the URL targets a non-existent resource (404); server rejecting the expiration/description body (400); 5xx from the api_keys service; validateEnv(baseUrl, 'key_id') misconfiguration producing a malformed request.","commonSituations":"The admin API key env var was rotated between runs; CI secrets not injected so adminApiKey is undefined; the merchant record was purged on the target environment; the env key-id prefix doesn't match what the environment issues, breaking the success-path assertions after a 200.","solutions":["Verify the admin API key env var is set, current, and belongs to the same environment as baseUrl","Confirm globalState.get('merchantId') came from a successful merchant-create step in this run","Grab the logged x-request-id and inspect the server logs for the exact rejection","Check the apiKeyCreateBody fixture (description/name) matches the current api_keys schema","Fix credentials and re-run — all subsequent steps depend on apiKeyId/api_key this command sets"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!globalState.get('adminApiKey')) {\n  throw new Error('adminApiKey missing from globalState — check env/secrets before apiKeyCreateTest');\n}","typeGuard":null,"tryCatchPattern":"cy.on('fail', (err) => {\n  if (err.message.includes('API Key create call failed')) {\n    throw new Error(`Setup gate: API key provisioning failed — every later step needs apiKey/apiKeyId. Root cause: ${err.message}`);\n  }\n  throw err;\n});","preventionTips":["Fail fast on a missing adminApiKey before the run starts","Treat this command as a gate: everything after it depends on apiKeyId/api_key","Rotate secrets before launching a long suite, not midway"],"tags":["cypress","hyperswitch","api-key","admin-key","authentication"],"backgroundTag":null,"analyzedSha":"9b8b89dc378b62c9a6feda647bad4719d2de7699","analyzedAt":"2026-08-16T09:01:53.433Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}