Import and Export

The import/export APIs allow you to work with a Realtime document using a RESTful API when you don’t have an active client.

  • get exports the document into a JSON format.
  • update takes in a document in that same JSON format, and updates the document with any changes

If you provide a baseRevision to the update request, the uploaded model is diffed against the provided revision and those differences are merged with any changes made to the model after the provided revision. Any active users would see the changes as if they were coming from an active collaborator.

This JSON format can be used in conjunction with the in-memory mode to manipulate a document using the Javascript API when not directly connected to the server.

Format

Top Level Fields

Each exported document contains three top level fields:

name type description
appId number The ID of the app that owns the document.
serverRevision number The revision at which the document was exported. This can be provided to the update method as the baseRevision for a modified document.
data nested object An object that contains the contents of the data model beginning with the root CollaborativeMap.

Within the data field, each type of object is represented with appropriate fields.

Collaborative Objects

All collaborative object types include some common fields:

name type description
type string One of: Map, List, EditableString, IndexReference or the name of a custom object
value nested object Contains the contents of the CollaborativeObject. Specifics vary by type.

The values of the collaborative objects are as follows:

CollaborativeMap: JSON Object with a key/value pair for each entry in the map.

CollaborativeList: JSON Array with an entry for each item in the list.

CollaborativeString: JSON String with the contents stored as text.

Custom object: JSON Object with a key/value pair for each collaborative field in the custom object.

IndexReference: JSON Object with following fields:

name type description
objectId string ID of the CollaborativeObject to which the reference points.
index number The index location to which the reference points.
canBeDeleted boolean True if the index reference can be deleted.
deleteMode enum One of: SHIFT_AFTER_DELETE, SHIFT_BEFORE_DELETE, SHIFT_TO_INVALID

JavaScript Objects

A JSON Object with key “json” whose value is the JSON-serialized version of the JavaScript Object.

Sample

This is a sample document exported from the Realtime Playground.

{
  "appId":"123465",
  "revision":"12",
  "data":{
    "id":"root",
    "type":"Map",
    "value":{
      "demo_map":{
        "id":"Erd0Cjkit0Mi",
        "type":"Map",
        "value":{
          "key3":{
            "json":"value 3"
          },
          "key2":{
            "json":"value 2"
          },
          "key1":{
            "json":"value 1"
          }
        }
      },
      "demo_list":{
        "id":"fElnUQSkt0Mg",
        "type":"List",
        "value":[
          {
            "json":"Cat"
          },
          {
            "json":"Dog"
          },
          {
            "json":"Sheep"
          },
          {
            "json":"Chicken"
          }
        ]
      },
      "demo_custom":{
        "id":"VtzpPnL3t0Mj",
        "type":"DemoMovie",
        "value":{
          "name":{
            "json":"Minority Report"
          },
          "rating":{
            "json":""
          },
          "director":{
            "json":"Steven Spielberg"
          },
          "notes":{
            "json":""
          }
        }
      },
      "demo_string":{
        "id":"GVD94hbct0Ma",
        "type":"EditableString",
        "value":"Edit Me!"
      },
      "demo_cursors":{
        "id":"XLzwGXP3t0Mi",
        "type":"Map",
        "value":{
          "7863c8169cbc4fa8":{
            "id":"YKhCjomXwea-",
            "type":"IndexReference",
            "value":{
              "objectId":"fElnUQSkt0Mg",
              "index":2,
              "canBeDeleted":true
            }
          }
        }
      }
    }
  }
}

Enviar comentarios sobre…