New Vertabelo Feature: Document-Oriented Vertabelo API

Find out how to use the new Vertabelo Public API to access data models, SQL scripts, and more.

Updated on: November 17, 2023

One of the signs of a decent SaaS solution is its public API. A good API helps users to incorporate some automation into an application.

Based on our experience in using other SaaS services, we have introduced a more document-oriented version of our public API. In this article, we will demonstrate how to use Vertabelo API to fetch a list of documents (models), SQL scripts, and data models in various formats.

Why do we call our API document-oriented? We believe that users should easily access their documents (models, SQL scripts) through the API, simply by copying its URL.

  • Generating a Token
  • Document Identification
  • Accessing Data
    • Download a Document Tree
    • Download a Physical Data Model as XML
    • Download a Physical Data Model as an SQL Script
    • Download a Logical Data Model as XML
    • Download an SQL Script
    • Download a Migration Script
  • Managing Document (Model) Sharing
    • List users with document sharing
    • Send invitations to other team members
    • Cancel document sharing
  • Import a Physical Data Model as XML
    • Importing the physical model
    • Importing the logical model
  • Summary

Generating a Token

First of all, you have to enable access to the API. You’ll need to have at least an individual account or be a member of a company plan to do this.

  1. Go to the My profile page.

Document-Oriented Vertabelo API

2. In the left-hand menu, click on Settings.

Document-Oriented Vertabelo API

3. Click on Enable API Access.

Document-Oriented Vertabelo API

4. You’ll get a generated API token. This token will be used to identify you when you connect to the Vertabelo API.

Document-Oriented Vertabelo API

Note: You may also disable API access here. You can enable it again to get a new token.

Document Identification

All documents are identified by their URL. The document list is identified by the URL https://datamodeler.redgate-platform.com/drive, while each model has a unique URL; you can simply copy these as needed. Please see the images below.

Document-Oriented Vertabelo API

The document tree URL

Document-Oriented Vertabelo API

The URL of the physical model. The unique identifier of the model is “WCs…”

Accessing Data

Vertabelo’s document-oriented API functionality allows users to easily fetch:

  1. Lists of models and SQL scripts as a document tree in the JSON format.
  2. A physical data model as an XML file or a corresponding SQL result.
  3. A logical data model as an XML file.
  4. An SQL script.
  5. A migration script.

Examples

All the following examples use the curl tool. We assumed there is a “$TOKEN” variable available, which stores the public token generated as described in an earlier section of this article. A “:” character in the user parameter (-u option) is intended.

You can use the following command to declare the “$TOKEN” variable:

Download a Document Tree

To fetch a document tree, we need to make a GET HTTPS request to https://datamodeler.redgate-platform.com/drive with the following HTTP headers:

  1. An accept header with a JSON mime type: Accept: application/json
  2. An authorization header with a username equal to $TOKEN and an empty password, in the following format: Authorization: Basic (base64($TOKEN:))

Here is the corresponding curl example:

The result is a JSON file with a list of the documents (logical and physical models, SQL scripts to which you have access) in your Redgate Data Modeler account. Please note that the link property is a valid document URL and can be used for further requests.

Download a Physical Data Model as XML

Our API allows users to download their physical models as XML files. Downloading a model follows the same pattern as the document tree example. It is a GET HTTP request to the URL of the model with the following parameters:

  1. An accept header with an XML mime type: Accept: text/xml
  2. An authorization header with a username equal to $TOKEN and an empty password, in the following format: Authorization: Basic (base64($TOKEN:))

The corresponding curl example:

In the above example, a physical model is saved in the XML format with the name model.xml.

Download a Physical Data Model as an SQL Script

Users can also download SQL scripts generated from their models. To generate an SQL script through the API please, change the header in the previous example to Accept: text/sql

The corresponding curl example:

The above example saves the DDL script generated from the physical model as the model.sql text file.

Download a Logical Data Model as XML

Logical models can be also downloaded from the Redgate Data Modeler API. Downloading a logical data model is almost exactly the same as downloading a physical model. The only difference is a different model URL pattern: https://datamodeler.redgate-platform.com/logical/model/...

The corresponding curl example:

,

In the above example, the logical model is saved in the XML format with the name logical-model.xml.

Download an SQL Script

Redgate Data Modeler allows users to store and edit their models in the SQL format. To fetch an SQL script, follow the previous patterns. The header Accept: text/sql is expected.

Here is the corresponding curl example:

The above example stores an SQL script as the scripts.sql text file.

Download a Migration Script

In Redgate Data Modeler, you can generate migration scripts. This makes it easy to change versions of a database structure. The migration script allows us to choose two versions of a model and generate an SQL script that transforms the model from one version to the other. The script may perform different SQL operations, such as creating new tables, renaming or adding new columns, and creating indexes. We may generate the migration scripts manually using the Redgate Data Modeler web application, but it is also possible to create them using API.

To do that, we need to prepare the request in JSON format:

Here, from_identifier and to_identifier need to be replaced by the source and target identifiers of the physical model. We can obtain them from the URLs. We also need to choose the source and target model versions. We need version tags for that – see how to tag a version of your data model here. Then, simply put the correct version tag as from_tag and to_tag in the JSON. If you wish to migrate from/to the latest version, just use an empty string: "".

Your final JSON should resemble something like this:

When the JSON is ready, save it as a migrate.json file.

Now, you can query the API. Here is the corresponding curl example:

The command above stores an SQL script as a text file named migration-script.sql.

Managing Document (Model) Sharing

The API also allows you to see which team members the document (model, SQL script) has been shared with. You can also send invitations to other team members, change the document permission type, and cancel sharing.

All the API methods described below require:

  1. An authorization header with a username equal to $TOKEN and an empty password in the format Authorization: basic (base64($TOKEN:))
  2. An accept header with a JSON mime type: Accept: application/json
  3. A content type header with a JSON mime type: Accept: application/json

List users with document sharing

To see users you have shared the document with, send a HTTP GET request to the URL /api/v2/share/users/$MODEL_ID.

Related curl example:

The sample response looks like the following:

Send invitations to other team members

To send a document invitation to another user, send a HTTP POST request to the URL /api/v2/share/invite/$MODEL_ID with the content (BODY):

Related curl example:

As a response, the server will return an “ok” message (in case of correct execution) or an error message (in case of incorrect execution).

Cancel document sharing

To cancel sharing, send a HTTP POST request to the URL /api/v2/share/delete/$MODEL_ID with the content (BODY):

Related curl example:

As a response, the server will return an “ok” message (in case of correct execution) or an error message.

Import a Physical Data Model as XML

The API allows you to import the model as an XML file, either as a completely new document or to an existing document. In the latter case, you can overwrite existing data (using the overwrite option) or add new objects to those already existing in the document (using the add option).

These API functions are equivalent to user interface functions: “My Redgate Data Modeler -> Create new document” and “Import -> Import from XML”.
Import can apply to both physical and logical models.

All the API methods described below require:

  1. An authorization header with a username equal to $TOKEN and an empty password in the format Authorization: basic (base64($TOKEN:))
  2. An accept header with a JSON mime type: Accept: application/json
  3. A content type header with a JSON mime type: Accept: text/xml

Importing the physical model

To import a physical model from an XML file as a new document, send an HTTP POST request to the URL: /api/v2/model/new with the XML file as content (body).
Related curl example:

As a response, the server will return an “ok” status and the ID of the created document (in case of correct execution) or an error message (in case of incorrect execution).

In the example above, a new document will be created in the root folder and given a default name. To have the document created in a different folder and with a name in the API request, the folderId and name parameters should be added to the URL.

Related curl example:

To import a physical model from an XML file to an existing document by overwriting its content, send an HTTP POST request to the URL: /api/v2/model/overwrite/$MODEL_ID with the XML file as content (body).

Related curl example:

To import a physical model from an XML file by adding new objects to an existing document, send an HTTP POST request to the URL: /api/v2/model/add/$MODEL_ID with the XML file as content (body).

Related curl example:

In both of the above scenarios, the server will return an “ok” status (in case of correct execution) or an error message (in case of incorrect execution).

Importing the logical model

The import of the logical model is similar to the logical one, only the service addresses differ.

To import a logical model from an XML file as a new document, send an HTTP POST request to the URL: /api/v2/logical/model/new with the XML file as content (body).

Related curl example:

As a response, the server will return an “ok” status and ID of the created document (in case of correct execution) or an error message (in case of incorrect execution).

In the example above, a new document will be created in the root folder and given a default name. To create the document in a different folder and include a name in the API request, add the folderId and name parameters to the URL.

Related curl example:

To import a logical model from an XML file to an existing document by overwriting the document content, send an HTTP POST request to the URL: /api/v2/logical/model/overwrite/$MODEL_ID with the XML file as content (body).

Related curl example:

To import a logical model from an XML file to an existing document by adding new objects to its content, send an HTTP POST request to the URL: /api/v2/logical/model/add/$MODEL_ID with the XML file as content (body).

Related curl example:

In both of the above scenarios, the server will return an “ok” status (in case of correct execution) or an error message (in case of incorrect execution).

Summary

As you can see, accessing the Redgate Data Modeler API is as simple as writing an HTTP request.

Tools in this post

Redgate Data Modeler

Design, update, and manage database schemas

Find out more