Writing to ODK-X Sync Endpoint database

I have ODK-X Sync Endpoint fully installed and configured and have a form designed on a tablet and loaded to the server with a couple records. My use case for this is to create partial records in the Sync Endpoint database from another program (more specifically a php program that has read access to other databases the data is coming from), that will be synced to tablets by users and completed. I located a table called “__ODKTABLES__TABLE_TABLENAME” which has the records entered on the tablet and synced. Is this the only table I would need to write to? Is it possible for me to generate valid values for _URI,_ROW_ETAG and _DATA_ETAG_AT_MODIFICATION that will make the records act like they were created in ODK Survey?


I would advice against writing directly to the database and instead use the APIs we provide. Writing directly to the database has a high chance of producing undefined behavior. The Sync Endpoint API is documented at https://docs.opendatakit.org/odk-x/odk-2-sync-protocol/. We also provide a Java Client for the library, see https://github.com/opendatakit/sync-client.

For simple tasks such as bulk importing data, there is also a graphical tool available. See https://docs.opendatakit.org/odk-x/suitcase-intro/.

1 Like

Thank you for pointing me to the API. In general I’m more comfortable reading SQL than API definitions, but after I made sense of it, it turned out to be pretty easy. At first reading I thought it was only intended for building a full replacement client that maintains and synchronizes a full copy of the database, rather than just being able to add or modify an occasional row. For anyone else looking at it, the “/path/of/prefix” at the beginning of the documentation is currently “odktables” for Sync Endpoint 2.1.2 - I guessed that based on the nginx configuration file and it worked. If you are writing in PHP, there are good descriptions on stackoverflow of doing PUT/GET/etc. calls using curl, and including the http-basic-authentication required for Sync Endpoint. Also, jsonencode and jsondecode functions in PHP make JSON incredibly easy to work with - much better than XML in my opinion.

I would upgrade that to STRONGLY advise against writing directly to the database.