Call a process from a GET Web API

Hello,

I need to build several Web API's that, besides doing their main purpose, register in the database the parameters received and the date & time that the call occurred (basically, a customized log). I've started by creating the web API's with their main purpose and then, in the same web API, to use the a!startprocess or a!writetodatastoreentity(), bu it doesn't work.

I've tried to isolate the problem and came to two main bottlenecks:

1) Can I call a smart service in web API's of the method GET?

2) Even if the method is post, is it possible, for example, to start a process AND write the data store entity in the same Web API?

 

Is there a way to do this?

 

Thank you

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    1) You can't call smart services with GET API's, only POST/PUT/DELETE methods will allow you to launch a smart service.

    2) Could you pass in the log info to the process and write to the data store inside of your process instance? To get around having to put this DSE node for the Web API log in each process you will invoke, you could create a pass-through process model that writes to the DSE and then invokes the start process node to start the relevant process model.
  • 0
    Certified Lead Developer

    Hi  as per my understanding, you need to change your implementation approach a bit.

    Instead of calling two smart service functions together, (while working with POST/PUT/DELETE but not GET API methods) try calling a!startprocess() which will trigger the target process model, pass necessary information as it's parameter and persist the data into the DB using Write to Data Store Entity Smart Service and then call the actual process, which you were trying to invoke.

    Hope this will help.

  • Thank you both for your answers!

    The problem of the a!startprocess() is that 1) it's asynchronous and 2) I can't pass values out of the process for the a!httpResponse().
    I was trying to do both things separately inside the Web API, because I need to give a response (ex: calculate something, get/post client data) and to log the request.
    Should I try a different approach? For example, trying to retrieve the information from the Appian Logs?

    Regards
    Susana
  • Hi ... I think the JBOSS / TOMCAT access log (18.3 and higher for TOMCAT) will register the webAPI calls - not sure if that will include parameters or not though. You could try checking that access log in the root directory of the logs to see if it contains the information you need.
  • 0
    Certified Lead Developer

    Yes we can call  write the data store entity and  start a process one in another  in the Web API  something like below

     a!writeToDataStoreEntity(
            dataStoreEntity: cons!DSE_NAME,
            valueToStore: local!constructRequest,
            onSuccess: a!startProcess(
              processModel: cons!PM_NAME,
              processParameters: {
                inputJason: a!toJson({ aa: fv!storedValues })
              },
              onSuccess: a!httpResponse(
                statusCode: 200,
                headers: {
                  a!httpHeader(
                    name: "Content-Type",
                    value: "application/json"
                  )
                },
                body: a!toJson({ aa: fv!storedValues, bb: fv!processInfo })
              ),
              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"
                  }
                )
              )
            ),
            onError: a!httpResponse(
              statusCode: 500,
              headers: {
                a!httpHeader(
                  name: "Content-Type",
                  value: "application/json"
                )
              },
              body: a!toJson(
                {
                  error: "There was an error writing to the data store"
                }
              )
            )
          )