Hi,
i've a portal with some users fileds. When i compile the fields on click button i want to save this fields in my appian db using post api (i want to test the API). I wrote this code for the portal interface:
=a!localVariables( local!nome, local!cognome, local!dataNascita, local!indirizzoResidenza, local!codiceFiscale, { a!textField( label: "Nome", value: local!nome, saveInto: local!nome ), a!textField( label: "Cognome", value: local!cognome, saveInto: local!cognome ), a!textField( label: "Data di nascita", value: local!dataNascita, saveInto: local!dataNascita ), a!textField( label: "Indirizzo di residenza", value: local!indirizzoResidenza, saveInto: local!indirizzoResidenza ), a!textField( label: "Codice fiscale", value: local!codiceFiscale, saveInto: local!codiceFiscale ), a!buttonLayout( primaryButtons: { a!buttonWidget( label: "Invia dati", saveInto: { } ) } ) })
=a!localVariables(
local!nome,
local!cognome,
local!dataNascita,
local!indirizzoResidenza,
local!codiceFiscale,
{
a!textField(
label: "Nome",
value: local!nome,
saveInto: local!nome
),
label: "Cognome",
value: local!cognome,
saveInto: local!cognome
label: "Data di nascita",
value: local!dataNascita,
saveInto: local!dataNascita
label: "Indirizzo di residenza",
value: local!indirizzoResidenza,
saveInto: local!indirizzoResidenza
label: "Codice fiscale",
value: local!codiceFiscale,
saveInto: local!codiceFiscale
a!buttonLayout(
primaryButtons: {
a!buttonWidget(
label: "Invia dati",
saveInto: {
}
)
I also created a post api:
a!localVariables( local!value: cast( 'type!{urn:com:appian:types:AHUTENTE}AH_UTENTE', a!fromJson(http!request.body) ), a!writeToDataStoreEntity( dataStoreEntity: cons!AH_UTENTE_DSE_POINTER, 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" } ) ) ))
Now I was wondering, how do I call the API to write to the db within the interface and pass the parameters? Do I need anything else? Sorry but I'm not very practical.
Discussion posts and replies are publicly visible
Can you please wrap your code in the code window?
You will need to create an Integration object to call the API - https://docs.appian.com/suite/help/23.4/Create_an_Integration.html
When you are done creating and testing the integration successfully, then you can call that integration in your button's saveInto.
Try doing the steps I told you and if you face any errors or issues, feel free to post them here.
You don't need to create an API then. You can directly start processes from a button's saveInto
I tried, the request gives me success, but it doesn't write anything in the db
Can you share a screenshot of your API? What are you doing there?
The URL you have added in the integration is not correct. Here is where you can find the right URL in your API.
Ok done but when click on test i've this message "
Authentication is required
This request requires Basic authentication, but no credentials were provided HTTP/1.1 401 Next Steps
"
so i put basic auth -> insert my user and pass and i've this "
Something went wrong
Failed to connect to mptq.appian.community/.../add-new-user Next Steps
Why??
1) Yes
2) Ehm I don't know (i think yes)
And if you test the API using the "Test Request" button, does it work fine?
Oh now it works fine . Oh thanks!!!
But now how i can pass the params from the interface?
Okay. The final step, make sure the body you are sending is correct and in the same format as accepted by the API
yes the same
If your data isn't business sensitive, can you paste the body here and also add the screenshot of the entire Integration window where you have added the Username and password (keep it masked) and integration's output?
Harshit Bumb (Appyzie) thanks so much,i've called the integration from the interface passing all the ri like this Call an Integration - Appian 23.4. Thanks a lot!
Awesome. Looks like the problem was with the request body.
If you found what you were looking for, please verify the answers to close this thread!
Harshit Bumb (Appyzie) the last thing, when i call the integration in my interface i get the response like the image below, but if you see into the body i've the id, how can i get it and save into a local variable? It's important this for me
In your integration, make sure this is configured - "Convert JSON to Appian value"
Then in your interface, where you are calling the integration -> onSuccess, you can write the following block of code.
a!save(local!userResult, fv!result.body.id)