diff --git a/src/main/java/cloud/dnation/hetznerclient/HetznerApi.java b/src/main/java/cloud/dnation/hetznerclient/HetznerApi.java index 49414ff..7c84a18 100644 --- a/src/main/java/cloud/dnation/hetznerclient/HetznerApi.java +++ b/src/main/java/cloud/dnation/hetznerclient/HetznerApi.java @@ -30,6 +30,17 @@ * For full version, check official documentation */ public interface HetznerApi { + + /** + * Get/poll the status of an asynchronous API on the Hetzner Cloud. + *

Normally, the rate limit of this API is higher and separate from the other API calls, + * as it is preferred to poll the /actions endpoint to wait for an asynchronous action to complete.

+ * @param actionId the ID of the action whose status you want to poll + * @return the full Action object, including its current status + */ + @GET("/v1/actions/{id}") + Call getActionById(@Path("id") Long actionId); + /** * Get all images that matches given label expression. * diff --git a/src/test/java/cloud/dnation/hetznerclient/BasicTest.java b/src/test/java/cloud/dnation/hetznerclient/BasicTest.java index d3b10b6..b11bc3e 100644 --- a/src/test/java/cloud/dnation/hetznerclient/BasicTest.java +++ b/src/test/java/cloud/dnation/hetznerclient/BasicTest.java @@ -51,6 +51,22 @@ public static void tearDownAfterClass() throws IOException { ws.close(); } + @Test + public void testGetActionById() throws IOException { + ws.enqueue(new MockResponse() + .setBody(resourceAsString("get-action-by-id.json")) + ); + Call call = api.getActionById(603984077612933L); + ActionResponse result = call.execute().body(); + assertEquals("delete_server", result.getAction().getCommand()); + assertEquals(100, result.getAction().getProgress().intValue()); + assertEquals("success", result.getAction().getStatus()); + assertNull(result.getAction().getError()); + List relatedResources = result.getAction().getResources(); + assertEquals(1, relatedResources.size()); + assertEquals(117017457L, relatedResources.get(0).getId().longValue()); + } + @Test public void testGetNetworkById() throws IOException { ws.enqueue(new MockResponse() diff --git a/src/test/resources/get-action-by-id.json b/src/test/resources/get-action-by-id.json new file mode 100644 index 0000000..d2fedda --- /dev/null +++ b/src/test/resources/get-action-by-id.json @@ -0,0 +1,17 @@ +{ + "action": { + "id": 603984077612933, + "command": "delete_server", + "started": "2026-01-08T17:33:08Z", + "finished": "2026-01-08T17:33:13Z", + "progress": 100, + "status": "success", + "resources": [ + { + "id": 117017457, + "type": "server" + } + ], + "error": null + } +}