I have read the Documentation for creating relations with REST but am having trouble applying it to my specific situation.
Whenever the HTML form is submitted, it will fill my “APIs” table with APIEndpoint, APISecretKey, and EmailAddress. I would like for it to automatically add an entry to the three Latency tables using the APIEndpoint property. Could you please help me set this up? The part I am having trouble with is setting the data type for the properties in console and the -d parameter in the REST POST request. This is what my four tables look like:
APIs
APIEndpoint
APISecretKey
EmailAddress
Latency_SanJose
APIEndpoint
Run01
Run02
Run03
Latency_NewYork
APIEndpoint
Run01
Run02
Run03
Latency_Orlando
APIEndpoint
Run01
Run02
Run03
Thank you in advance.
Hello, Eric!
First, let’s consider I’ve understood you right. By submitting the form, you’re sending a POST request which would create a row in table “APIs”. This table has three columns with type String: EmailAddress, APISecretKey and APIEndpoint. You’d like to create three more rows in other three tables, each of them referencing the row you’ve just created in table “APIs”. Is that right?
About -d parameter: it contains json object, which describes the entity you’d like to create. If one of entities property is a relation, you should include “___class” property to the nested object. Let me show an example: here is a request (without needed headers) which creates rows in two tables - Person and Address:
curl -X POST -v http://api.backendless.com/v1/data/Person -d {"name":"Bob", "address":{"___class":"Address", "city":"New York"}}
Here class Person has two properties: “name” (String) and “address” (relation to table Address). Class Address has one property: “city”(String).
If these tables didn’t exist before request execution, they would be created.
You can practice with Backendless REST API for data service using our REST console. You can find it on “Data” tab in developers console of your application.
Hope it would help you.
with best regards,
Alex Navara