Hi everyone,
I’ve created a GET method Web API that returns a list of countries in the HTTP response. The Web API also includes a query parameter for the username. Now I need to log each Web API call by saving the endpoint name, response body, query parameter, and the current date and time into my Web API Log record. However, the issue I am facing is that Appian doesn't allow the execution of the WriteRecords smart service within a GET method Web API and gives me this error: Smart Services cannot be executed in Web APIs that have a method of "GET." Does anyone have any suggestions on how to handle this case without changing the API method to POST, PUT, or any other? I would appreciate any help. Thank you!
For reference, here’s an example of my Web API code:
a!localVariables( /* Retrieve all avalaible countries from the corresponding Record Type */ local!countries: a!queryRecordType( recordType: 'recordType!ABC Country', pagingInfo: a!pagingInfo( startIndex: 1, batchSize: 300 ) ).data, /* Generate JSON response body */ local!responseBody: a!toJson( a!forEach( items: local!countries, expression: a!map( "countryCode": fv!item['recordType!ABC Country.fields.countrycode'], "countryName": fv!item['recordType!ABC Country.fields.countryname'] ) ) ) /* Write the Web API Log and return a list of countries in a JSON format */ a!writeRecords( records: { 'recordType!ABC Web API Log'( 'recordType!ABC Web API Log.fields.endpointname': "Get Countries List", 'recordType!ABC Web API Log.fields.responseBody': tostring(local!responseBody), 'recordType!ABC Web API Log.fields.username': http!request.queryParameters.username, 'recordType!ABC Web API Log.fields.createdon': now() ) }, onSuccess: a!httpResponse( statusCode: 200, body: local!responseBody ) ) )
Discussion posts and replies are publicly visible
have you considered enabling request/response loggingg for this webApi. This can be enabled from the properties section.
I dont think there is a way to do that in Appian.
Change the method of API to POST and you can write the details to record and pass the required http response.
Only web APIs for the POST, PUT, DELETE, and PATCH methods may execute smart services.
Web APIs for the GET method will not execute any smart services included in their expression. Attempting to do so will result in the following error message: Smart Services cannot be executed in Web APIs that have a method of "GET."
That logging is already implemented by the Appian platform. There is no need to do that yourself.
Kumar Agniwesh Thank you for your message, but unfortunately it won't work in my scenario. I used to log all my POST Web APIs calls in a separate Log record as it's easier to access and work with. So I was hoping that there is a way do the same for GET Web APIs as well.