Questions on WEB API Object

Hi,

Need help on below. Could someone please help me?

I have few questions on Web API objects:

  1. Can I use query parameters in Post method? In what scenario?
  2. Where can we use Query Parameters as well as body in Post method?
  3. When I am trying to update one field model by passing body as

{"id":1,

"model":"Jaguar"},

 

It is updating all the fields and except id and model all other fields are updated with null.

How can I update only “model” field?

 

Thanks

Faisal

  Discussion posts and replies are publicly visible

Parents
  • The Web API objects are really cool as they can be any Appian expression. You can access the entire HTTP requesting using the HTTP!request domain 

    https://docs.appian.com/suite/help/21.2/Designing_Web_APIs.html#accessing-the-http-request

    1. You can use query parameters for a POST method, it's really up to you as you are defining the API requirements. Common query parameters might be sorting information or locale information

    2. Looking at the docs above, you can use HTTP!request.queryParameters to access the query parameters anywhere in your expression.

    3. When updating a database row using a!writeToDataStore() you must always provide all fields, otherwise fields get overwritten. To do this, query the row from the database first, then use a!update() to update the new field before writing to the database.

  • Hi Danny,

    Thank you for the answers. I am clear about first and second questions.

    I will rephrase my second question.

    In a same web API object creation can  Query parameters and Body both be used? if yes, in what scenario?

    If no, it means at a time only one thing either Query Parameter or Body can be used. Kindly correct me if this is a wrong understanding.

    Thanks

    Faisal

  • Sure you can use both query parameters and body in a POST. Like Danny said, you can reference both of them using the http! domain. The main thing to make sure is that whatever system you're making the request from adds the parameters in a way that you can use it. Here's an example of how you can pull both the query parameters and body to start a process based on the details from the request:

    a!localVariables(
      local!queryParameters: http!request.queryParameters,
      local!body a!fromJson(
        http!request.body
      ),
      a!startProcess(
        processModel: cons!MY_PROCESS_MODEL,
        processParameters: {
          queryParameters: local!queryParameters,
          body: local!body
        },
        onSuccess: a!httpResponse(
          statusCode: 200,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            fv!processInfo
          )
        ),
        onError: a!httpResponse(
          statusCode: 500,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            {
              error: "There was an error starting the process"
            }
          )
        )
      )
    )

Reply
  • Sure you can use both query parameters and body in a POST. Like Danny said, you can reference both of them using the http! domain. The main thing to make sure is that whatever system you're making the request from adds the parameters in a way that you can use it. Here's an example of how you can pull both the query parameters and body to start a process based on the details from the request:

    a!localVariables(
      local!queryParameters: http!request.queryParameters,
      local!body a!fromJson(
        http!request.body
      ),
      a!startProcess(
        processModel: cons!MY_PROCESS_MODEL,
        processParameters: {
          queryParameters: local!queryParameters,
          body: local!body
        },
        onSuccess: a!httpResponse(
          statusCode: 200,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            fv!processInfo
          )
        ),
        onError: a!httpResponse(
          statusCode: 500,
          headers: {
            a!httpHeader(name: "Content-Type", value: "application/json")
          },
          body: a!toJson(
            {
              error: "There was an error starting the process"
            }
          )
        )
      )
    )

Children
No Data