variants

variants.find

Returns the variants that meet the given conditions.

JS
CR.api('commerce.variants.find', request, function(response) { … });
HTTP
POST /open2b/api/v3/commerce.variants.find

request

{
  "conditions" : { // returns only the variants …
    "ids" : [ 81, … ]  // … with these identifiers - int(1…)
  },
  "language" : "en", // language ( ISO code ) of the texts to return - string(2)
  "fields" : [ "id", "code", … ], // fields to return - string
  "order" : [ "name" ], // sort order of returned variants, can contain "id", "-id", "code", "-code", "name" and "-name" - string
  "limit" : 10, // maximum number of variants to return - int(1…100)
  "first" : 0 // index of the first variant to return - int(0…)
}

response

{
  "status" : "ok",
  "variants" : [ {
    "id" : 81, // identifier - int(1…)
    "code" : "RED", // code - string(1…32)
    "name" : { // name - string(2) -> string(0…60)
      "en" : "Red",
      "it" : "Rosso"
    },
    "showName" : true // indicates if the name should be displayed
  }, … ]
}

variants.get

Returns a variant given its identifier.

JS
CR.api('commerce.variants.get', request, function(response) { … });
HTTP
POST /open2b/api/v3/commerce.variants.get

request

{
  "id" : 81, // identifier of the variant (required) - int(1…)
  "language" : "en", // language ( ISO code ) of the texts to return - string(2)
  "fields" : [ "id", "code", … ]  // fields to return - string
}

response

{
  "status" : "ok",
  "variant" : { // (can be null)
    "id" : 81, // identifier - int(1…)
    "code" : "RED", // code - string(1…32)
    "name" : { // name - string(2) -> string(0…60)
      "en" : "Red",
      "it" : "Rosso"
    },
    "showName" : true // indicates if the name should be displayed
  }
}

variants.count

Number of variants that meet the given conditions.

JS
CR.api('commerce.variants.count', request, function(response) { … });
HTTP
POST /open2b/api/v3/commerce.variants.count

request

{
  "conditions" : { // counts only the variants …
    "ids" : [ 81, … ]  // … with these identifiers - int(1…)
  }
}

response

{
  "status" : "ok",
  "count" : 89 // number of variants - int(0…)
}

variants.create

Creates a new variant.

JS
CR.api('commerce.variants.create', request, function(response) { … });
HTTP
POST /open2b/api/v3/commerce.variants.create

request

{
  "variant" : {
    "code" : "SHIRT COLOR", // code (required) - string(1…32)
    "name" : { // name - string(2) -> string(0…60)
      "en" : "color",
      "it" : "Colore"
    },    
    "showName" : true // indicates if the name should be displayed
  },
}

response

{
  "status" : "ok",
  "id" : 81 // identifier of the new variant - int(1…)
}

variants.update

Updates a variant. Any fields left out of the request will remain unchanged.

JS
CR.api('commerce.variants.update', request, function(response) { … });
HTTP
POST /open2b/api/v3/commerce.variants.update

request

{
  "id" : 43, // identifiers of the variants to update (required) - int(1…)
  "variant" : { // variant's fields to update (required)
    "code" : "SHIRT COLOR", // code - string(1…32)
    "name" : { // name - string(2) -> string(0…60)
      "en" : "color",
      "it" : "Colore"
    },
    "showName" : true // indicates if the name should be displayed
  }
}

response

{
  "status" : "ok"
}

Errors

field Type Description
id NotFound Variant <id> does not exist

variants.delete

Deletes one or more variants.

JS
CR.api('commerce.variants.delete', request, function(response) { … });
HTTP
POST /open2b/api/v3/commerce.variants.delete

request

{
  "ids" : [ 81, 12, 33, … ]  // identifiers of the variants to delete (required) - int(1…)
}

response

{
  "status" : "ok"
}