Posting data to multiple tables with joins

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsPosting data to multiple tables with joins
Line 1: Line 1:
### Tutorial
+
=== 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.
Line 5: Line 5:
 
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|1000px]]
 
[[File:Swagger-post-related-records.png|1000px]]
  
### Example - POST contact records (parent table) and contact_info_by_contact_id records (child table)
+
=== 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": [
 
   {
 
   {

Revision as of 17:55, 3 February 2016

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.

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