Working with product model
Sometimes you need to analyze or transform a design file. Customer's Canvas provides several ways to do this:
- Use the Design Atoms library either directly or via the editor.
- Manipulate the serialized design model.
- Use the RESTful Design Atoms API.
In this article, you will learn how you can manipulate print-product models of a design and work with surfaces, print areas, and mockups through HTTP requests. These endpoints are organized in the group DesignAtomsPrintProduct and allows you to both general CRUD operations on objects embedded in the design and such specific operations as combining multiple designs into one, inserting an external image into an empty design template, resizing an empty template, replacing text in elements, adding mockups, and more.
Using the API
This guide assumes that you are familiar with the principles of using the Customer's Canvas Hub API. If not, we recommend reviewing these articles first.
- Design Atoms API Reference - for an API overview and information about supported API Client libraries
- C# API Client - for a guide on integrating the C# API Client library to your .NET app
Before starting, ensure that your app has credentials to make API calls:
- In your tenant, navigate to Settings > External apps and register your app.
- In your app, implement the authentication as explained in the Authentication in Customer's Canvas Hub article.
Design Atoms API is a multi-tenant service. The tenantId must be correctly filled in the method's parameters. It must match the tenantId encoded in the token. If no tenantId is specified, it will be taken from the token.
Design Atoms API allows you to work with both public and private assets in a tenant. Therefore, the parameters of method calls include "ownerId" fields indicating the owner of an asset. For public assets, these fields are left unfilled. For private assets, they must be filled in.
C# API clients
To use a C# API client, it is necessary to set it up through a dependency injection mechanism. For .NET Core, it is a built-in dependency injection functionality, for .NET Framework we will use Autofac. You may use another IoC container if you prefer. For more details, refer to Setting Up API Clients.
To make successful API calls, it is necessary to authorize them. You can do so by passing an API key or a token received from BackOffice to the configuration. To learn possible ways to authorize a client, refer to the Authorization instructions.
There is a separate client for each section in the API Reference. To work with design models, you will need an interface IDesignAtomsPrintProductApiClient.
Working with surfaces
The model
A DesignSurfaceDto object represents a surface and defines its ID, its position in the array of surfaces, and its size.
{
"id": "string",
"name": "string",
"index": 0,
"size": {
"width": 0,
"height": 0
}
}
Methods
The official C# API Client provides the following methods, which are the endpoint wrappers.
GetDesignSurfaces(id): DesignSurfaceDto[]
Gets a list of design surfaces as a set of data models.
GET /api/atoms/v1/designs/{id}/print-product/surfaces
-> DesignSurfaceDto[]
DeleteDesignSurface(id, surfaceId): void
Deletes a surface from a design.
DELETE /api/atoms/v1/designs/{id}/print-product/surfaces/{surfaceId}
GetDesignSurfaceModel(id, surfaceId): string
Gets a serialized surface model containing all its components.
GET /api/atoms/v1/designs/{id}/print-product/surfaces/{surfaceId}/model
-> string
ReplaceDesignSurfaceModel(id, surfaceId, surfaceModel): string
Replaces the specified design surface with another surface transferred as a serialized model. At the same time, the IDs of all elements of the transferred surface are forcibly replaced with new values to prevent a situation where elements with the same ID appear in the design.
PUT /api/atoms/v1/designs/{id}/print-product/surfaces/{surfaceId}/model
string, string, string -> string
AddDesignSurfaceModel(id, surfaceIndex, model): string
Adds a new surface to an existing design. At the same time, this forces the IDs of all elements of the transferred surface to be replaced with new values to prevent a situation where elements with the same ID appear in the design.
POST /api/atoms/v1/designs/{id}/print-product/surfaces/model
string, int, string -> string