Creating content

A guide to using the `createContent` mutation to create content via the BaseCMS GraphQL API.

Requirements

You'll need the following information to create content via the API:

  • An API URL

  • A BASE instance URL

  • A Tenant Key

  • An active BASE user with permission to read and write data

If you're missing any of this information, please reach out to support@parameter1.com and we'd be happy to provide it!

Connecting to the API

Connect to the API using a the GraphQL client, programming library, or request utility of your choice. Make sure to send your tenant key along with your request in the x-tenant-key HTTP header. For a detailed example, review the Connecting to the API guide.

Authentication

To modify content, you must first authenticate to the BaseCMS GraphQL API using valid user credentials with access to read and write data. Once complete, send your authentication token along with your request in the authorization header (using the Bearer prefix). For a detailed example, review the Authenticating to the API segment of the Connecting to the API guide.

BASE instance access

In order to route to the correct environment, make sure you send your BASE instance URL along with your request in the x-base4-api-uri HTTP header. For a detailed example, review the Specifying your BASE instance segment of the Connecting to the API guide.

Creating a content item

There are three values required to create a content item:

  1. The content item's name

  2. The content item's type

  3. The content item's primary section

Name

This one's up to you!

Type

The type of content you want to create should correlate with the available options within BASE, and should semantically describe your content. For example, when creating a company or company-like content item, use the Company content type. For long-form text content, use the Article type. For shorter descriptions of current events, use the News or PressRelease type.

Ultimately, the choice is yours, but each content type will have fields specific to its use case.

Finding available content types

To see the available content types, review the ContentType enum within the GraphQL schema definition. You can find the latest version on the project's Github repository, or via introspection:

Viewing fields for a content type

You can see the available fields for each content type by looking them up in the schema:

The Content interface

A Content<Type> definition implements one or more content interfaces, the most basic of which is the Content interface. All Content<Type> definitions will implement this interface, meaning that these fields are available regardless of selected content type.

Other commonly used interfaces include Authorable (defining contact/contributor relationships), Addressable (defining location fields such as city, region, and postal code), and Contactable (defining contact fields, such as phone number and email address).

Primary Section

Finally, we need to know the "Primary Section" of the content item. Within the BASE ecosystem, all content must have a home when displayed on the website (the final fallback for which is, unsurprisingly, the "Home" website section). When a new BASE instance is provisioned, your selected website sections were made available, along with the Home section (and a few others, such as Authors or Contact Us).

Below, we'll query for our available website sections in order to determine the section ID to use with our query. Once we've identified which section we want our content to be housed under, we'll use this ID to tell BASE where to place the content item upon creation.

Putting it all together

Now that we have a name, a type, and a primary section ID, we can use the createContent mutation to create the content item via the GraphQL API.

The createContent mutation (and other related modifying mutations) require you to send your BASE instance URL along with the request in the x-base4-uri HTTP header.

The createContent mutation (and other related modifying mutations) require you to send your BASE instance URL along with the request in the x-base4-api-uri HTTP header.

Now that we've sent our mutation, BASE has returned the new content item -- and most importantly, its id field. We can now use that identifier to make changes to the content item, which we'll walk through in the next guide: Modifying content.

Last updated