# Tctl workflow show equivalent in Java

**URL:** https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520
**Category:** Community Support
**Tags:** java-sdk
**Created:** [December 2, 2021, 11:19pm UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520 "2021-12-02T23:19:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jayk](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jayk](https://community.temporal.io/u/jayk)
#### Post date: [December 2, 2021, 11:19pm UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520/1 "2021-12-02T23:19:07Z")

</div>

Hi,

Is it possible to retrieve the information available using tctl workflow show command using Java API?

Kind Regards,  
Jay.

---

<div class="post-metadata">

### Author: ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)
#### Post date: [December 2, 2021, 11:55pm UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520/2 "2021-12-02T23:55:34Z")

</div>

`tctl wf show -w <workflowId> -r <runid>`

You can use WorkflowExecutionHistory, for example:

```auto
public static void printWorkflowExecutionHistory(WorkflowClient client, String workflowId, String runId, WorkflowStub wfStub, ByteString token) {
        if(wfStub == null) {
            wfStub = client.newUntypedWorkflowStub(workflowId, Optional.of(runId), Optional.empty());
        }

        GetWorkflowExecutionHistoryRequest workflowExecutionHistoryRequest;
        if(token == null) {
            workflowExecutionHistoryRequest =
                    GetWorkflowExecutionHistoryRequest.newBuilder()
                            .setNamespace(client.getOptions().getNamespace())
                            .setExecution(wfStub.getExecution())
                            .build();
        } else {
            workflowExecutionHistoryRequest =
                    GetWorkflowExecutionHistoryRequest.newBuilder()
                            .setNamespace(client.getOptions().getNamespace())
                            .setExecution(wfStub.getExecution())
                            .setNextPageToken(token)
                            .build();
        }

        GetWorkflowExecutionHistoryResponse workflowExecutionHistoryResponse =
                service.blockingStub().getWorkflowExecutionHistory(workflowExecutionHistoryRequest);
        for(HistoryEvent historyEvent : workflowExecutionHistoryResponse.getHistory().getEventsList()) {
            System.out.println(historyEvent.getEventId() + " - " + historyEvent.getEventType());
        }
        if(workflowExecutionHistoryResponse.getNextPageToken() != null && workflowExecutionHistoryResponse.getNextPageToken().size() > 0) {
            printWorkflowExecutionHistory(client, workflowId, runId, wfStub, workflowExecutionHistoryResponse.getNextPageToken());
        }
    }

```

The initial call to this method would pass null for wfstub and token, for example:

`printWorkflowExecutionHistory(client, myWfId, myWfRunId, null, null);`

---

<div class="post-metadata">

### Author: ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)
#### Post date: [December 3, 2021, 4:11am UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520/3 "2021-12-03T04:11:52Z")

</div>

Don’t forget that history is paginated. So you have to call `getWorkflowExecutionHistory` more than once if the page token in the response is not emptyh.

---

<div class="post-metadata">

### Author: ![jayk](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jayk](https://community.temporal.io/u/jayk)
#### Post date: [December 3, 2021, 10:29am UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520/4 "2021-12-03T10:29:32Z")

</div>

Thanks @tihomir, @maxim.

This is really useful.

If I wanted the equivalent of tctl wf describe command in Java, would I use DescribeWorkflowExecutionRequest and DescribeWorkflowExecutionResponse classes?

Kind Regards,  
Jay.

---

<div class="post-metadata">

### Author: ![jayk](https://avatars.discourse-cdn.com/v4/letter/j/e47774/32.png) [@jayk](https://community.temporal.io/u/jayk)
#### Post date: [December 3, 2021, 1:41pm UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520/5 "2021-12-03T13:41:18Z")

</div>

@maxim - is it possible to get all the data in one go without pagination?

Thanks,  
Jay.

---

<div class="post-metadata">

### Author: ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)
#### Post date: [December 3, 2021, 2:24pm UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520/6 "2021-12-03T14:24:03Z")

</div>

> is it possible to get all the data in one go without pagination?

Very good point by @maxim, thank you. Here is the updated version that also works for large wf histories (using tokens):

```auto
    public static void printWorkflowExecutionHistory(WorkflowClient client, String workflowId, String runId, WorkflowStub wfStub, ByteString token) {
        if(wfStub == null) {
            wfStub = client.newUntypedWorkflowStub(workflowId, Optional.of(runId), Optional.empty());
        }

        GetWorkflowExecutionHistoryRequest workflowExecutionHistoryRequest;
        if(token == null) {
            workflowExecutionHistoryRequest =
                    GetWorkflowExecutionHistoryRequest.newBuilder()
                            .setNamespace(client.getOptions().getNamespace())
                            .setExecution(wfStub.getExecution())
                            .build();
        } else {
            workflowExecutionHistoryRequest =
                    GetWorkflowExecutionHistoryRequest.newBuilder()
                            .setNamespace(client.getOptions().getNamespace())
                            .setExecution(wfStub.getExecution())
                            .setNextPageToken(token)
                            .build();
        }

        GetWorkflowExecutionHistoryResponse workflowExecutionHistoryResponse =
                service.blockingStub().getWorkflowExecutionHistory(workflowExecutionHistoryRequest);
        for(HistoryEvent historyEvent : workflowExecutionHistoryResponse.getHistory().getEventsList()) {
            System.out.println(historyEvent.getEventId() + " - " + historyEvent.getEventType());
        }
        if(workflowExecutionHistoryResponse.getNextPageToken() != null && workflowExecutionHistoryResponse.getNextPageToken().size() > 0) {
            printWorkflowExecutionHistory(client, workflowId, runId, wfStub, workflowExecutionHistoryResponse.getNextPageToken());
        }
    }

```

The initial call to this method would pass null for wfstub and token, for example:

` printWorkflowExecutionHistory(client, myWfId, myWfRunId, null, null);`

Note, I have updated the initial response (one marked as solution) to include this updated code.

---

<div class="post-metadata">

### Author: ![tihomir](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/tihomir/32/6580_2.png) [@tihomir](https://community.temporal.io/u/tihomir)
#### Post date: [December 3, 2021, 2:45pm UTC](https://community.temporal.io/t/tctl-workflow-show-equivalent-in-java/3520/7 "2021-12-03T14:45:46Z")

</div>

> [@jayk](#):
>
> If I wanted the equivalent of tctl wf describe command in Java, would I use DescribeWorkflowExecutionRequest and DescribeWorkflowExecutionResponse classes?

You use both, request is the request sent to server, and response includes the response info. Here is a method that you could use:

```auto
public static void printDescribeWorkflowExecution(WorkflowClient client, String workflowId, String runId) {
        WorkflowStub wfStub = client.newUntypedWorkflowStub(workflowId, Optional.of(runId), Optional.empty());
        DescribeWorkflowExecutionRequest request = DescribeWorkflowExecutionRequest.newBuilder()
                .setNamespace(client.getOptions().getNamespace())
                .setExecution(wfStub.getExecution()).build();
        DescribeWorkflowExecutionResponse response = service.blockingStub().describeWorkflowExecution(request);
        // response includes info like workflow exec info, pending activities (and their count),
        // pending child wfs, etc
    }

```
