Reputation: 193
I am trying to call Databricks api to run a notebook or job by its ID by the API endpoint api/2.0/jobs/run-now
but I am getting an error like getaddrinfo ENOTFOUND https://adb-<workspace-id>.<random-number>.azuredatabricks.net/api/2.0/jobs/run-now
. But I am giving the right url (NOTE: I copied the url from the browser address bar till .net as per the example mentioned in : Example Job API
Below is my Node.JS code :
router.get('/triggerJob', (req, res) => {
var job_payload = {
"job_id": <Job_ID>
}
var options = {
host: 'https://adb-<workspaceid>.<number>.azuredatabricks.net/api/2.0/jobs/run-now',
body: JSON.stringify(job_payload),
method: 'Post',
headers: { 'Authorization': 'token' }
}
var data = '';
console.log('till here')
var request = https.request(options, function (result) {
var body = "";
result.on('data', function (data) {
console.log('data came');
body += data;
});
result.on('end', function () {
console.log('ended too');
data = JSON.parse(body);
res.json(data);
});
});
request.on('error', function (e) {
console.log('Problem with request: ' + e.message);
});
request.end();
})
Upvotes: 0
Views: 1856
Reputation: 193
As I got Solution for my question I want share it with all for the future refernce.
According to microsoft docs: enter link description here
They ask us to hit the url with https://adb-<workspaceid>.<number>.azuredatabricks.net/api/2.0/jobs/run-now
but I got is we need to hit the url:
https://<{locationname}>.azuredatabricks.net then api/2.0/jobs/run-now. So below is the code for the same:
const request=require("request");
const rp=require("request-promise");
const triggerJob=((res,req)=>{
var job_payload = {
"job_id": <Job_ID>
}
var options = {
host: 'https://<locationname>.azuredatabricks.net/api/2.0/jobs/run-now',
body: JSON.stringify(job_payload),
method: 'Post',
headers: { 'Content-Type':'application/jsoon','Authorization': 'Bearer token' }
}
var response=await rp(url,options);
if(response!=null){
return res.json(response)
}
});
module.exports= triggerJob;
I minimize the line of code for clarity.
Upvotes: 1