API is giving error invalid JSON format

Certified Associate Developer

I've created a web API that retrieves data from a process model, but when I call this API during integration,it returns the following error:
Error Code: errorIntegrationError
Title: Error processing integration response
Message: The response body could not be converted to an Appian value
Detail: The jsonText parameter was not valid JSON. Received: <...>.

I have attached the code

a!startProcess(
  processModel: cons!PDBPOC_gDrivePermissionPM,
  isSynchronous: true(),
  onSuccess: a!httpResponse(
    statusCode: 200,
    headers: {
      a!httpHeader(
        name: "Content-Type",
        value: "application/json"
      )
    },
    body: a!toJson(
      if(
        a!isNotNullOrEmpty(fv!processInfo.pv.userData),
        fv!processInfo.pv.userData,
        {
          message: "userData process variable is empty or not set."
        }
      )
    )
  ),
  onError: a!httpResponse(
    statusCode: 500,
    headers: {
      a!httpHeader(
        name: "Content-Type",
        value: "application/json"
      )
    },
    body: a!toJson(
      {
        error: "There was an error starting the process"
      }
    )
  ),
  onIncomplete: a!httpResponse(
    statusCode: 504,
    headers: {
      a!httpHeader(
        name: "Content-Type",
        value: "application/json"
      )
    },
    body: a!toJson(
      {
        error: "The process did not complete within the expected time"
      }
    )
  )
)

  Discussion posts and replies are publicly visible