API create environment: Host Environment Type not recognised

  • 0
  • 1
  • Problem
  • Updated 9 months ago
  • Solved
  • (Edited)

I am trying to create a new source environment, via a call to the API.

It Looks like I’m getting my API call rejected because of the engine not recognising the WindowsHostEnvironment Type. I checked the documentation and this seems to be the corect type to use. Our API version is 1.8.1

I was able to successfully make the call to create the environment using the CLI.
What I saw from the json tracking of a successful create via the CLI:

=== POST /resources/json/delphix/environment ===
{
    "type": "HostEnvironmentCreateParameters",
    "primaryUser": {
        "type": "EnvironmentUser",
        "name": "REDACTED",
        "credential": {
            "type": "PasswordCredential",
            "password": "REDACTED"
        }
    },
    "hostEnvironment": {
        "type": "WindowsHostEnvironment",
        "name": "REDACTED",
        "proxy": "WINDOWS_HOST-13"
    },
    "hostParameters": {
        "type": "WindowsHostCreateParameters",
        "host": {
            "type": "WindowsHost",
            "address": "REDACTED"
        }
    }
}


Using the API I issued a post request to ‘https://SERVERNAME/resources/json/delphix/environment
{
    "type":  "HostEnvironmentCreateParameters",
   "primaryUser":  {
                        "type":  "EnvironmentUser",
                        "name":  "REDACTED",
                        "credential":  {
                                           "type":  "PasswordCredential",
                                           "password":  "REDACTED"
                                       }
                    },
    "hostEnvironment":  {
                            "type": "WindowsHostEnvironment",
                            "name":  "REDACTED",
                            "proxy":  "WINDOWS_HOST_ENVIRONMENT-81"
                        },
    "hostParameters":  {
                           "type":  "WindowsHostCreateParameters",
                           "host":  {
                                        "type":  "WindowsHost",
                                        "address":  "REDACTED"
                                    }
                       }
}

And got the following response:
{
    "type": "ErrorResult",
    "status": "ERROR",
    "error": {
        "type": "APIError",
        "details": {
            "hostEnvironment": {
                "proxy": {
                    "details": "Reference to invalid object type \"WindowsHostEnvironment\". Expected \"Host\" or sub type.",
                    "action": null,
                    "id": "exception.validation.referenceto.invalid",
                    "commandOutput": null,
                    "diagnoses": null
                }
            }
        },
        "action": "Check your input parameters and try again.",
        "id": "exception.validation.bad.input",
        "commandOutput": null,
        "diagnoses": null
    }
}


I have tried settting it as the parent class "HostEnvironment" but this was also not recognised. I also tried as 'Host' and ommitting the type  but these calls also failed.

I'd appreciate any pointers to what I should try next.

Photo of Jonathan

Jonathan

  • 92 Points 75 badge 2x thumb

Posted 9 months ago

  • 0
  • 1
Photo of Scott MacDonald

Scott MacDonald, Support Engineer

  • 2,332 Points 2k badge 2x thumb
Hi Jonathan,

This looks like an API version issue. Are you specifying a particular version in your API script when you establish the session? If so, what is the script setting it to?

Best Regards,

Scott.
Photo of Jonathan

Jonathan

  • 92 Points 75 badge 2x thumb
Hi Scott,
I specify 1.8.1 when I create the session. That's the version I read from the engine
(Edited)
Photo of Scott MacDonald

Scott MacDonald, Support Engineer

  • 2,332 Points 2k badge 2x thumb
Hi Jonathan,

Ok, think I've got it, your definition for "proxy" points to a host environment (WINDOWS_HOST_ENVIRONMENT-81), but it should be a host reference instead.
Try using the corresponding host reference for that environment and let me know if that works.

Best Regards,

Scott.
Photo of Eyal Kaspi

Eyal Kaspi, Employee

  • 970 Points 500 badge 2x thumb
I believe the problem is that for the "proxy" property you've specified the object reference of the windows host environment instead of the windows host. In the working CLI example the value "WINDOWS_HOST-13" was set, but in your example you passed "WINDOWS_HOST_ENVIRONMENT-81". You can use the CLI to find the object reference of the host that is contained in the "WINDOWS_HOST_ENVIRONMENT-81" environment, for instance on my machine:

cli> /environment select UNIX_HOST_ENVIRONMENT-2; get host
    test-host-name
cli> /host select test-host-name; get reference
    UNIX_HOST-2
(Edited)
Photo of Jonathan

Jonathan

  • 92 Points 75 badge 2x thumb
Yep. That was it alright.

Thanks a heap, I wouldn't have spotted that in my own code for ages.
Thanks Scott & Eyal
(Edited)