Daksh Dutta
Daksh Dutta

Reputation: 193

Run Azure Notebook By API (external)

I am trying to run the notebook from node, everything is working fine except the parameters are not accepted by the notebook instead it is sending the output based on default params. I am not getting where I am doing wrong.

Below is my call:

var job_payload = {
            "run_name": runName,
            "existing_cluster_id": 'cluster_id',
            "notebook_task":
            {
                "notebook_path": notebookPath
            },
            "notebook_params": notebook_params //{'x':1,'y':2}
        }
        
        var url = "https://<location>.<azr_databricks>.net/api/2.0/jobs/runs/submit";
        var options = {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': 'Bearer token'
            },
            body: JSON.stringify(job_payload),
        };

My notebook:

import json
dbutils.widgets.text("x", '3', "firstParam")
dbutils.widgets.text("y", '4', "secondParam")
x=int(dbutils.widgets.get("x"))
y=int(dbutils.widgets.get("y"))
sum=x+y
class Output:
  def __init__(self, val):
    self.resultTest2 = val

p1 = Output(sum)
print(p1.resultTest2)
result=json.dumps(p1.__dict__)
#RETURNING THE OUTPUT
dbutils.notebook.exit(result)

I am sending x:1 and y:2 as param but instead of getting output 3 I am getting 7 which is default value.

As I am not getting much help from the documentation, please help:

Document URL: Microsoft link

Upvotes: 0

Views: 691

Answers (1)

Daksh Dutta
Daksh Dutta

Reputation: 193

I got the answer that where I was wrong from the below link :

StackOverflow Link

the job_payload will look like below:

var job_payload = {
            "run_name": runName,
            "existing_cluster_id": 'cluster_id',
            "notebook_task":
            {
                "notebook_path": notebookPath,
                "base_parameters":notebook_params //{'x':1,'y':2}
            },
           
        }
        
        var url = "https://<location>.<azr_databricks>.net/api/2.0/jobs/runs/submit";
        var options = {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': 'Bearer token'
            },
            body: JSON.stringify(job_payload),
        };

Now, it is working fine.

Upvotes: 1

Related Questions