Unable to decode Temporal Data Payload in GoLang

Hello Team , I am Fetching workflow data using below code , but payload is Encoded , How Can I Decode my payload in golang ? , any Hints ? , Thanks in Advance :grinning:

c, err := client.NewClient(client.Options{})
	if err != nil {

	}
	defer c.Close()
	otr, err := c.ListWorkflow(context.Background(), &workflowservice.ListWorkflowExecutionsRequest{
		Namespace: "default",
	})
	temp := otr.GetExecutions()
	val := temp[0].GetSearchAttributes().GetIndexedFields()```

@tihomir can u help me on this ?

1 Like

You need to use data converter (default one unless you use a custom data converter in your code) to convert Payload to string.

See here for example.
Hope this helps.

Thanks @tihomir for reply , but still my issue is not resolved let me explain in detail.
I want to get input data fields from temporal workflows.

Below Json Snippet is the Demo Example input of Workflow which I want to fetch using go sdk

[
  {
    "Provider": "AWS",
    "AccountID": "67",
    "Regions": null,
    "AWS": {
      "AssumeRole": {
        "RoleARN": "arn:aws:iam::XXXXXXXXXXX:role/account-xxxxx-xxx",
        "RoleSessionName": "XxXxxXXXxxxXXXxxxxxxXXXxxxxXXxxxxX",
        "ExternalID": "XxxXxxxxxxxxxxxxxxxxxxxxxxxxxxXXXX"
      }
    }
  }
]

Here is my snippet for getting workflow data and convert them into actual data.

func GetWorkflow() {
	c, _ := client.NewClient(client.Options{})
	defer c.Close()
	otr, _ := c.ListWorkflow(context.Background(), &workflowservice.ListWorkflowExecutionsRequest{
		Namespace: "default",
	})
	temp := otr.GetExecutions()
	searchAttribute := temp[0].GetSearchAttributes()

	for _, v := range searchAttribute.GetIndexedFields() {
		var currentVal interface{}
		err := converter.GetDefaultDataConverter().FromPayload(v, &currentVal)
		fmt.Println("This is CurrentVal", currentVal)
		if err != nil {
			fmt.Println("Error Occurred.")
		}
	}
}

But … When I run the program , I got only BinaryChecksum payload ,But I want input payload . the output looks like this :point_down:
This is CurrentVal [c6190170857b5b2fff9f654b23b740ab]

So , how can I get Input Payload of the workflows using go sdk ?

You are fetching search attributes in your snippet. Obtaining the original input of the workflow isn’t the most straightforward currently, but what you have to do is, for whichever workflow you want the input for, you must ask for its history (GetWorkflowHistory and with isLongPoll as false for your use case) and then iterate the events until you reach the event with WorkflowExecutionStartedEventAttributes attributes (or can check for workflow started event type) which will often be one of the first events. Those attributes will have the input originally given to the workflow.

Often users who need such state tend to maintain it themselves in their preferred data store since they are the ones supplying it when starting the workflow. But if you must, extracting the input from history as described above can be done.

1 Like