How to write record data within a GET method Web API

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:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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']
)
)
)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  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. 

  • +1
    Certified Lead Developer

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

  • 0
    Certified Lead Developer

    That logging is already implemented by the Appian platform. There is no need to do that yourself.

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