Add Task API not adding content or remote host/username/password

Just trying to add a test task, and the task gets created, but only contains the name and code. I’m trying to get it to add the content, and the remote host, but those are always blank. This code doesn’t contain the Bearer header, but it’s there. Any ideas?

curl --request POST \
     --url https://changeme/api/tasks \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --data '
{
     "task": {
          "taskType": {
               "taskOptions": {
                    "host": "pu1cldutil1001",
                    "username": "username",
                    "password": "password"
               },
               "retryable": false,
               "file": {
                    "sourceType": "local",
                    "content": "test"
               },
               "credential": {
                    "type": "local"
               },
               "code": "script",
               "executeTarget": "remote"
          },
          "name": "Log: Add CMDB User 1",
          "code": "logaddcmdbuser1"
     }
}
'

The following payload example should work. It appears that the API documentation for creating and updating an automation task needs to be fixed to move attributes from underneath taskType. The morpheus cli can also be used to generate the payload using the dry run option (-d) in addition to the output format for json (-j).

morpheus tasks add -d -j

Example API payload for creating a shell task

{
  "task": {
    "name": "Log: Add CMDB User 1",
    "code": "logaddcmdbuser1",
    "taskType": {
      "code": "script"
    },
    "taskOptions": {
      "host": "pu1cldutil1001",
      "username": "username",
      "password": "password"
    },
    "file": {
      "sourceType": "local",
      "content": "test"
    },
    "executeTarget": "remote",
    "credential": {
      "type": "local"
    },
    "retryable": false
  }
}
1 Like

This is fantastic information! Thank you.