Calling a third party api from cloud code or directly on view

Hi,

I have to validate two fields by using a third party api on button click.
What should i use cloud code task or directly hit api on button click.

Hi @taranbirbajwa

I would use a CloudCode task that you call directly from the app when the user press the button.

  • Reason being that with using a CC task, you have the CC Invocation History to look at if something goes wrong with your API call in production.

If your app flow does not require a synchronous validation, you could have the validation happen asynchronously with calling the CC task via a webhook.

If anyone has some reasons for calling an API directly from the app, I’d like to know your thoughts.

  • Only reason I can think to call an API directly from the app is if the call is directly on the local network (VPN network) of the device or maybe if for some geographical/other reason you don’t want to route the API call through CloudCode.

One thing I’ve noticed testing CC is there might be a delay before its status goes to STARTED
Is that just because I’m running that in testing?

Also, If I just needed a distance, or shipping amount, or temperature, then it sure would be easier to call a simple endpoint (via Button) than go thru all the CC stuff. (I’m biased, because CC is kicking my ass right now so I’m not a fan :grinning: )

@jaymer you make a good point, but CloudCode works great for making asynchronous API calls especially when the application has offline requirements.

yes, i keep forgetting that.
my app def. needs offline, but I forgot about that in the context of your message.
definitely wouldn’t work for me.