Skip to content

Commit b6e649e

Browse files
Add GET /v1/actions API call to HetznerApi client
This will allow the polling of asynchronous actions from the Hetzner API without consuming the main rate limit of the other (main) endpoints.
1 parent f7245cf commit b6e649e

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/main/java/cloud/dnation/hetznerclient/HetznerApi.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
* For full version, check <a href="https://docs.hetzner.cloud/">official documentation</a>
3131
*/
3232
public interface HetznerApi {
33+
34+
/**
35+
* Get/poll the status of an asynchronous API on the Hetzner Cloud.
36+
* <p>Normally, the rate limit of this API is higher and separate from the other API calls,
37+
* as it is preferred to poll the /actions endpoint to wait for an asynchronous action to complete.</p>
38+
* @param actionId the ID of the action whose status you want to poll
39+
* @return the full Action object, including its current status
40+
*/
41+
@GET("/v1/actions/{id}")
42+
Call<ActionResponse> getActionById(@Path("id") Long actionId);
43+
3344
/**
3445
* Get all images that matches given label expression.
3546
*

src/test/java/cloud/dnation/hetznerclient/BasicTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ public static void tearDownAfterClass() throws IOException {
5151
ws.close();
5252
}
5353

54+
@Test
55+
public void testGetActionById() throws IOException {
56+
ws.enqueue(new MockResponse()
57+
.setBody(resourceAsString("get-action-by-id.json"))
58+
);
59+
Call<ActionResponse> call = api.getActionById(603984077612933L);
60+
ActionResponse result = call.execute().body();
61+
assertEquals("delete_server", result.getAction().getCommand());
62+
assertEquals(100, result.getAction().getProgress().intValue());
63+
assertEquals("success", result.getAction().getStatus());
64+
assertNull(result.getAction().getError());
65+
List<IdentifiableResource> relatedResources = result.getAction().getResources();
66+
assertEquals(1, relatedResources.size());
67+
assertEquals(117017457L, relatedResources.get(0).getId().longValue());
68+
}
69+
5470
@Test
5571
public void testGetNetworkById() throws IOException {
5672
ws.enqueue(new MockResponse()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"action": {
3+
"id": 603984077612933,
4+
"command": "delete_server",
5+
"started": "2026-01-08T17:33:08Z",
6+
"finished": "2026-01-08T17:33:13Z",
7+
"progress": 100,
8+
"status": "success",
9+
"resources": [
10+
{
11+
"id": 117017457,
12+
"type": "server"
13+
}
14+
],
15+
"error": null
16+
}
17+
}

0 commit comments

Comments
 (0)