skip to Main Content

I am trying to call a REST API post method to Cloudify.

I can run this successfully from commandline. Please see the command.

curl -X POST --header "Tenant: default_tenant" --header "Content-Type: application/json" -u admin:admin -d '{"deployment_id": "OSCreateVM", "workflow_id": "install"}' "http://xxxxxxxxx/api/v3.1/executions?_include=id"

However when I create an AJAX REST API call from my html, I am getting an “undefined” error. What went wrong here? Can someone help please?

function ajaxFunction(){
var parameters= {"deployment_id": "OSCreateVM", "workflow_id": "install"};
 $.ajax({
        type: "POST",
        url: "http://xxxxxxxxx/api/v3.1/executions?_include=id",
        headers: {
        'Tenant': 'default_tenant',
        'Content-Type': 'application/json'
        },
        data: JSON.stringify(parameters),
        crossDomain: true,
        dataType: "json",
        username: "admin",
        password: "admin",
        success: function (responseData, status, jqXHR) {
            alert ("Request for VM Creation is Succcessfully submitted");
         },
        error: function (request, status, error) {
             // error handler
             alert(request.responseText);
         }
      });
}

2

Answers


  1. Chosen as BEST ANSWER

    I tested more. Undefined Error occurs because of this line: "alert(request.responseText);", request object doesn't have a responseText variable defined in it.

    If you change the code as below, undefined error will disappear.

    error: function (request) {
                 // error handler
                 alert(request.status);
             }
    

  2. It’s hard to understand what went wrong, syntactically it looks valid but “undefined” could be a lot of things.

    I suggest you try to look at the events in the Cloudify manager Web-UI or CLI to understand what was undefined.
    If you use the Web-UI go to the deployments tab, look for OSCreateVM, click on it and look at the executions done to see more details.

    If you do it via CLI run cfy executions list -d OSCreateVM

    Once you have the executions list run cfy events list <ID_OF_THE_INSTALL_EXECUTION

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search