- Joined
- May 20, 2024
- Messages
- 4
- Reaction score
- 0
Hello,
I am trying to programmatically change the "internal calls forwarding rules" settings using the 3CX REST API, but my server constantly returns a 401 Unauthorized status code. I have verified that the API token is copied directly from the 3CX web platform. I am using the Node.js framework for web requests and have also tried using tools like curl, but I am encountering the same issue.
Does anyone have any idea what might be wrong?
Here is an example of my code:
const axios = require('axios');
const apiBaseUrl = 'http://myserver/api';
const apiToken = 'myToken';
async function checkAuthentication() {
try {
const response = await axios.get(`${apiBaseUrl}/`, {
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json',
}
});
if (response.status === 200) {
console.log('Successfully authenticated to 3CX server');
} else {
console.log('Failed to authenticate to 3CX server');
}
} catch (error) {
if (error.response && error.response.status === 401) {
console.log('Authentication failed: Invalid API token or credentials');
console.log('Response from server:', error.response.data);
} else {
console.error('Error connecting to 3CX server:', error.message);
if (error.response) {
console.error('Server responded with:', error.response.data);
}
}
}
}
checkAuthentication();
Thank you in advance for your assistance!
I am trying to programmatically change the "internal calls forwarding rules" settings using the 3CX REST API, but my server constantly returns a 401 Unauthorized status code. I have verified that the API token is copied directly from the 3CX web platform. I am using the Node.js framework for web requests and have also tried using tools like curl, but I am encountering the same issue.
Does anyone have any idea what might be wrong?
Here is an example of my code:
const axios = require('axios');
const apiBaseUrl = 'http://myserver/api';
const apiToken = 'myToken';
async function checkAuthentication() {
try {
const response = await axios.get(`${apiBaseUrl}/`, {
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json',
}
});
if (response.status === 200) {
console.log('Successfully authenticated to 3CX server');
} else {
console.log('Failed to authenticate to 3CX server');
}
} catch (error) {
if (error.response && error.response.status === 401) {
console.log('Authentication failed: Invalid API token or credentials');
console.log('Response from server:', error.response.data);
} else {
console.error('Error connecting to 3CX server:', error.message);
if (error.response) {
console.error('Server responded with:', error.response.data);
}
}
}
}
checkAuthentication();
Thank you in advance for your assistance!