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.
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.