K
Kinde4mo ago
Parth

Not able to create/read environment variable using management API

I'm trying to create an environment variable using management api: import { EnvironmentVariables } from '@kinde/management-api-js'; I've set all the scopes related to environment variables in M2M application already. Though whenever I try to read/create environment variable I'm getting below error:
S [ApiError]: Invalid request.
at or (D:\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:49952)
at D:\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:50557
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
url: 'https://{my-kinde-domain}/api/v1/environment_variables/q',
status: 400,
statusText: 'Bad Request',
body: { errors: [ [Object] ] },
request: {
method: 'GET',
url: '/api/v1/environment_variables/{variable_id}',
path: { variable_id: 'q' },
errors: {
'400': 'Invalid request.',
'403': 'Unauthorized - invalid credentials.',
'429': 'Too many requests. Request was throttled.'
}
}
}
S [ApiError]: Invalid request.
at or (D:\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:49952)
at D:\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:50557
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
url: 'https://{my-kinde-domain}/api/v1/environment_variables/q',
status: 400,
statusText: 'Bad Request',
body: { errors: [ [Object] ] },
request: {
method: 'GET',
url: '/api/v1/environment_variables/{variable_id}',
path: { variable_id: 'q' },
errors: {
'400': 'Invalid request.',
'403': 'Unauthorized - invalid credentials.',
'429': 'Too many requests. Request was throttled.'
}
}
}
All other management APIs are working fine, only these environment variables related APIs are giving error Help me why this error is occuring?
5 Replies
Roshan
Roshan4mo ago
Hi, The error you're encountering is a 400 Bad Request with the URL showing /api/v1/environment_variables/q, which indicates you're passing an invalid variable_id parameter. Looking at your error, the issue appears to be that you're passing 'q' as the variable_id, but environment variable IDs should follow a specific format. According to the API documentation, environment variable IDs should look like env_var_0192b1941f125645fa15bf28a662a0b3. To get a specific environment variable, you need a valid environment variable ID.
//Use a proper environment variable ID:
const variableId = 'env_var_0192b1941f125645fa15bf28a662a0b3';
const response = await EnvironmentVariables.getEnvironmentVariable(variableId);
//Use a proper environment variable ID:
const variableId = 'env_var_0192b1941f125645fa15bf28a662a0b3';
const response = await EnvironmentVariables.getEnvironmentVariable(variableId);
Let me know if this helps, Thanks
Parth
ParthOP4mo ago
@Abdiwak - Kinde Hi, thanks for reply. But when i try to create one, im getting below error:
S [ApiError]: Invalid request.
at or (D:\pap-api\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:49952)
at D:\pap-api\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:50557
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
url: 'https://<my-kinde-domain>/api/v1/environment_variables',
status: 400,
statusText: 'Bad Request',
body: { errors: [ [Object] ] },
request: {
method: 'POST',
url: '/api/v1/environment_variables',
body: {
key: 'org_857450760c0eb-org_857450760c0eb',
value: 'pdp_c2363ff2241a44b19766759ff4ecdbdd-org_857450760c0eb-prj_73b91d6b4bf6493fbabfc168380d9034',
is_secret: false
},
mediaType: 'application/json',
errors: {
'400': 'Invalid request.',
'403': 'Unauthorized - invalid credentials.',
'429': 'Too many requests. Request was throttled.'
}
}
}
S [ApiError]: Invalid request.
at or (D:\pap-api\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:49952)
at D:\pap-api\node_modules\@kinde\management-api-js\dist\kinde-management-api-js.cjs:1:50557
at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
url: 'https://<my-kinde-domain>/api/v1/environment_variables',
status: 400,
statusText: 'Bad Request',
body: { errors: [ [Object] ] },
request: {
method: 'POST',
url: '/api/v1/environment_variables',
body: {
key: 'org_857450760c0eb-org_857450760c0eb',
value: 'pdp_c2363ff2241a44b19766759ff4ecdbdd-org_857450760c0eb-prj_73b91d6b4bf6493fbabfc168380d9034',
is_secret: false
},
mediaType: 'application/json',
errors: {
'400': 'Invalid request.',
'403': 'Unauthorized - invalid credentials.',
'429': 'Too many requests. Request was throttled.'
}
}
}
Roshan
Roshan4mo ago
In that case, may be your key might be causing issues because: - It uses hyphens instead of underscores For your specific case, I recommend: Stick with UPPER_SNAKE_CASE (underscores only, no hyphens).

Can you check this approach and let me know.
Thanks
Parth
ParthOP4mo ago
Oh yes, that was the issue Thanks
Roshan
Roshan4mo ago
Glad it works.
Let us know if you encountered any issues. Thanks

Did you find this page helpful?