# productVariantCreate - admin-graphql - MUTATION
Version: 2024-07

## Description
Creates a product variant.

### Access Scopes
`write_products` access scope. Also: The user must have a permission to create a product variant.


## Arguments
* [input](/docs/api/admin-graphql/2024-07/input-objects/ProductVariantInput): ProductVariantInput! - The properties for the new product variant.


## Returns
* [product](/docs/api/admin-graphql/2024-07/objects/Product): Product The product associated with the variant.
* [productVariant](/docs/api/admin-graphql/2024-07/objects/ProductVariant): ProductVariant The successfully created variant.
* [userErrors](/docs/api/admin-graphql/2024-07/objects/UserError): UserError! The list of errors that occurred from executing the mutation.


## Examples
### Create a new metafield on a new product variant
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation createProductVariantMetafields($input: ProductVariantInput!) { productVariantCreate(input: $input) { productVariant { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }\",\n \"variables\": {\n    \"input\": {\n      \"metafields\": [\n        {\n          \"namespace\": \"my_field\",\n          \"key\": \"liner_material\",\n          \"type\": \"single_line_text_field\",\n          \"value\": \"Synthetic Leather\"\n        }\n      ],\n      \"productId\": \"gid://shopify/Product/108828309\"\n    }\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation createProductVariantMetafields($input: ProductVariantInput!) {\n      productVariantCreate(input: $input) {\n        productVariant {\n          id\n          metafields(first: 3) {\n            edges {\n              node {\n                id\n                namespace\n                key\n                value\n              }\n            }\n          }\n        }\n        userErrors {\n          message\n          field\n        }\n      }\n    }`,\n    \"variables\": {\n      \"input\": {\n        \"metafields\": [\n          {\n            \"namespace\": \"my_field\",\n            \"key\": \"liner_material\",\n            \"type\": \"single_line_text_field\",\n            \"value\": \"Synthetic Leather\"\n          }\n        ],\n        \"productId\": \"gid://shopify/Product/108828309\"\n      }\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation createProductVariantMetafields($input: ProductVariantInput!) {\n    productVariantCreate(input: $input) {\n      productVariant {\n        id\n        metafields(first: 3) {\n          edges {\n            node {\n              id\n              namespace\n              key\n              value\n            }\n          }\n        }\n      }\n      userErrors {\n        message\n        field\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"input\": {\n    \"metafields\": [{\"namespace\"=>\"my_field\", \"key\"=>\"liner_material\", \"type\"=>\"single_line_text_field\", \"value\"=>\"Synthetic Leather\"}],\n    \"productId\": \"gid://shopify/Product/108828309\"\n  }\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation createProductVariantMetafields($input: ProductVariantInput!) {\n    productVariantCreate(input: $input) {\n      productVariant {\n        id\n        metafields(first: 3) {\n          edges {\n            node {\n              id\n              namespace\n              key\n              value\n            }\n          }\n        }\n      }\n      userErrors {\n        message\n        field\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"input\": {\n        \"metafields\": [\n          {\n            \"namespace\": \"my_field\",\n            \"key\": \"liner_material\",\n            \"type\": \"single_line_text_field\",\n            \"value\": \"Synthetic Leather\"\n          }\n        ],\n        \"productId\": \"gid://shopify/Product/108828309\"\n      }\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation createProductVariantMetafields($input: ProductVariantInput!) {\n  productVariantCreate(input: $input) {\n    productVariant {\n      id\n      metafields(first: 3) {\n        edges {\n          node {\n            id\n            namespace\n            key\n            value\n          }\n        }\n      }\n    }\n    userErrors {\n      message\n      field\n    }\n  }\n}"
#### Graphql Input
{
  "input": {
    "metafields": [
      {
        "namespace": "my_field",
        "key": "liner_material",
        "type": "single_line_text_field",
        "value": "Synthetic Leather"
      }
    ],
    "productId": "gid://shopify/Product/108828309"
  }
}
#### Graphql Response
{
  "data": {
    "productVariantCreate": {
      "productVariant": {
        "id": "gid://shopify/ProductVariant/1070325086",
        "metafields": {
          "edges": [
            {
              "node": {
                "id": "gid://shopify/Metafield/1069229040",
                "namespace": "my_field",
                "key": "liner_material",
                "value": "Synthetic Leather"
              }
            }
          ]
        }
      },
      "userErrors": []
    }
  }
}

### Create a new product variant with media
Curl example: "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-07/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation CreateProductVariantWithMedia($input: ProductVariantInput!) { productVariantCreate(input: $input) { product { id } productVariant { id title media(first: 10) { nodes { id alt mediaContentType preview { status } } } } userErrors { field message } } }\",\n \"variables\": {\n    \"input\": {\n      \"productId\": \"gid://shopify/Product/108828309\",\n      \"options\": [\n        \"Yellow\"\n      ],\n      \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n    }\n  }\n}'\n"
Node example: "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n  data: {\n    \"query\": `mutation CreateProductVariantWithMedia($input: ProductVariantInput!) {\n      productVariantCreate(input: $input) {\n        product {\n          id\n        }\n        productVariant {\n          id\n          title\n          media(first: 10) {\n            nodes {\n              id\n              alt\n              mediaContentType\n              preview {\n                status\n              }\n            }\n          }\n        }\n        userErrors {\n          field\n          message\n        }\n      }\n    }`,\n    \"variables\": {\n      \"input\": {\n        \"productId\": \"gid://shopify/Product/108828309\",\n        \"options\": [\n          \"Yellow\"\n        ],\n        \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n      }\n    },\n  },\n});\n"
Ruby example: "session = ShopifyAPI::Auth::Session.new(\n  shop: \"your-development-store.myshopify.com\",\n  access_token: access_token\n)\nclient = ShopifyAPI::Clients::Graphql::Admin.new(\n  session: session\n)\n\nquery = <<~QUERY\n  mutation CreateProductVariantWithMedia($input: ProductVariantInput!) {\n    productVariantCreate(input: $input) {\n      product {\n        id\n      }\n      productVariant {\n        id\n        title\n        media(first: 10) {\n          nodes {\n            id\n            alt\n            mediaContentType\n            preview {\n              status\n            }\n          }\n        }\n      }\n      userErrors {\n        field\n        message\n      }\n    }\n  }\nQUERY\n\nvariables = {\n  \"input\": {\n    \"productId\": \"gid://shopify/Product/108828309\",\n    \"options\": [\"Yellow\"],\n    \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n  }\n}\n\nresponse = client.query(query: query, variables: variables)\n" 
Remix example: "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n  `#graphql\n  mutation CreateProductVariantWithMedia($input: ProductVariantInput!) {\n    productVariantCreate(input: $input) {\n      product {\n        id\n      }\n      productVariant {\n        id\n        title\n        media(first: 10) {\n          nodes {\n            id\n            alt\n            mediaContentType\n            preview {\n              status\n            }\n          }\n        }\n      }\n      userErrors {\n        field\n        message\n      }\n    }\n  }`,\n  {\n    variables: {\n      \"input\": {\n        \"productId\": \"gid://shopify/Product/108828309\",\n        \"options\": [\n          \"Yellow\"\n        ],\n        \"mediaId\": \"gid://shopify/MediaImage/1041834415\"\n      }\n    },\n  },\n);\n\nconst data = await response.json();\n"
Graphql query: "mutation CreateProductVariantWithMedia($input: ProductVariantInput!) {\n  productVariantCreate(input: $input) {\n    product {\n      id\n    }\n    productVariant {\n      id\n      title\n      media(first: 10) {\n        nodes {\n          id\n          alt\n          mediaContentType\n          preview {\n            status\n          }\n        }\n      }\n    }\n    userErrors {\n      field\n      message\n    }\n  }\n}"
#### Graphql Input
{
  "input": {
    "productId": "gid://shopify/Product/108828309",
    "options": [
      "Yellow"
    ],
    "mediaId": "gid://shopify/MediaImage/1041834415"
  }
}
#### Graphql Response
{
  "data": {
    "productVariantCreate": {
      "product": {
        "id": "gid://shopify/Product/108828309"
      },
      "productVariant": {
        "id": "gid://shopify/ProductVariant/1070325084",
        "title": "Yellow",
        "media": {
          "nodes": [
            {
              "id": "gid://shopify/ExternalVideo/1041834415",
              "alt": "This is a video",
              "mediaContentType": "EXTERNAL_VIDEO",
              "preview": {
                "status": "READY"
              }
            }
          ]
        }
      },
      "userErrors": []
    }
  }
}