Posting data to multiple tables with joins

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsPosting data to multiple tables with joins
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
### Tutorial
 
 
 
POST records to multiple SQL tables related by foreign key. Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL.
 
POST records to multiple SQL tables related by foreign key. Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL.
 +
 +
'''Note''' When using a 'Many to Many' relationship to POST you must use an array for the related data.
  
 
Note that this example also applies to updating records.
 
Note that this example also applies to updating records.
  
### API Endpoint
+
=== API Endpoint ===
  
 
<pre>POST https://{url}/api/v2/{api_name}/_table/{table_name}</pre>
 
<pre>POST https://{url}/api/v2/{api_name}/_table/{table_name}</pre>
  
### API Docs Screenshot
+
=== API Docs Screenshot ===
  
[[File:Swagger-post-related-records.png]]
+
[[File:Swagger-post-related-records.png|1000px]]
  
### Example - Post multiple contact records
+
=== Example - POST contact records (parent table) and contact_info_by_contact_id records (child table) ===
  
 
* Table name: contact
 
* Table name: contact
* Body parameter in API call: <pre>{
+
* Body parameter in API call:  
 +
<pre>
 +
{
 
  "resource": [
 
  "resource": [
 
   {
 
   {

Latest revision as of 19:49, 9 October 2019

POST records to multiple SQL tables related by foreign key. Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL.

Note When using a 'Many to Many' relationship to POST you must use an array for the related data.

Note that this example also applies to updating records.

API Endpoint

POST https://{url}/api/v2/{api_name}/_table/{table_name}

API Docs Screenshot

Swagger-post-related-records.png

Example - POST contact records (parent table) and contact_info_by_contact_id records (child table)

  • Table name: contact
  • Body parameter in API call:
{
 "resource": [
   {
     "first_name": "Alice",
     "last_name": "Jones",
     "contact_info_by_contact_id": [
        {
          "info_type": "home",
          "phone": "701-555-5555",
          "email": "[email protected]",
          "address": "3761 N. 14th St",
          "city": "MEDINA",
          "state": "ND",
          "zip": "58467",
          "country": "USA"
        },
        {
          "info_type": "work",
          "phone": "701-555-5556",
          "email": "[email protected]",
          "address": "2243 W St.",
          "city": "MEDINA",
          "state": "ND",
          "zip": "58467",
          "country": "USA"
        }
    ]
   },
   {
     "first_name": "Bob",
     "last_name": "Simpson",
     "contact_info_by_contact_id": [
        {
          "info_type": "home",
          "phone": "701-555-0162",
          "email": "[email protected]",
          "address": "3762 N. 14th St",
          "city": "MEDINA",
          "state": "ND",
          "zip": "58467",
          "country": "USA"
        },
        {
          "info_type": "work",
          "phone": "701-555-0110",
          "email": "[email protected]",
          "address": "2244 W St.",
          "city": "MEDINA",
          "state": "ND",
          "zip": "58467",
          "country": "USA"
        }
    ]
   }
 ]
} 
  • Request URL:
    https://foo.com/api/v2/db/_table/contact