Show the product catalog
The product catalog is a ready-made landing page that partners can embed in their website. You can use the product catalog get an integration up and running as quickly as possible.
This part of the tutorial explains how to embed the product catalog in a web page.
An integration doesn't have to use Canva's product catalog—you can create a custom landing page—but this is beyond the scope of this tutorial.

Step 1: Create a container

The Partnership SDK needs a HTMLElement for rendering the product catalog and editor. To provide this element, create a div element between the body tags of the index.ejs file:
1
<div id="container"></div>
Copied!
Then pass this element into the initialize method via the container property:
1
(async () => {
2
const api = await Canva.Partnership.initialize({
3
apiKey: "<%= partnerApiKey %>",
4
container: document.getElementById("container"),
5
});
6
})();
Copied!

Step 2: Call the showCatalog method

The showCatalog method renders the product catalog in the container element:
1
(async () => {
2
const api = await Canva.Partnership.initialize({
3
apiKey: "<%= partnerApiKey %>",
4
container: document.getElementById("container"),
5
});
6
7
api.showCatalog({});
8
})();
Copied!
This method expects an object as its only argument. For the time being, pass through an empty object.
If you refresh the page, the SDK renders the product catalog in an iframe.

Step 3: Fix the container's height and margins

By default, the iframe that contains the product catalog doesn't extend to the full width and height of the page.
To fix this, add the following styles to the page:
1
<style type="text/css">
2
body,
3
html {
4
margin: 0;
5
}
6
7
#container {
8
height: 100vh;
9
}
10
</style>
Copied!
These styles extend the catalog's iframe to the edges of the viewport.
Some partners also choose to render a header at the top of the page, before the iframe.

Step 4: Select a product or template

If you select a product or template, nothing happens.
This is because you need to pass a function to the showCatalog method that opens the editor. For that to be possible though, you must first Calculate an autoAuthToken.

Example

src/views/index.ejs

1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="UTF-8" />
5
<meta
6
name="viewport"
7
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover"
8
/>
9
<title>Print Partnership Example</title>
10
<script src="https://sdk.canva.com/partnership.js"></script>
11
<style type="text/css">
12
body,
13
html {
14
margin: 0;
15
}
16
17
#container {
18
height: 100vh;
19
}
20
</style>
21
</head>
22
<body>
23
<div id="container"></div>
24
<script type="text/javascript">
25
(async () => {
26
const api = await Canva.Partnership.initialize({
27
apiKey: "<%= partnerApiKey %>",
28
container: document.getElementById("container"),
29
});
30
31
api.showCatalog({});
32
})();
33
</script>
34
</body>
35
</html>
Copied!
Last modified 3mo ago