API Update By Unique Key

API Update By Unique Key

  

Hi everyone,

I have a table, and I want to create update API by phonenumber not by id_table. 

But when I try in SQL and with hardcode data not with parameters, the data was successfully updated. 

But when I implement with parameters in SQL, the data was not updated. 

Here, my code. Is there any steps that I don't implement or something ?

Kind Regards,

Sabdo Widiastuti

Assuming you're passing the REST method's parameters to the SQL widget, it seems ok. Two remarks, though:

  • Check for errors in Service Center. By default, the transaction will rollback if an exception occurs.
  • Not sure why you need the 1st aggregate in your screenshot.

Paulo Ramos wrote:

Assuming you're passing the REST method's parameters to the SQL widget, it seems ok. Two remarks, though:

  • Check for errors in Service Center. By default, the transaction will rollback if an exception occurs.
  • Not sure why you need the 1st aggregate in your screenshot.

Hi Paulo, 

Thank's for your response before. :)

About the aggregate, I just wanna try maybe that's can be working if I add filter data by phone number. And I already delete it. 

And after I check in error log and there was nothing. 

And I check it in Integrations tab, my rest API was not marked as error. Like in picture bellow.

 

Kind Regards, 

Sabdo Widiastuti

I'm not seeing anything obvious in the screenshots.

Try debugging your web service (in the public area). If you can't find the issue, post your eSpace here and I'll take a look.

Paulo Ramos wrote:

I'm not seeing anything obvious in the screenshots.

Try debugging your web service (in the public area). If you can't find the issue, post your eSpace here and I'll take a look.

After I try debugging my web service, this is my local view. and After I press F11 (until ending debugging) there was nothing / empty view. 

And I attached my file bellow if you want take a look my web service. 

Thank's before. 


Kind Regards, 

Sabdo Widiastuti


Solution

Well, the data is being correctly updated, but you're not returning the values in the query (you're only updating the row).

Try changing the query in order to return the customer record that was just updated:

UPDATE {Customer} set {Customer}.[Name] = @SalesName where {Customer}.[PhoneNumber] = @PhoneNumber;
SELECT {Customer}.* from {Customer} where {Customer}.[PhoneNumber] = @PhoneNumber

This will work, but as an alternative to writing SQL, consider using one Aggregate to load the record; an Assign element to change the name in memory; and an entity action (UpdateCustomer) to save it in the database.

Solution

Paulo Ramos wrote:

Well, the data is being correctly updated, but you're not returning the values in the query (you're only updating the row).

Try changing the query in order to return the customer record that was just updated:

UPDATE {Customer} set {Customer}.[Name] = @SalesName where {Customer}.[PhoneNumber] = @PhoneNumber;
SELECT {Customer}.* from {Customer} where {Customer}.[PhoneNumber] = @PhoneNumber

This will work, but as an alternative to writing SQL, consider using one Aggregate to load the record; an Assign element to change the name in memory; and an entity action (UpdateCustomer) to save it in the database.


Hi Paulo Ramos, 

Thank's for your help. You save my day.


Kind Regards, 

Sabdo Widiastuti

Hi Sabdo,

I'm just curious why do you need to use API to update a row? Do you have a special case or reason?


Regards,

Lady

Lady wrote:

Hi Sabdo,

I'm just curious why do you need to use API to update a row? Do you have a special case or reason?


Regards,

Lady


Hi Lady, 

Yeah, because this API will be consume in mobile apps but in the mobile apps data was not access my API, so I need to update by unique key. 


Kind Regards, 

Sabdo Widiastuti

Hi,

Just a remark, if you're planning to build an OutSystems mobile app to consume this API, you don't really need to build a REST API. Just expose your services using public server actions and then reference + use them from the mobile app.

When you execute a server action from the mobile app, you're actually invoking a REST service, but this way OutSystems takes care of all the plumbing for you.

Paulo Ramos wrote:

Hi,

Just a remark, if you're planning to build an OutSystems mobile app to consume this API, you don't really need to build a REST API. Just expose your services using public server actions and then reference + use them from the mobile app.

When you execute a server action from the mobile app, you're actually invoking a REST service, but this way OutSystems takes care of all the plumbing for you.

Hi Paulo,

Can you help to explain more when is the best time(s) to use API? When do we need it?


Thanks,

Lady


Hi,

REST APIs are usually used when you need to expose services to other systems. Besides that, there are a few more advanced scenarios on which they may be useful, such as when building a microservices or plugin architecture. 

But for allowing an OutSystems mobile app to communicate to the server, it's probably not needed (unless you have very a specific scenario), as server actions allow it in a simpler way.

Paulo Ramos wrote:

Hi,

REST APIs are usually used when you need to expose services to other systems. Besides that, there are a few more advanced scenarios on which they may be useful, such as when building a microservices or plugin architecture. 

But for allowing an OutSystems mobile app to communicate to the server, it's probably not needed (unless you have very a specific scenario), as server actions allow it in a simpler way.

Hi Paulo,

I used it once when I have to integrate Outsystems with Mulesoft, that's why I was a little bit confuse why does Sabdo need to use it for updating a row.

Thank you for your clear explanation.


Have a good day,

Lady

hi there,

My experience in a real project is there are web developers (who creates web app and must know the business) that must provide web services that will be consumed by mobile app and the mobile developers just want to know..what is the inputs, and the outputs and how to display it in the mobile phone. So, the mobile developers do not know the business. They just view the business as a black box.

The mobile application are created both using hybrid outsystems and native java.

regards,

A