Hello,
i would like to test one of the APIs in the business hub (https://api.sap.com/api/OP_API_MAINTNOTIFICATION/overview?ReleaseInfo=2021%20FPS02)
with mocha. In order to do it it is required to authorize yourself/generate an authorization token.
let chai = require("chai"); let chaiHttp = require("chai-http"); let server = require("./apiPage"); //Assertion Style chai.should(); chai.use(chaiHttp); describe("API TEST", function() { it.only('Get all notifications', function(done) { const url = "https://sandbox.api.sap.com/s4hanacloud/sap/opu/odata/sap/API_MAINTNOTIFICATION/MaintenanceNotification"; chai.request(url) .post('/auth/sign_in') // send user login details .send({ 'email': 'ExampleEmail', 'password': 'ExamplePassword' }) .end(function(err, res) { var token = res.body.token; done(); }); chai.request(url) .get('') .set('Authorization', 'JWT ' + token) .end(function(err, res) { console.log(res); done(); }); }); });
Issue: It doesn't really function.
Question: How to authorize yourself/generate a token in order to test API: Maintenance Notification ?