Skip to main content
priyas0007
October 7, 2021
Question

Invoke POST WebAPI

  • October 7, 2021
  • 8 replies
  • 0 views

Hi,

I have created a!writeToDataStore in webAPI which is writing to DB when I test through API,to invoke this API I created an integration of Method POST and URL accepting ri! as parameters.

I am unable to write to DB when I test through integration.Can someone please help where I am going wrong.

Later I want to use this integration in my interface.

Thanks in advance!

    8 replies

    danny.verb
    October 7, 2021

    You can use a!writeToDataStore() directly in your Appian interface.

    In the onSuccess and onFailure parameters of a!writeToDatastore you can return an HTTP response using the a!httpResponse() function. I recommend using this to help you view useful information when testing in the API designer. 

    priyas0007
    October 8, 2021

    Hi [mention:cd62cf79924f483cb1bf072c9026a3ec:e9ed411860ed4f2ba0265705b8793d05] 

    Thanks for the reply I tried that only first,

    but this is what I get in response,not sure what I am missing.

    a!localVariables(
      local!value:
      a!writeToDataStoreEntity(
      dataStoreEntity: cons!DS,
      valueToStore: ri!variable,
      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"
          }
        )
      )
    ),
    local!value
    )

    danny.verb
    October 8, 2021

    You can't test Smart Services in the expression rule editor, instead, try running that code directly in the Web API designer. Also, since you don't need any local variables there's not need to put your a!writeToDataStoreEntity() in a local variable