Skip to main content

Workflow Template

The interfaces related to workflow templates allow users to generate diagrams using a predefined series of templates, requiring only simple modifications to a few parameters within the template.

Get Workflow Template

  • Request Parameter Example: Replace the following parameters in the URL path.

    template_id: 676018193025756628

    Response (Including all fields that need to be modified) :

    {
    "templateId": "676018193025756628",
    "name": "二次元转真实",
    "fields": {
    "fieldAttrs": [
    {
    "nodeId": "25",
    "fieldName": "image",
    "fieldValue": ""
    },
    {
    "nodeId": "27",
    "fieldName": "text",
    "fieldValue": "1 girl"
    }
    ]
    }
    }

Check Workflow Template Parameters

This interface first retrieves the workflow template, then replaces the fields corresponding to the request parameters in the obtained template (specifically, replacing the field_value in the node_id corresponding to field with field_name). After the replacement is completed, it checks if the parameters are valid. If they are valid, it returns the estimated credits based on the parameters.

  • Error Request Example 1(Some fields are missing in the parameters.):

    {
    "template_id": "676018193025756628",
    "fields": {
    "field_attrs": [
    {
    "node_id": "27",
    "field_name": "text",
    "field_value": "1 girl, amber_eyes"
    }
    ]
    }
    }

    Response:

    {
    "code": 2,
    "message": "can't find [nodeId:fieldName] 25:image in fields parameter"
    }
  • Error Request Example 2: During the processing of this request, the image of node_25 in the obtained template will be set to null. Since this action is invalid, it will return false along with the error reason.

    {
    "templateId": "676018193025756628",
    "fields": {
    "fieldAttrs": [
    {
    "nodeId": "25",
    "fieldName": "image",
    "fieldValue": null
    },
    {
    "nodeId": "27",
    "fieldName": "text",
    "fieldValue": "1 girl"
    }
    ]
    }
    }

    Response:

    {
    "code": 3,
    "message": "Params Valid",
    "details": [
    {
    "@type": "type.googleapis.com/tams_api.ArgumentError",
    "field": "workflow",
    "message": "node id: 25\nclass type: LoadImage\nimage: 字段必填\n"
    }
    ]
    }
  • Correct Request Example:

    {
    "templateId": "676018193025756628",
    "fields": {
    "fieldAttrs": [
    {
    "nodeId": "25",
    "fieldName": "image",
    "fieldValue": "f29036b4-ff7b-4394-8c26-aabc1bdae008"
    },
    {
    "nodeId": "27",
    "fieldName": "text",
    "fieldValue": "1 girl"
    }
    ]
    }
    }

    Response (estimated credits are 1):

    {
    "valid": true,
    "credits": 1
    }

Create Workflow Template Job

This interface also retrieves the workflow template, then replaces the fields and checks the parameters. After the checking is completed, it creates a new job to generate the diagram. (fieldValue is the media_resource_id obtained after uploading the image)

  • Request Example:

    {
    "request_id": "cc05d4e1a98f8a1438ea6ebcce77a8d5",
    "templateId": "676018193025756628",
    "fields": {
    "fieldAttrs": [
    {
    "nodeId": "25",
    "fieldName": "image",
    "fieldValue": "f29036b4-ff7b-4394-8c26-aabc1bdae008"
    },
    {
    "nodeId": "27",
    "fieldName": "text",
    "fieldValue": "1 girl"
    }
    ]
    }
    }

    request_id is an md5 string generated based on the current timestamp. You can use the following JavaScript script or script in other languages to generate it:

    const crypto = require('crypto')
    const request_id = crypto
    .createHash('md5')
    .update('' + Date.now())
    .digest('hex')
    console.log(request_id)

    Response (You can query the diagram generation status using the returned jobId. The status of the newly created job is CREATED):

    {
    "job": {
    "id": "709385162603889157",
    "status": "CREATED"
    }
    }