Content Publisher app
You can build a content publishing app quickly using Canva's Content Publisher template, which is available through the @canva/cli(opens in a new tab or window) command-line interface (CLI).
The Content Publisher template is a starting point for implementing the Content Publisher intent, which enables users to publish Canva designs directly to external platforms like social media, blogs, or newsletters. The template provides a mock publishing flow with settings and preview UIs, allowing you to explore the user experience before integrating with your platform's APIs.
This article shows you how to install the Content Publisher template, run it locally, and customize it.
Step 1: Create a new app using the Content Publisher template
-
Install the Canva CLI(opens in a new tab or window) globally:
npm install -g @canva/cli@latestSHELL -
Log in to the Canva CLI. This command opens an access request page in your browser:
canva loginSHELL -
Click Allow to grant the Canva CLI permission to manage your Canva apps.
-
Use the following command to create a new app using the Content Publisher template:
canva apps create --template "content_publisher"SHELL -
The setup process guides you through the remaining settings:
- Choose the audience for your app.
- Enter a name for your app.
- Choose whether to initialize a git repository for your project.
- Choose whether your project should use npm to install its dependencies.
After the setup process has completed, the output lists the steps for running the new app. For example:
cd example-content-publisher-appnpm start
- Replace
example-content-publisher-appwith your app's name.
Step 2: Preview your app
You can now start the app preview to explore the UI.
-
In the root directory for your app, start the app preview with the following command:
npm startSHELLAfter the app starts, the
Development URL (Frontend)local address is shown in the output. -
In Your apps(opens in a new tab or window), select your app, then Code upload > App source > Development URL.
-
Under Code upload > App source > Development URL confirm that the
Development URL (Frontend)address matches the address shown in the Development URL field. -
Locate the Preview button at the top right of the page, and click it to open a new tab that loads the Canva editor.
-
Click Open if prompted. This message only appears when using an app for the first time.
Step 3: Understand the Content Publisher user experience
With the Content Publisher app running locally, you can explore the publishing flow. The template implements all 4 required functions of the Content Publisher intent:
- Settings UI: A form where users configure publishing options, such as entering a caption. The settings UI validates required fields and enables or disables the publish button accordingly.
- Preview UI: A mock social media post preview showing how the content will appear after publishing. This helps users visualize their post before committing.
- Output type configuration: Defines the "Feed Post" output type with image specifications, including aspect ratio constraints and file format requirements.
- Publish handler: A placeholder function that returns a mock success response. In production, this connects to your platform's APIs.
Test the Content Publisher app by entering a caption in the settings panel, observing the preview update, and clicking the publish button to see the mock response.
Step 4: Customize your app
Add additional settings fields
To add more configuration options to the settings UI:
-
Open the
src/intents/content_publisher/types.tsfile. -
Add new fields to the
PublishSettingsinterface:export interface PublishSettings {caption: string;visibility: "public" | "private";}TYPESCRIPT -
Open the
src/intents/content_publisher/settings_ui.tsxfile. -
Update the initial state and add new form controls for the additional fields.
-
Update the
validatePublishReffunction to validate the new fields.
Customize the preview appearance
To modify the preview to match your platform's design:
-
Open the
src/intents/content_publisher/post_preview.tsxfile. -
Modify the
PostPreviewcomponent to match your platform's visual style, including colors, layout, and branding elements. -
Update the
styles/preview_ui.cssfile to apply custom styles.
Configure output types
To modify the supported publishing formats:
-
Open the
src/intents/content_publisher/index.tsxfile. -
Modify the
getPublishConfigurationfunction to define your platform's supported formats:return {status: "completed",outputTypes: [{id: "story",displayName: intl.formatMessage({defaultMessage: "Story",description: "Label for story format",}),mediaSlots: [{id: "media",displayName: "Media",fileCount: { exact: 1 },accepts: {image: {format: "png",aspectRatio: { min: 9 / 16, max: 9 / 16 },},},},],},],};TSX
Step 5: Add user authentication
Most publishing platforms require user authentication to post content. You can use OAuth authentication to connect user accounts:
- Configure OAuth settings in the Developer Portal(opens in a new tab or window) for your app.
- Implement the OAuth flow to obtain access tokens for your platform.
- Store tokens securely and use them when making API calls in the
publishContentfunction.
For more information, see Authenticating users.
Step 6: Implement platform integration
To complete your content publishing app, replace the placeholder implementation with actual API calls:
-
Open the
src/intents/content_publisher/index.tsxfile. -
In the
publishContentfunction, add your platform's API integration:async function publishContent(request: PublishContentRequest,): Promise<PublishContentResponse> {// Parse the settings from publishRefconst settings = JSON.parse(request.publishRef);// Upload media to your platform// const uploadedMedia = await uploadToYourPlatform(request.outputMedia);// Create the post on your platform// const post = await createPost({// media: uploadedMedia,// caption: settings.caption,// });return {status: "completed",externalId: "your-platform-post-id",externalUrl: "https://your-platform.com/post/123",};}TSX -
Update the preview UI in
src/intents/content_publisher/preview_ui.tsxto fetch and display the authenticated user's profile information.
Next steps
- To dive deeper into building content publishing apps, explore the Content Publisher intent documentation.
- Review the Content Publisher design guidelines to ensure your app provides a great user experience.
- When your app is ready, you can submit it for review through the Developer Portal. For more information, see the guide on submitting apps.