It seems that if an deployed Backendless API service modifies a DB table, the onCreate event is not captured for an event handler to respond to and process.
What is the correct way to respond to a table being changed from an API service that’s been triggered?
Here’s my process:
API call to add an item to a table → after the call is completed and the new object response is returned to the caller of the API I need to POST a call to an additional foreign API and simply print the results of this call to the RT Logs for reference and troubleshooting.
if you call POST /orders event handler for the table will not be triggered when you make the call. This happens because the system doesn’t trigger the event handler when you call data service from server cloud code. In case when you use server cloud code you can do anything you need inside the service
However, the event handler will be triggered if you directly call the Data Service API from the client, such as by using cURL or any other client.
For example, you can use a cURL command like this:
curl -X POST https://<your-generated-domain>.backendless.app/api/data/LabSavvy -d ‘{…data…}’
This will ensure that the event handler is executed as expected.
Let me know if you need further clarification or assistance!
The problem with this one (the Create Order service) is that after I return the response back to the invoker of the API, I need to branch to a HTTPS POST call to a foreign API, but the results of THIS call (which I’m assuming is the error) are being returned to the caller instead of what I’m actually trying to return: (the “SOSPostObject”).
Here’s the error that I get when I try this: (Triggered by the HTTPS POST call in the POST to SOS API function)
Wed Aug 14 2024 10:03:54 GMT-0400 (Eastern Daylight Time) | SERVER_CODE | ERROR | [1843458] Error:
## Object moved to [here](https://develop.backendless.com/error.aspx?status=HYbB5vm9hJPmFvTGq3cdGjfzxNqYhDqwsANSPNpHdw9JThVINObXDQ%3d%3d).
at checkStatus (/usr/local/lib/node_modules/backendless-coderunner/node_modules/backendless-request/lib/request.js:343:9) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
I’m not sure what the correct way to accomplish this is.
In other words, I need to POST to another API AFTER the record is created in the DB by this service, and still return the proper response of the newly created object back to the caller of the API.
Steps: #1 : Create the new record in the DB #2 : Return the newly created object back to the API invoker #3 : Make a separate call to the foreign API and simply write the results of the call to the RT Logs.
Steps: #1 : Create the new record in the DB #2 : Make an async call to the foreign API and simply write the results of the call to the RT Logs. #3 : Return the newly created object back to the API invoker
the codeless logic runs in a specific environment, we call it CodeRunner Worker
each worker wait until your code is complemented
once your logic is done the worker will be killed
the AsyncBlock runs code outside the main invocation flow and as a result, the worker does not wait until the async code is done and the worker might be killed before it’s completed sending any HTTP requests inside the AsyncBlock
Therefore:
there is no guarantee that it will have time to send the request
there is no guarantee that it will have time to receive a response from the request
How do I capture the HTTPS response from this async POST call to the foreign API?
The SOSResponse variable (that is await-ing) is currently just an empty object because of the timing of setting the variable occurs after the POST call is already out-of-scope, right?
If it’s currently not possible to do this, I’m a little confused why @sergey.kuk recommended this route?
How, exactly, can this be accomplished in Backendless?
How do I capture the HTTPS response from this async POST call to the foreign API?
The SOSResponse variable (that is await-ing) is currently just an empty object because of the timing of setting the variable occurs after the POST call is already out-of-scope, right?
If it’s currently not possible to do this, I’m a little confused why @sergey.kuk recommended this route?
How, exactly, can this be accomplished in Backendless?
If you need to simply log result of that HTTP block to RT or other place you need to add a logging logic to that async block so it will be executed independently from main execution flow when response from foreign API is returned.
It is better not to ask additional questions in topics which were marked as “answered” and create a new topic instead. In this way you will get answer to your question as soon as possible.