Skip to main content
February 23, 2023
Question

How to create Data store web api?

  • February 23, 2023
  • 5 replies
  • 0 views

created web api with below code but getting below error

local!entities: a!queryEntity(
entity: cons!TI_FINALEXCELTODATABASESTORE,
query: a!query(
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 50
)
),
fetchTotalCount: true
).data,

An error occurred while retrieving the data. Details: Unexpected error executing query (type: [TIFinalExcelToDatabaseDT7969], query: [queryentity expression], order by: [[Sort[null asc]]], filters:[null])

    5 replies

    harshitb6843
    February 23, 2023

    Looks like the problem is with the sort fields. Try to check if

    1. the entity is verified successfully in the Data store
    2. Try passing at least one sort field and see if it works. 
    Inspiring
    February 23, 2023

    You can also verify database permissions. In case if you are using alias for tables in DB, make sure verify those alias and permissions.

    abhayd3663
    February 23, 2023

    From the error it looks like it is expecting values for sort and filter parameters. Although the sort and filter parameter are optional in a!pagingInfo(), the a!query() should work without these parameters. Make sure the constant "cons!TI_FINALEXCELTODATABASESTORE" points to correct entity and publish the Data Store. 

    February 24, 2023

    If you want to add record using post method in data store entity you will write code as given example below

    a!localVariables(
      local!value: cast(
        'type!{urn:com:appian:types}KBS_Categories',
        a!fromJson(http!request.body)
      ),
      /*  API never updates existing data */
      if(
        not(
          isnull(index(local!value, "catName", null))
        ),
        a!httpResponse(
          statusCode: 400,
          headers: {
            a!httpHeader(
              name: "Content-Type",
              value: "application/json"
            )
          },
          body: a!toJson(
            {
              error: "The provided Category data included an id, which is not allowed.  " & "You can only create new category name, not modify ones that already exist."
            }
          )
        ),
        a!writeToDataStoreEntity(
          dataStoreEntity: cons!KBS_CATEGORY_API_POST,
          valueToStore: local!value,
          onSuccess: a!httpResponse(
            statusCode: 200,
            headers: {
              a!httpHeader(
                name: "Content-Type",
                value: "application/json"
              )
            },
            body: a!toJson(fv!storedValues)
          ),
          onError: a!httpResponse(
            statusCode: 500,
            headers: {
              a!httpHeader(
                name: "Content-Type",
                value: "application/json"
              )
            },
            body: a!toJson(
              {
                error: "There was an error writing to the data store"
              }
            )
          )
        )
      )
    )

    stefanhelzle0001
    Brainy
    February 24, 2023

    I suggest to check the tomcat-stdout log file for details. I see these kind of error messages often related to timeout or memory issues.