How to launch a request with a FILE using GraphQL


#1

Configure the process

To send a file to a process you need to :

  1. Enable the sub-process mode in the process and set Access level to Public.

  2. Create a file data (such as REQUEST_FILE) and select IN or INOUT as sub-process parameters.

    Create%20file%20data

Create a request with a file as parameter

With GraphQL, you need to use the CreateRequest method. There are three ways to send a file:

  • Send a file URL

  • Send a base64 file

  • Send an uploaded file

Send a file URL

The file you want to upload needs to be accessible by WorkflowGen. In the URL you can set a physical path accessible by WorkflowGen (prefixed by file:///) or another URL.

Local file

mutation {
  createRequest(input: {
    processName: "SIMPLE_REQUEST_FILE",
    isTest: true,
    parameters:[{
      name:"REQUEST_FILE",
      fileValue:{
        name: "test.txt",
        contentType: "text/plain",
        size: 616,
        url: "file:///C:\\GraphQL\\test.txt"
      }
    }]
  }){
    request {
    number
    }
  }
}

To authorize WorkflowGen to access your file, go to the Configuration Panel Integration tab. In the GraphQL section, enter your folder path in the Input file allowed folders (comma separated values) field.

setfolder

Public file

mutation {
  createRequest(input: {
    processName: "SIMPLE_REQUEST_FILE",
    isTest: true,
    parameters:[
      {
        name:"REQUEST_FILE",
        fileValue:{
          name: "update.zip",
          contentType: "application/zip",
          size: 4120858,
          url: "http://download.workflowgen.com/product/latest/update.zip"
        }
      }
    ]
  		}) {
    request {
      number
    }
  }
}

You can use the above code in the GraphiQL editor (http:\\YOUR_SITE\wfgen\graphql).

Use a file content parameter

mutation {
  createRequest(input: {
    processName: "SIMPLE_REQUEST_FILE",
    isTest: true,
    parameters:[{
      name:"REQUEST_FILE",
      fileValue:{
        name:"test.txt",
        contentType:"plain/text",
        size:12,
        content:"R3JhcGhRTCBGaWxl"
      }
    }]
  }){
    request {
      number
    }
  }
}

To authorize WorkflowGen to rebuild the file, go to the Configuration Panel Integration tab. In the GraphQL section, set the size in the Maximum input file content size (kB) field.

setsize

You can use the above code in GraphiQL editor (http:\\YOUR_SITE\wfgen\graphql)

Use an uploaded file

curl -X POST \
  http://localhost/wfgen/graphql/
  -H 'content-type: multipart/form-data'
  -F 'operations={ "query": "mutation ($fileUpload1: Upload) { createRequest(input: {processName: \"SIMPLE_REQUEST_FILE\" processVersion:1 parameters:[{name:\"REQUEST_FILE\" fileValue:{ upload: $fileUpload1}}] }) { request { number } } }", "variables": { "fileUpload1": null } }' \
  -F 'map={ "z_file1": ["variables.fileUpload1"] }' \
  -F 'z_file1=@C:\GraphQL\test.txt'
Parameter Description
operations The operations field is required, and contains the GraphQL query
map The map field is required and contains the file mappings
z_file1 Each file to be uploaded should contain the alphanumeric key and the file path

Test

You can use the Postman project to test.


How to use WorkflowGen Web Services API to send a file