Confirm and Publish Workflow Proposals

Applications integrating with the workflow editor can accept a reviewed candidate proposal stored on the server and deploy it as a runnable workflow.

Task flow

Acceptance takes the task ID, artifact ID, and proposal ID for the same candidate and returns an accepted candidate record; deployment publishes that record as a workflow and returns its workflow ID.

Task ID + Artifact ID + Proposal ID + Idempotency key
                          │
                          ▼
               Accept workflow candidate
                          │
                          ▼
              Accepted candidate record
                          │
                          ▼
       Deploy workflow and obtain workflow ID

Prerequisites

  1. Complete the endpoint, personal access token, and workspace setup in Use the SDK.

  2. Candidate proposal reference (TASK_ID, ARTIFACT_ID, PROPOSAL_ID): save the task ID, candidate artifact ID, and confirmation proposal ID from the same authoring task or history restoration result (see Test and Submit Workflow Projects or Inspect and Restore Workflow History), and verify its compilation and test results before accepting.

  3. Acceptance idempotency key (ACCEPT_KEY): generate and save a unique key for this acceptance; reuse the exact same key if retrying after an uncertain network outcome.

Accept and publish a proposal

Accept the candidate using the server-issued reference and confirmation, then deploy it. Check the bound target in the originating authoring task first: a proposal bound to an existing workflow updates that workflow even when the workflow ID argument in the deployment call is empty, and any explicit workflow ID must match the bound target. An unbound proposal with an empty workflow ID performs its initial deployment (or replays that same deployment).

import os
import moi_product_sdk as sdk

client = sdk.new_with_personal_access_token(
    os.environ["PRODUCT_API_BASE_URL"], os.environ["PRODUCT_API_KEY"]
)
workspace = client.workspace(os.environ["WORKSPACE_ID"])
accepted = workspace.accept_workflow_candidate(
    sdk.WorkflowCandidateRef(
        task_id=os.environ["TASK_ID"], artifact_id=os.environ["ARTIFACT_ID"]
    ),
    sdk.WorkflowCandidateConfirmation(
        proposal_id=os.environ["PROPOSAL_ID"], idempotency_key=os.environ["ACCEPT_KEY"]
    ),
)
workflow, deployment = workspace.deploy_workflow_candidate(
    "Document processing", accepted, "",
    sdk.with_workflow_execution_mode("one_shot"),
)
print("Workflow:", workflow.id)
print("Warnings:", deployment.warnings)
package main

import (
	"context"
	"fmt"
	"os"

	sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)

func main() {
	ctx := context.Background()
	client, err := sdk.NewWithPersonalAccessToken(
		os.Getenv("PRODUCT_API_BASE_URL"),
		os.Getenv("PRODUCT_API_KEY"),
	)
	if err != nil {
		panic(err)
	}
	workspace, err := client.Workspace(os.Getenv("WORKSPACE_ID"))
	if err != nil {
		panic(err)
	}
	ref := sdk.WorkflowCandidateRef{
		TaskID:     os.Getenv("TASK_ID"),
		ArtifactID: os.Getenv("ARTIFACT_ID"),
	}
	confirmation := &sdk.WorkflowCandidateConfirmation{
		ProposalId:     os.Getenv("PROPOSAL_ID"),
		IdempotencyKey: os.Getenv("ACCEPT_KEY"),
	}
	accepted, err := workspace.AcceptWorkflowCandidate(ctx, ref, confirmation)
	if err != nil {
		panic(err)
	}
	workflow, deployment, err := workspace.DeployWorkflowCandidate(
		ctx,
		"Document processing",
		accepted,
		"",
		sdk.WithWorkflowExecutionMode("one_shot"),
	)
	if err != nil {
		panic(err)
	}
	fmt.Println("Workflow:", workflow.ID())
	fmt.Println("Warnings:", deployment.GetWarnings())
}

Retain the complete acceptance record returned by the server and pass it unchanged to deployment; during deployment, the server re-resolves the accepted reference and its target workflow. If deployment fails, keep the accepted record, adjust the deployment configuration, and retry deployment, then save the returned workflow ID.

Next steps

Last updated on