Job execution via Rest API

Hi All,

I want to execute a job I created by rest api. But so far I am not able to do so. Please find the details below

  1. I created a job using rest api without executing it:

    curl -X POST "https://knime.server.com/knime/rest/v4/repository/Project1/Test/simple_restapi:jobs?timeout=-1&asyncLoading=true" -u user:pass -H "Content-Type: application/json"

Received the folowing output:

{
  "@controls" : {
    "self" : {
      "href" : "https://knime.server.com/knime/rest/v4/jobs/2359c356-bfc5-48c0-84b9-0fc0116bdc38",
      "method" : "GET"
    },
    "collection" : {
      "href" : "https://knime.server.com/knime/rest/v4/repository/Project1/Test/simple_restapi:jobs",
      "method" : "GET"
    },
    "edit" : {
      "href" : "https://knime.server.com/knime/rest/v4/jobs/2359c356-bfc5-48c0-84b9-0fc0116bdc38",
      "encoding" : "Json",
      "method" : "PUT"
    },
    "knime:delete" : {
      "href" : "https://knime.server.com/knime/rest/v4/jobs/2359c356-bfc5-48c0-84b9-0fc0116bdc38",
      "method" : "DELETE"
    },
    "knime:workflow" : {
      "href" : "https://knime.server.com/knime/rest/v4/repository/Project1/Test/simple_restapi",
      "method" : "GET"
    },
    "knime:upload" : {
      "href" : "https://knime.server.com/knime/rest/v4/repository/{path}:data?from-job=2359c356-bfc5-48c0-84b9-0fc0116bdc38",
      "method" : "PUT",
      "isHrefTemplate" : true
    },
    "knime:swap" : {
      "href" : "https://knime.server.com/knime/rest/v4/jobs/2359c356-bfc5-48c0-84b9-0fc0116bdc38/swap",
      "method" : "PUT",
      "isHrefTemplate" : true
    },
    "knime:workflow-summary" : {
      "href" : "https://knime.server.com/knime/rest/v4/jobs/2359c356-bfc5-48c0-84b9-0fc0116bdc38/workflow-summary{?format,includeExecutionInfo}",
      "method" : "GET",
      "output" : [ "application/json", "application/xml" ],
      "isHrefTemplate" : true
    }
  },
  "id" : "2359c356-bfc5-48c0-84b9-0fc0116bdc38",
  "discardAfterSuccessfulExec" : false,
  "discardAfterFailedExec" : false,
  "configuration" : {
    "knime.cred.knime.system.default" : {
      "login" : "user",
      "password" : "*************"
    }
  },
  "executorID" : "<unknown>",
  "createdVia" : "generic client",
  "state" : "LOADING",
  "name" : "simple_restapi 2021-04-07 17.08.12",
  "properties" : {
    "com.knime.enterprise.server.executor.requirements" : "",
    "com.knime.enterprise.server.jobpool.size" : "0"
  },
  "owner" : "user",
  "notifications" : { },
  "workflow" : "/Project1/Test/simple_restapi",
  "hasReport" : false,
  "isSwapped" : false,
  "createdAt" : "2021-04-07T17:08:12.820+02:00[Europe/Berlin]",
  "isOutdated" : false,
  "@namespaces" : {
    "knime" : {
      "name" : "http://www.knime.com/server/rels#"
    }
  }
}
  1. After I used the following rest api call to execute the workflow:

curl -X POST "https://knime.zf-world.com/knime/rest/v4/jobs/a02117cb-6c23-4c09-aeac-c096610512b7?async=false" -u user:pass

But did not receive any results back. I checked the job created in the AP, but it is not executed.
When I execute it in the Swagger UI I am getting 415 error.
What am I doing wrong here?

Regards,
Nithin

Hi Nithin,
415 means unsupported media type. I think in your second call you also need to set -H “Content-Type: application/json” and as a request body just send an empty JSON object ({}). That should do the trick.
Kind regards,
Alexander

Hi Alex,

Yes that worked!! Thank you for the solution :slight_smile:

Regards,
Nithin

Hi Alex,

I am facing another issue. How can I pass content for the container input (JSON)? I tried with -d but didn’t work. And with which call I should pass this info? workflow:jobs or jobs/uuid ?

Regards,
Nithin

Hi Nithin,
Configuration for configuration nodes is passed during job creation (POST to workflow:jobs) and the data for container inputs is passed when executing the job via POST to jobs/uuid. The -d option of curl should be the right one. What error do you get?
Kind regards,
Alex

Hi Alex,

yes, when I give the data to jobs/uuid using -d it is working. Thanks again :slight_smile:

Regards,
Nithin

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.