Batch

The Batch endpoint is an asynchronous process that handles multiple actions simultaneously, reducing the number of requests that need to be sent. Instead of calling the API multiple times, you just need one Batch call to do this. The supported actions are:

These are a couple of examples where you may want to use a Batch call:

  • You need to generate one pattern with multiple measurement profiles.
  • You need to export one draft to multiple file types (DXF, PLT, PDF).

Please check the example flow below. As you can see, instead of executing three calls, a single Batch call is made.

Create batch

API Request

POST https://api.bespokify.com/v2/batches

Request Parameters

Parameter Type Required Description
callbackUrl string no The URL that our server will send the response data to. See: Callback URL
definitions object no Contains the Nesting, Scaling, and/or Export configurations.
actions object yes Contains a series of items where the key is the action id and the value is an action object.

TIP

  • action id is a custom ID you assign to that action. You can reuse this ID in next action through the $ref pointer.
  • Batch calls support $ref pointers. See: JSON Schema

Request parameters for the action object

Parameter Description
type Possible values: predictBody, predictScan, draft, export
body Request data of action. This is the same data that is sent if you were making individual Prediction, Draft, or Export calls.

TIP

When an action finishes, it means its corresponding resource was created. The resource's URL will then be included into the resources field of the Get Batch response.

  "resources": {
    "p1": {
      "$ref": "https://api.bespokify.com/v2/predictions/d19bbf92-0c5d-4fd7-8c7a-41d002d8bf88"
    }
  }

You can use this resource elsewhere by using the $ref pointer.

Example of a Predict Body action

{
  "actions": {
    "p1": {
      "type": "predictBody",
      "body": {
        "gender": "female",
        "measurements": {
          "fbHeight": 175,
          "fbWeight": 60
        }
      }
    }
  }
}

Example of a Predict Scan action

{
  "actions": {
    "p1": {
      "type": "predictScan",
      "body": {
        "source": "scanSource",
        "content": {
          "gender": "male",
          "scanHeight": 185,
          "scanWeight": 65
        }
      }
    }
  }
}

Example of a Draft action

This example uses $ref to refer to the measurements of the p1 resource in resources field.

{
  "actions": {
    "d1": {
      "type": "draft",
      "body": {
        "patternId": 397,
        "measurementType": "body",
        "metadata": {
          "customer": "John Doe",
          "cutDate": "02/07/18"
        },
        "seams": {
          "armhole": 0.5,
          "attachment": 1,
          "collar": 0.6
        },
        "options": {
          "bodyLengthAdj": 1,
          "collar": "regular",
          "pocket": "leftBreast"
        },
        "bodyShapes": {
          "posture": "regular",
          "shoulderSlope": "regular"
        },
        "measurements": {
          "$ref": "#/resources/p1/measurements"
        }
      }
    }
  }
}

Example of an Export action

This uses $ref to refer to the nestConfig in the definitions field.

{
  "actions": {
    "e1": {
      "type": "export",
      "body": {
        "draftId": {
          "$ref": "#/resources/d1/id"
        },
        "fileType": "dxf",
        "config": {
          "singleInstance": true,
          "materialGroup": false,
          "singleFile": true
        },
        "nesting": {
          "$ref": "#/definitions/nestConfig"
        }
      }
    }
  }
}

Example Request

{
  "callbackUrl": "https://bespokify.com/callbackUrl",
  "definitions": {
    "nestConfig": {
      "sheetWidth": 140,
      "preNestRotation": 45,
      "partRotation": null,
      "partMargin": 1,
      "sheetLength": 30000,
      "sheetEdgeMargin": 1
    }
  },
  "actions": {
    "p1": {
      "type": "predictBody",
      "body": {
        "gender": "female",
        "measurements": {
          "fbHeight": 175,
          "fbWeight": 60
        }
      }
    },
    "d1": {
      "type": "draft",
      "body": {
        "patternId": 397,
        "measurementType": "body",
        "metadata": {
          "customer": "John Doe",
          "cutDate": "02/07/18"
        },
        "seams": {
          "armhole": 0.5,
          "attachment": 1,
          "collar": 0.6
        },
        "options": {
          "bodyLengthAdj": 1,
          "collar": "regular",
          "pocket": "leftBreast"
        },
        "bodyShapes": {
          "posture": "regular",
          "shoulderSlope": "regular"
        },
        "measurements": {
          "$ref": "#/resources/p1/measurements"
        }
      }
    },
    "e1": {
      "type": "export",
      "body": {
        "draftId": {
          "$ref": "#/resources/d1/id"
        },
        "fileType": "dxf",
        "config": {
          "singleInstance": true,
          "materialGroup": false,
          "singleFile": true
        },
        "nesting": {
          "$ref": "#/definitions/nestConfig"
        }
      }
    }
  }
}

Example Response

{
  "id": "e02bc2c6-ff09-4f71-9b31-062f5ef7e751",
  "jobUrl": "https://api.bespokify.com/v2/jobs/12908488-3926-493d-a2b4-81e9b11df378"
}

You can monitor the status of this job using the jobUrl.

Get single batch

API Request

GET https://api.bespokify.com/v2/batches/{id}

Request Parameters

Parameter Type Required Description
id string yes The ID of the batch to retrieve.

Example Response

{
  "id": "e02bc2c6-ff09-4f71-9b31-062f5ef7e751",
  "createdAt": "2018-08-24T09:41:21.393Z",
  "createdBy": "94a6c3b9-fd26-45cc-884c-43de08fab93c",
  "status": "completed",
  "definitions": {
    "nestConfig": {
      "sheetWidth": 140,
      "preNestRotation": 45,
      "partRotation": null,
      "partMargin": 1,
      "sheetLength": 30000,
      "sheetEdgeMargin": 1
    }
  },
  "actions": {
    "p1": {
      "type": "predictBody",
      "body": {
        "gender": "female",
        "measurements": {
          "fbHeight": 175,
          "fbWeight": 60
        }
      }
    },
    "d1": {
      "type": "draft",
      "body": {
        "patternId": 397,
        "measurementType": "body",
        "metadata": {
          "customer": "John Doe",
          "cutDate": "02/07/18"
        },
        "seams": {
          "armhole": 0.5,
          "attachment": 1,
          "collar": 0.6
        },
        "options": {
          "bodyLengthAdj": 1,
          "collar": "regular",
          "pocket": "leftBreast"
        },
        "bodyShapes": {
          "posture": "regular",
          "shoulderSlope": "regular"
        },
        "measurements": {
          "$ref": "#/resources/p1/measurements"
        }
      }
    },
    "e1": {
      "type": "export",
      "body": {
        "draftId": {
          "$ref": "#/resources/d1/id"
        },
        "fileType": "dxf",
        "config": {
          "singleInstance": true,
          "materialGroup": false,
          "singleFile": true
        },
        "nesting": {
          "$ref": "#/definitions/nestConfig"
        }
      }
    }
  },
  "resources": {
    "e1": {
      "$ref": "https://api.bespokify.com/v2/exports/46e3e1d3-ce27-489b-9342-f16cccf69432"
    },
    "d1": {
      "$ref": "https://api.bespokify.com/v2/drafts/9310e8c3-4731-4063-bb0f-893ae96cf37e"
    },
    "p1": {
      "$ref": "https://api.bespokify.com/v2/predictions/d19bbf92-0c5d-4fd7-8c7a-41d002d8bf88"
    }
  }
}