I am trying to make use of UDEMY API. Each request must contain Authorization: Basic + keys header. This is in the api documentation:
curl --user {YOUR_CLIENT_ID}:{YOUR_CLIENT_SECRET} https://www.udemy.com/api-2.0/courses/
curl -H "Authorization: Basic {BASE64_ENCODED(CLIENT_ID:CLIENT_SECRET)}" https://www.udemy.com/api-2.0/courses/
This is what I have tried below but I have been getting errors.
const axios = require('axios');
const config = require('../config');
const { app: { API_URL, CLIENT_ID, CLIENT_SECRET } } = config;
var options = {
method: 'GET',
url: 'courses',
baseURL: API_URL,
headers: {
'Authorization': 'Basic ' + CLIENT_ID + ':' + CLIENT_SECRET,
},
responseType: 'json',
};
// Get all Posts handler
exports.getCourses = async(req, res, next) => {
try {
const response = await axios(options);
console.log(response);
res.status(200).json({ courses: response });
} catch (error) {
res.status(500).json({message: 'ERROR: Error Occured!'});
}
}
This is the error I am getting:
GET http://localhost:3000/api/courses 500 (Internal Server Error)
ERROR Error: Error Code: 500, Message: Http failure response for http://localhost:3000/api/courses: 500 Internal Server Error
Please, I need your help in resolving this.
Thanks in advance!