How can I pass a complex objects as input when using Cadence HTTP API tool?

28 views Asked by At

Here is a sample workflow and its input struct:

func MyWorkflow(ctx cadence.Context, input MyInput) error {
    ...
}

type MyInput struct {
    SomeString: string,
    SomeInteger: int
} 

According to Cadence HTTP API documentation, workflow can be started by sending a HTTP POST request with the payload like below:

{
  "domain": "sample-domain",
  "workflow_id": "sample-workflow-id",
  "execution_start_to_close_timeout": "61s",
  "task_start_to_close_timeout": "60s",
  "workflow_type": {
    "name": "sample-workflow-type"
  },
  "task_list": {
    "name": "sample-task-list"
  },
  "identity": "client-name-visible-in-history",
  "request_id": "8049B932-6C2F-415A-9BB2-241DCF4CFC9C",
  "input": {
    "data": "IkN1cmwhIg=="
  }
}

When I tried to start the workflow through HTTP API with the above payload, the workflow failed immediately and gave this error:

{
  "reason": "cadenceInternal:Generic",
  "details": "unable to decode the workflow function input bytes with error: unable to decode argument: 0, *MyInput, with json error: EOF, function name: sample-workflow-type",
}

From my understanding, it failed because it cannot decode bytes into the type MyInput.

I tried to change the input type to byte array:

func MyWorkflow(ctx cadence.Context, input []byte) error {
}

However, when I tried to read different input, it is always return 0 for the length.

func MyWorkflow(ctx cadence.Context, input []byte) error {
    // output 0 for length of input
    logger.Info("length of input", zap.Int("length", len(input))
}

Could someone let me know what I did wrong here please? Thanks in advance!

0

There are 0 answers