Your application’s workflow may require the creation of objects in the destination before syncing data to them.

Rather than asking your customers to prepare a table in their database or a tab in their Google Sheets, Census provides instrumentation to create these objects via API, thereby eliminating any manual steps from your customer.

Doing so requires 2 simple steps:

1

List Destination Object Types

To create an object in a destination, you first need to know what types of objects are available in the destination. You can list the object types available in a destination using the following API:

curl --request GET \
  --url https://app.getcensus.com/api/v1/connectors/{service_name}/object_types \
  --header 'Authorization: Bearer <your API key>'

There are 2 ways to get the available object types.

  1. Get destination object types by your destination ID.
  2. Get destination object types by the name of the destination type.

Both of these return the same result. The former requires the ID of the connection in Census, while the latter only requires the service name “google_sheets”.

The response will look something like

  {
    ...
    "data": [
      {
        "type": "Sheet",
        "object_attributes": [
          {
              "key": "spreadsheetName",
              "label": "Spreadsheet Name",
              "type": "string",
              "required": false,
              "hint": "Either spreadsheetName or spreadsheetId is required"
          },
          {
              "key": "spreadsheetId",
              "label": "Spreadsheet Id",
              "type": "string",
              "required": false,
              "hint": "Either spreadsheetName or spreadsheetId is required"
          },
          {
              "key": "title",
              "label": "Title",
              "type": "string",
              "required": true
          },
        ],
        "field_attributes": [
          {
              "key": "name",
              "label": "Name",
              "type": "string",
              "required": true
          },
          {
              "key": "type",
              "label": "Type",
              "type": "string",
              "required": true,
              "possible_values": [
                  "Bool",
                  "String",
                  "Double"
              ]
          }
        ]
      }
    ]
  }
2

Create Object in Destination

Using the response from the previous step, you can construct the API call to create a new object in the destination.

The Create a new destination object API is provided to accomplish this. An example API call may look like this:

curl --request POST \
  --url https://app.getcensus.com/api/v1/destinations/{destination_id}/objects \
  --header 'Authorization: Bearer <your API key>' \
  --body '{
    "object_type": "Sheet",
    "object_attributes": {
      "spreadsheetId": "12jfdi8fj29ffj29dwfsas",
      "title"
    }
    "fields": [{"name": "Company", "type": "String"}]
  }'