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

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

Children
No Data