<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Can anyone tell me how to submit a job using serverless compute using restapi in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-how-to-submit-a-job-using-serverless-compute/m-p/92005#M38318</link>
    <description>&lt;P&gt;#serverless#createjob&lt;/P&gt;</description>
    <pubDate>Fri, 27 Sep 2024 08:29:15 GMT</pubDate>
    <dc:creator>tonyd</dc:creator>
    <dc:date>2024-09-27T08:29:15Z</dc:date>
    <item>
      <title>Can anyone tell me how to submit a job using serverless compute using restapi</title>
      <link>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-how-to-submit-a-job-using-serverless-compute/m-p/92005#M38318</link>
      <description>&lt;P&gt;#serverless#createjob&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 08:29:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-how-to-submit-a-job-using-serverless-compute/m-p/92005#M38318</guid>
      <dc:creator>tonyd</dc:creator>
      <dc:date>2024-09-27T08:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Can anyone tell me how to submit a job using serverless compute using restapi</title>
      <link>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-how-to-submit-a-job-using-serverless-compute/m-p/92034#M38330</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/55268"&gt;@tonyd&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;If you want to use serverless, first of all you need to enable it:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_0-1727444114314.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11557i1AD17CF1A2E4041F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_0-1727444114314.png" alt="filipniziol_0-1727444114314.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When enabled, when sending the request to the&amp;nbsp;REST API simply do not specify the cluster:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

# Your Databricks domain
DATABRICKS_DOMAIN = '&amp;lt;&amp;gt;'
# Personal Access Token for authentication
TOKEN = '&amp;lt;&amp;gt;'

# The JSON string representing your job configuration
job_json_string =  """{
  "name": "my_serverless_job",
  "email_notifications": {
    "no_alert_for_skipped_runs": false
  },
  "webhook_notifications": {},
  "timeout_seconds": 0,
  "max_concurrent_runs": 1,
  "tasks": [
    {
      "task_key": "df_regular",
      "run_if": "ALL_SUCCESS",
      "notebook_task": {
        "notebook_path": "/Workspace/Users/my_user/df_regular",
        "base_parameters": {
          "storage_account": "my_storage_account"
        },
        "source": "WORKSPACE"
      },
      "timeout_seconds": 0,
      "email_notifications": {},
      "notification_settings": {
        "no_alert_for_skipped_runs": false,
        "no_alert_for_canceled_runs": false,
        "alert_on_last_attempt": false
      },
      "webhook_notifications": {}
    }
  ],
  "run_as": {
    "user_name": "my_user"
  }
}"""

# Convert the JSON string to a dictionary
job_config = json.loads(job_json_string)

# The API endpoint for creating a job
api_url = f'{DATABRICKS_DOMAIN}/api/2.1/jobs/create'

# Headers for the request
headers = {
    'Authorization': f'Bearer {TOKEN}',
    'Content-Type': 'application/json'
}

# Make the POST request to create the job
response = requests.post(api_url, headers=headers, json=job_config)

# Check if the request was successful
if response.status_code == 200:
    # Job created successfully
    print("Job created successfully.")
    # Print the job ID
    job_id = response.json()['job_id']
    print(f"Job ID: {job_id}")
else:
    # There was an error
    print("Failed to create job.")
    print(f"Status Code: {response.status_code}")
    print(f"Response: {response.text}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The job has been created:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_1-1727444263334.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11558i797589E7353CE056/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_1-1727444263334.png" alt="filipniziol_1-1727444263334.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The job compute is serverless:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="filipniziol_2-1727444338067.png" style="width: 400px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/11559i635320F75D4C5C43/image-size/medium?v=v2&amp;amp;px=400" role="button" title="filipniziol_2-1727444338067.png" alt="filipniziol_2-1727444338067.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hope it helps&lt;/P&gt;</description>
      <pubDate>Fri, 27 Sep 2024 13:40:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/can-anyone-tell-me-how-to-submit-a-job-using-serverless-compute/m-p/92034#M38330</guid>
      <dc:creator>filipniziol</dc:creator>
      <dc:date>2024-09-27T13:40:08Z</dc:date>
    </item>
  </channel>
</rss>

