Home > database >  Getting error while creating Job from Jobs API
Getting error while creating Job from Jobs API

Time:03-23

I am passing job configuration from database as string and storing as string in .Net Web API as

var result =  _context.Output.FromSqlRaw(StoredJson).ToList().FirstOrDefault().Details;

Now I Used RestSharp library to create request in .Net as

var client = new RestClient(".....");
var request = new RestRequest("/api/2.0/jobs/create", Method.Post);
string Auth = "......";

request.AddParameter("application/json", result, ParameterType.RequestBody);
request.AddParameter("Authorization", "Bearer "   Auth, ParameterType.HttpHeader);
var response = await client.ExecuteAsync(request);
return(response.content)

And My Json looks like this

{
    "name": "LoadData_test",
    "new_cluster": {
        "spark_version": "7.6.x-scala2.12",
        "init_scripts": [
            {
                "dbfs": {
                    "destination": "....."
                }
            }
        ],
        "instance_pool_id": ".......",
        "azure_attributes": {
            "spot_bid_max_price": -1
        },
        "autoscale": {
            "min_workers": 2,
            "max_workers": 5
        }
    },
    "libraries": [
        {
            "maven": {
                "coordinates": "......"
            }
        }
    ],
    "timeout_seconds": 0,
    "notebook_task": {
        "notebook_path": "......",
        "revision_timestamp": 0
    },
    "max_concurrent_runs": 1
}

And I think when I am passing this JSON into request.AddParameters, It is taking as text/plain. but I want it to be JSON.

I think, I have done everything right, but still getting error while send the request as

{"error_code":"INVALID_PARAMETER_VALUE","message":"Job settings must be specified."}

Can somebody please help me out ?

And I have use "..." as there is valid content.

CodePudding user response:

I guess that you got the code generated by some codeegen, like Postman. It doesn't work with the latest RestSharp, as the way to build requests was broken.

The documentation has a complete overview of the RestSharp API for building proper requests, I strongly suggest looking at it.

Specifically, you need to replace this line:

request.AddParameter("application/json", result, ParameterType.RequestBody);

with

request.AddStringBody(result, DataFormat.Json);
  • Related