Editing designs
Edit an existing design with the HTML API.
After a user creates a design, they may want to edit that design at a later point in time. To enable this, Canva provides your website with the ID of the design. You can use this ID to re-open a design in the Canva editor.
This part of the tutorial series explains how to open an existing design in the Canva editor.

Step 1: Get the ID of the design

You can get the ID of a design in the following ways:
  • Using an HTML input element.
  • Using JavaScript callback functions.
You can use whatever option is most convenient.

Option 1: Using an HTML input element

On the same page as the Canva Button, create an input element with a unique name attribute:
1
<input name="designId" />
Copied!
Add either (or both) of the following attributes to the Canva Button's button element:
  • data-on-design-open-input-design-id
  • data-on-design-publish-input-design-id
Then set these attributes to the value of the input element's name attribute:
1
<button
2
data-design-type="Poster"
3
data-on-design-open-input-design-id="designId"
4
data-on-design-publish-input-design-id="designId"
5
data-api-key="API KEY GOES HERE"
6
class="canva-design-button"
7
style="display: none;"
8
>Design with Canva</button
9
>
10
<script>
11
(function (c, a, n) {
12
var w = c.createElement(a),
13
s = c.getElementsByTagName(a)[0];
14
w.src = n;
15
s.parentNode.insertBefore(w, s);
16
})(document, "script", "https://sdk.canva.com/designbutton/v2/api.js");
17
</script>
Copied!
If the data-on-design-open-input-design-id attribute is defined, Canva inserts the ID of the design into the specified field when the user opens a design. This includes when creating a new design or editing an existing design.
If the data-on-design-publish-input-design-id attribute is defined, Canva inserts the ID of the design into the specified field when the user publishes their design.
When Canva inserts a value into the input element, save the ID for future use.

Option 2: Using JavaScript callback functions

On the same page as the Canva Button, create two JavaScript functions:
1
function onDesignOpen(opts) {
2
console.log(opts);
3
}
4
5
function onDesignPublish(opts) {
6
console.log(opts);
7
}
Copied!
Each function should accept a single argument. These functions receive the same parameters as the JavaScript API's onDesignOpen and onDesignPublish functions.
Add either (or both) of the following attributes to the Canva Button's button element:
  • data-on-design-open
  • data-on-design-publish
Then set these attributes to the names of the JavaScript functions:
1
<button
2
data-design-type="Poster"
3
data-on-design-open="onDesignOpen"
4
data-on-design-publish="onDesignPublish"
5
data-api-key="API KEY GOES HERE"
6
class="canva-design-button"
7
style="display: none;"
8
>Design with Canva</button
9
>
10
<script>
11
(function (c, a, n) {
12
var w = c.createElement(a),
13
s = c.getElementsByTagName(a)[0];
14
w.src = n;
15
s.parentNode.insertBefore(w, s);
16
})(document, "script", "https://sdk.canva.com/designbutton/v2/api.js");
17
</script>
Copied!
When a user opens a design, Canva calls the function specified in the data-on-design-open attribute. This includes when creating a new design or editing an existing design.
When a user publishes a design, Canva calls the function specified in the data-on-design-publish attribute.
You can access the ID of the design via the opts.designId parameter:
1
function onDesignOpen(opts) {
2
console.log(opts.designId);
3
}
4
5
function onDesignPublish(opts) {
6
console.log(opts.designId);
7
}
Copied!
When Canva calls these functions, save the ID for future use.
You can also use the data-on-design-publish attribute to Download a design.

Step 2: Open an existing design in the Canva editor

To open an existing design in the Canva editor, create a Canva Button with a data-design-id attribute:
1
<button
2
data-design-id="DESIGN ID GOES HERE"
3
data-api-key="API KEY GOES HERE"
4
class="canva-design-button"
5
style="display: none;"
6
>Edit design</button
7
>
8
<script>
9
(function (c, a, n) {
10
var w = c.createElement(a),
11
s = c.getElementsByTagName(a)[0];
12
w.src = n;
13
s.parentNode.insertBefore(w, s);
14
})(document, "script", "https://sdk.canva.com/designbutton/v2/api.js");
15
</script>
Copied!
The presence of the data-design-id attribute on the button element tells the Canva Button SDK that clicking this button should open an existing design. The value of the data-design-id attribute must be the ID of a design.
If the button element has a data-design-id attribute, it must not have a data-design-type attribute. These attributes are mutually exclusive.
Last modified 1mo ago