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:

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

Parents Reply Children
No Data