ZSK Web API

ZSK Web API

CreatePNG

POST

CreatePNG creates a TrueView PNG preview of text, of an existing design, or of both. Send it as an HTTP POST with a JSON body to StitchJob (see Overview) with "RequestType": "CreatePNG", "ServerVersion": 3 and a valid WebApiLicense (see ZSK Web API License). Key names are case-sensitive, and integer fields need JSON integers ("DistanceMM": 2, not 2.5).

Input

  • Text only: send Monograms and Needle, omit EmbroideryBase64.
  • Existing design only: send EmbroideryType and EmbroideryBase64, omit Monograms (or send an empty list). No Needle list is needed.
  • Design + text: send EmbroideryType, EmbroideryBase64, Monograms and Needle (with a TC or TBF design, "UseEmbroideryColors": 1 can replace Needle, see Colors). TextAlignment with a Mode places the text relative to the design (see TextAlignment to Design).

Text rules: without a design, every monogram needs a non-blank text; up to 9 monograms, one line each, 200 characters in total; FontSizeMM 5 to 50; FontFamily as listed by GetFontList (case-sensitive); UsedNeedle starts at 1. See Monograms.

EmbroideryType is required with every design and must be one of these values (case-sensitive):

EmbroideryTypeFileProcessing
TC.z00Used directly. From ServerVersion 3, an optional SeqAssignmentJson assigns its sequences to new needles and colors.
TBF.tbfUsed directly.
DST.dstConverted to TC with the needle assignment in SeqAssignmentJson (required).
DSZ.dszConverted to DST, then handled like DST input; the sequence indexes in SeqAssignmentJson refer to the converted DST.

For DST and DSZ input, SeqAssignmentJson is a JSON string holding NeedleAssignment (key k: 0-based index into UsedConeDefs, becomes needle k + 1; value: the 0-based DST color sequences in that color) and UsedConeDefs (ColorNumber as integer). See NeedleAssignment.

"EmbroideryType": "DST",
"EmbroideryBase64": "base64 encoded embroidery data",
"SeqAssignmentJson": "{\"NeedleAssignment\":{\"0\":[0,2],\"1\":[1]},\"UsedConeDefs\":[{\"R\":196,\"G\":30,\"B\":58,\"ColorNumber\":5566,\"ColorName\":\"radiant red\"},{\"R\":0,\"G\":0,\"B\":0,\"ColorNumber\":20,\"ColorName\":\"Black\"}]}"

For TC input (from ServerVersion 3), SeqAssignmentJson is optional and has the same format. Its sequence indexes are the 0-based positions in the GetNeedleSequence list of the design, every sequence must be assigned to exactly one cone, and the cone colors replace the Needle colors. See NeedleAssignment.

The preview is built from the same input as CreateTC, but without pull compensation (PullRel, PullAbs), so stitch details can differ slightly from a stitch file created from the same request. Rotation is never applied: the PNG always shows the unrotated layout.

Colors

  • Needle sets the colors by position (first entry = needle 1); each monogram uses the entry in its UsedNeedle, so with text Needle needs at least that many entries. Red, Green, Blue: integers 0 to 255; other fields: strings.
  • Entry n also recolors needle n of the design: with a design, send one entry per design needle and set UsedNeedle to the entry with the text color. Without Needle, a design keeps its colors (DST and DSZ input: the UsedConeDefs colors).
  • Only Red, Green, Blue and ColorName affect the preview; the other fields have no effect on the PNG.
  • With a TC or TBF design, "UseEmbroideryColors": 1 builds Needle from the design, replacing a sent list; UsedNeedle then selects an entry by position. See UseEmbroideryColors.
  • With TC input and SeqAssignmentJson (ServerVersion 3), the cone colors win: entry n of Needle is replaced by UsedConeDefs[n - 1], also for text with UsedNeedle n, and UseEmbroideryColors is ignored. Needle can then be omitted when every UsedNeedle refers to a cone.

Preview settings

  • TrueView sets how the threads are drawn: LineThickness, Brightness, LightingOn, LightingAngle, HideStitches, HideStitchesFrom. All values are strings holding integers; omitted keys keep their defaults. German keys are still accepted. See TrueView Parameter.
  • PngResolution: resolution in dpi (integer), default 254 (10 pixels per mm); values below 72 use 254. See Preview resolution.

Response

On success: HTTP 200 with a JobResponseType with Success true and:

  • RequestData: the PNG of the stitched area of design and text (RGBA with a transparent background, resolution stored in the file), Base64-encoded; it can be shown directly as data:image/png;base64, followed by RequestData.
  • Info: widthMm and heightMm (size of design and text in mm, not the image size; text only: widthMm is the width of the text block), numberOfStitches and numberOfCuts (thread cuts). The other fields are 0 or null.
  • NeedleColor: with a design, one entry per needle color of the preview (design and text) with NeedleNumber, Red, Green, Blue and ColorName; the other strings are empty. Text only: one entry per monogram (its UsedNeedle and that Needle entry).
  • NeedleSequence: with a design, the needle of each sequence of design and text in stitch order. Text only: the UsedNeedle of each monogram. With TC input and SeqAssignmentJson, a needle change is added after a stop where the cone changes; the stop then shows up as an extra entry with the previous needle.
  • Time: processing times. PreviewData stays empty, also with WithPreview; the PNG is in RequestData.

Info, NeedleColor, NeedleSequence and Time are JSON strings: parse each non-empty string a second time. Example for text only (formatted and shortened):

{
	"Info": "{ \"widthMm\": ..., \"heightMm\": ..., ..., \"numberOfStitches\": ..., \"numberOfCuts\": ..., ... }",
	"NeedleColor": "[ { \"NeedleNumber\": 1, \"Red\": 196, \"Green\": 30, \"Blue\": 58, \"ColorName\": \"radiant red\", ... } ]",
	"NeedleSequence": "[ 1 ]",
	"PreviewData": "",
	"RequestData": "base64 encoded PNG data",
	"Success": true,
	"Time": "{ ... }"
}

On error, Success is false and RequestData holds the error message.

Errors

HTTPRequestDataCause
200Error: unknown command!RequestType is not exactly CreatePNG.
400No licence token found. / Invalid licence token.WebApiLicense is missing, empty or rejected.
400Only one line of text per monogram ... / A maximum of 9 lines ... / The text length is longer ...More than one Text entry, more than 9 monograms, or more than 200 characters.
400Invalid needle color listText without a Needle list, or too few Needle entries for the highest UsedNeedle.
400Invalid monogram text. Found empty textNo design, and Monograms is missing or empty or a monogram text is blank.
400Invalid font size. ... / Invalid font name(s). ... / The text contains not supported character(s): ...FontSizeMM outside 5 to 50, FontFamily not listed by GetFontList, or characters the font does not support.
400embroideryData.Length == 0DST or DSZ input without a valid SeqAssignmentJson.
400ApplyNasTC: ... (for example ApplyNasTC: Sequence 1 is not assigned to a cone)TC input: SeqAssignmentJson does not fit the design, or the design has K-head (Moos/Kettel) needles. See NeedleAssignment.
500Error messageUnexpected error, for example invalid Base64 in EmbroideryBase64.
503Error messageThe preview could not be created; retry later.

Parameters

Parameter Type Description Required
RequestType string Must be exactly "CreatePNG" (case-sensitive). Yes
ServerVersion int API version. Send 3. Yes
WebApiLicense string License key, see ZSK Web API License. Yes
EmbroideryType string "TC" (Z00), "TBF", "DST" or "DSZ" (case-sensitive): type of the design in EmbroideryBase64. Required with every design; DST and DSZ also need SeqAssignmentJson. TC can use it from ServerVersion 3. No
EmbroideryBase64 string Base64-encoded design file. Required for design only and design + text; omit it for text only. No
Monograms array Text lines: up to 9 monograms, one line each, 200 characters in total, non-blank without a design; UsedNeedle starts at 1 (see Monograms). Omit it or send an empty list for design only. PullRel and PullAbs are not applied to the preview. No
Needle array Needle colors by position (first entry = needle 1), required with text and covering the highest UsedNeedle, unless UseEmbroideryColors is 1 with a TC or TBF design. Red, Green, Blue: int 0..255, the other fields strings; only Red, Green, Blue and ColorName affect the preview, and entry n also recolors needle n of the design in the preview. No
UseEmbroideryColors int 1 = build the Needle list from a TC or TBF design, replacing a Needle list in the request; UsedNeedle then selects an entry by position. No effect for text only or DST/DSZ input. Ignored for TC input with SeqAssignmentJson (ServerVersion 3). No
SeqAssignmentJson string Needle assignment (NeedleAssignment, UsedConeDefs) as a JSON string, required for DST and DSZ input, optional for TC input from ServerVersion 3 (see NeedleAssignment). No
TextAlignment object Places the text relative to the design when Mode is set (design + text only): Mode (Top, Bottom, Left, Right, Manual; not case-sensitive), Alignment, DistanceMM (int), and xPosMM/yPosMM for Mode Manual (see TextAlignment to Design). No
LineSpacing array Extra spacing in mm between consecutive text lines, one double per gap, e.g. [5.0]; used with two or more monograms (see Linespacing). No
Rotation int No effect on the preview: the PNG always shows the unrotated layout (see Rotation). No
TrueView object Thread rendering; values are strings holding integers (LineThickness, Brightness, LightingOn, LightingAngle, HideStitches, HideStitchesFrom); omitted keys keep their defaults; German keys are still accepted (see TrueView Parameter). No
PngResolution int Resolution of the PNG in dpi, default 254 (10 pixels per mm); values below 72 use 254 (see Preview resolution). No

Example

{
	"RequestType": "CreatePNG",
	"Monograms": [
		{
			"Text": [
				"Heart"
			],
			"FontFamily": "Arial",
			"FontSizeMM": 10.0,
			"UsedNeedle": 1,
			"TextStitchParameter": "Premium"
		}
	],
	"Needle": [
		{
			"Red": 196,
			"Green": 30,
			"Blue": 58,
			"ColorName": "radiant red"
		}
	],
	"TrueView": {
		"LineThickness": "300",
		"Brightness": "100",
		"LightingOn": "1",
		"LightingAngle": "90",
		"HideStitches": "1",
		"HideStitchesFrom": "127"
	},
	"PngResolution": 254,
	"ServerVersion": 3,
	"WebApiLicense": "xxxxx-xxxxx-xxxxx-xxxxx-xxxxx"
}