Search code examples
google-compute-enginegoogle-api-java-clientgoogle-apis-explorer

Issue deleting instances with google API Explorer


I have tried deleting instances using https://cloud.google.com/compute/docs/reference/beta/instanceGroupManagers/deleteInstances but it's not working.

In the request body, I am entering

{
  "instances": [
    "scaler-group-instance-1"
  ]
}

For project, I used project-name-1

For zone, I used us-west1-a

For instanceGroupManager I am using scaling-group-manager

In response, I am receiving

{
  "code" : 400,
  "errors" : [ {
    "domain" : "global",
    "message" : "Invalid value for field 'instances[0]': 'scaler-group-instance-1'. The URL is malformed.",
    "reason" : "invalid"
  } ],
  "message" : "Invalid value for field 'instances[0]': 'scaler-group-instance-1'. The URL is malformed."
}

I have also tried this in Java as well using this code snippet and have also received a 400 Bad Request

String projectId = "project-name-1";
String zoneName = "us-west1-a";
String instanceGroupName = "scaling-group-manager";
List<String> instancesToDelete = new ArrayList<>();
instancesToDelete.add("scaler-group-instance-1");
InstanceGroupManagersDeleteInstancesRequest deleteInstancesRequest = new InstanceGroupManagersDeleteInstancesRequest().setInstances(instancesToDelete);
Compute.InstanceGroupManagers.DeleteInstances deleteInstances = compute.instanceGroupManagers().deleteInstances(projectId, zoneName, instanceGroupName, deleteInstancesRequest).execute();

Is there something wrong with my request that I'm not seeing?


Solution

  • I found the issue. This request expects the instance string to be a URL and not an instance name.

    The instance can be found in the selfLink value in the listInstances requests.

    Entering the selfLink URL into the request caused the server to reply correctly.