gift Card Createmutation
mutation
2024-10latest
Requires write
access scope. Also: User needs gift_cards permission.
Create a gift card.
Arguments
The input fields to create a gift card.
Was this section helpful?
GiftCardCreatePayload returns
The created gift card.
The created gift card's code.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Code examples for MUTATION: giftCardCreate
Query Reference for MUTATION: giftCardCreate
"mutation giftCardCreate($input: GiftCardCreateInput!) {\n giftCardCreate(input: $input) {\n giftCard {\n # GiftCard fields\n }\n giftCardCode\n userErrors {\n field\n message\n }\n }\n}"
Input Reference for MUTATION: giftCardCreate
"{\n \"input\": {\n \"code\": \"<your-code>\",\n \"customerId\": \"gid://shopify/<objectName>/10079785100\",\n \"expiresOn\": \"2019-07-16\",\n \"initialValue\": \"29.99\",\n \"note\": \"<your-note>\",\n \"recipientAttributes\": {\n \"id\": \"gid://shopify/<objectName>/10079785100\",\n \"message\": \"<your-message>\",\n \"preferredName\": \"<your-preferredName>\",\n \"sendNotificationAt\": \"2019-09-07T15:50:00Z\"\n },\n \"templateSuffix\": \"<your-templateSuffix>\"\n }\n}"
Schema Reference for MUTATION: giftCardCreate
"input GiftCardCreateInput {\n code: String\n customerId: ID\n expiresOn: Date\n initialValue: Decimal!\n note: String\n recipientAttributes: GiftCardRecipientInput\n templateSuffix: String\n}\n\ninput GiftCardRecipientInput {\n id: ID!\n message: String\n preferredName: String\n sendNotificationAt: DateTime\n}\n"
Display Examples for MUTATION: giftCardCreate
[ { "example": { "type_name": "giftcardcreate", "title": "Create a non-expiring gift card with a generated code for a customer", "query_string": "mutation giftCardCreate($input: GiftCardCreateInput!) {\n giftCardCreate(input: $input) {\n userErrors {\n message\n field\n }\n giftCard {\n id\n expiresOn\n note\n initialValue {\n amount\n }\n customer {\n id\n }\n }\n giftCardCode\n }\n}", "query_arguments": { "input": "$input" }, "variables": { "input": { "initialValue": "27.84", "customerId": "gid://shopify/Customer/743592264", "note": "Refund for Order #1" } }, "response": { "data": { "giftCardCreate": { "userErrors": [], "giftCard": { "id": "gid://shopify/GiftCard/1063936316", "expiresOn": null, "note": "Refund for Order #1", "initialValue": { "amount": "27.84" }, "customer": { "id": "gid://shopify/Customer/743592264" } }, "giftCardCode": "29cd47a94g68fe42" } } }, "api_name": "admin", "minimum_api_version": "2023-10", "maximum_api_version": "unstable", "location": "/components/stored_value_instruments/gift_cards/test/unit/graph_api/admin/mutations/gift_card_create_test.rb", "curl_example": "curl -X POST \\\nhttps://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \\\n-H 'Content-Type: application/json' \\\n-H 'X-Shopify-Access-Token: {access_token}' \\\n-d '{\n\"query\": \"mutation giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { userErrors { message field } giftCard { id expiresOn note initialValue { amount } customer { id } } giftCardCode } }\",\n \"variables\": {\n \"input\": {\n \"initialValue\": \"27.84\",\n \"customerId\": \"gid://shopify/Customer/743592264\",\n \"note\": \"Refund for Order #1\"\n }\n }\n}'\n", "remix_example": "const { admin } = await authenticate.admin(request);\n\nconst response = await admin.graphql(\n `#graphql\n mutation giftCardCreate($input: GiftCardCreateInput!) {\n giftCardCreate(input: $input) {\n userErrors {\n message\n field\n }\n giftCard {\n id\n expiresOn\n note\n initialValue {\n amount\n }\n customer {\n id\n }\n }\n giftCardCode\n }\n }`,\n {\n variables: {\n \"input\": {\n \"initialValue\": \"27.84\",\n \"customerId\": \"gid://shopify/Customer/743592264\",\n \"note\": \"Refund for Order #1\"\n }\n },\n },\n);\n\nconst data = await response.json();\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 giftCardCreate($input: GiftCardCreateInput!) {\n giftCardCreate(input: $input) {\n userErrors {\n message\n field\n }\n giftCard {\n id\n expiresOn\n note\n initialValue {\n amount\n }\n customer {\n id\n }\n }\n giftCardCode\n }\n }\nQUERY\n\nvariables = {\n \"input\": {\n \"initialValue\": \"27.84\",\n \"customerId\": \"gid://shopify/Customer/743592264\",\n \"note\": \"Refund for Order #1\"\n }\n}\n\nresponse = client.query(query: query, variables: variables)\n", "node_example": "const client = new shopify.clients.Graphql({session});\nconst data = await client.query({\n data: {\n \"query\": `mutation giftCardCreate($input: GiftCardCreateInput!) {\n giftCardCreate(input: $input) {\n userErrors {\n message\n field\n }\n giftCard {\n id\n expiresOn\n note\n initialValue {\n amount\n }\n customer {\n id\n }\n }\n giftCardCode\n }\n }`,\n \"variables\": {\n \"input\": {\n \"initialValue\": \"27.84\",\n \"customerId\": \"gid://shopify/Customer/743592264\",\n \"note\": \"Refund for Order #1\"\n }\n },\n },\n});\n", "php_example": "use Shopify\\Clients\\Graphql;\n\n$client = new Graphql(\"your-development-store.myshopify.com\", $accessToken);\n$query = <<<QUERY\n mutation giftCardCreate($input: GiftCardCreateInput!) {\n giftCardCreate(input: $input) {\n userErrors {\n message\n field\n }\n giftCard {\n id\n expiresOn\n note\n initialValue {\n amount\n }\n customer {\n id\n }\n }\n giftCardCode\n }\n }\nQUERY;\n\n$variables = [\n \"input\" => [\n \"initialValue\" => \"27.84\",\n \"customerId\" => \"gid://shopify/Customer/743592264\",\n \"note\" => \"Refund for Order #1\",\n ],\n];\n\n$response = $client->query([\"query\" => $query, \"variables\" => $variables]);\n" }, "titleStringKey": "variables", "inputVariableEntries": [ { "arg": { "name": "input", "description": "The input fields to create a gift card.", "type": { "kind": "INPUT_OBJECT", "name": "GiftCardCreateInput", "list": false, "non_null": true }, "defaultValue": null, "typeSignature": "GiftCardCreateInput!", "isDeprecated": false, "deprecationReason": null, "kind": "ARGUMENT" }, "key": "input", "argValue": " {\"initialValue\":\"27.84\",\"customerId\":\"gid://shopify/Customer/743592264\",\"note\":\"Refund for Order #1\"}", "typeKind": "MUTATION" } ] } ]