How to create Data store web api?

Certified Associate Developer

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])

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    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"
              }
            )
          )
        )
      )
    )

Reply
  • 0
    Certified Senior Developer

    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"
              }
            )
          )
        )
      )
    )

Children
No Data