Move inventory from one bin to another
Description
Move four units of an inventory item from one bin to another bin at the same location. The
origin bin's `changeFromQuantity` makes the move fail if the bin's on-hand quantity changed
since you last read it, and the `@idempotent` key makes the request safe to retry. This
mutation is part of the
[physical inventory feature preview](https://shopify.dev/changelog/physical-inventory-feature-preview).
Query
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
inventoryItem {
id
}
from {
... on InventoryBin {
id
name
}
}
to {
... on InventoryBin {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}
Variables
{
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 4,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": 10
}
},
"to": {
"bin": {
"binId": "gid://shopify/InventoryBin/103004229",
"changeFromQuantity": null
}
}
}
],
"idempotencyKey": "6b1e3f52-8d0a-4c47-9e21-0f5a7c3d2b18"
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) { inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) { inventoryBinMove { id name movements(first: 1) { nodes { items(first: 10) { nodes { quantity inventoryItem { id } from { ... on InventoryBin { id name } } to { ... on InventoryBin { id name } } } } } } } userErrors { field message code } } }",
"variables": {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 4,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": 10
}
},
"to": {
"bin": {
"binId": "gid://shopify/InventoryBin/103004229",
"changeFromQuantity": null
}
}
}
],
"idempotencyKey": "6b1e3f52-8d0a-4c47-9e21-0f5a7c3d2b18"
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
inventoryItem {
id
}
from {
... on InventoryBin {
id
name
}
}
to {
... on InventoryBin {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}`,
{
variables: {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 4,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": 10
}
},
"to": {
"bin": {
"binId": "gid://shopify/InventoryBin/103004229",
"changeFromQuantity": null
}
}
}
],
"idempotencyKey": "6b1e3f52-8d0a-4c47-9e21-0f5a7c3d2b18"
},
},
);
const json = await response.json();
return json.data;
}
Ruby
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
inventoryItem {
id
}
from {
... on InventoryBin {
id
name
}
}
to {
... on InventoryBin {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}
QUERY
variables = {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 4,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": 10
}
},
"to": {
"bin": {
"binId": "gid://shopify/InventoryBin/103004229",
"changeFromQuantity": null
}
}
}
],
"idempotencyKey": "6b1e3f52-8d0a-4c47-9e21-0f5a7c3d2b18"
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
inventoryItem {
id
}
from {
... on InventoryBin {
id
name
}
}
to {
... on InventoryBin {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}`,
"variables": {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 4,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": 10
}
},
"to": {
"bin": {
"binId": "gid://shopify/InventoryBin/103004229",
"changeFromQuantity": null
}
}
}
],
"idempotencyKey": "6b1e3f52-8d0a-4c47-9e21-0f5a7c3d2b18"
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
inventoryItem {
id
}
from {
... on InventoryBin {
id
name
}
}
to {
... on InventoryBin {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}' \
--variables \
'{
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 4,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": 10
}
},
"to": {
"bin": {
"binId": "gid://shopify/InventoryBin/103004229",
"changeFromQuantity": null
}
}
}
],
"idempotencyKey": "6b1e3f52-8d0a-4c47-9e21-0f5a7c3d2b18"
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
inventoryItem {
id
}
from {
... on InventoryBin {
id
name
}
}
to {
... on InventoryBin {
id
name
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}
`,
variables: {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 4,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": 10
}
},
"to": {
"bin": {
"binId": "gid://shopify/InventoryBin/103004229",
"changeFromQuantity": null
}
}
}
],
"idempotencyKey": "6b1e3f52-8d0a-4c47-9e21-0f5a7c3d2b18"
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"inventoryBinMoveCreate": {
"inventoryBinMove": {
"id": "gid://shopify/InventoryBinMove/1036221430",
"name": "#BM1002",
"movements": {
"nodes": [
{
"items": {
"nodes": [
{
"quantity": 4,
"inventoryItem": {
"id": "gid://shopify/InventoryItem/30322695"
},
"from": {
"id": "gid://shopify/InventoryBin/522906105",
"name": "Area 1"
},
"to": {
"id": "gid://shopify/InventoryBin/103004229",
"name": "Area 2"
}
}
]
}
}
]
}
},
"userErrors": []
}
}
Remove inventory from a bin
Description
Move two units of an inventory item out of a bin and into the `REMOVED` system bin, for
example to write off damaged stock. Use the `ADDED` system bin as the origin to bring new
stock into a bin instead. Passing `null` for `changeFromQuantity` skips the compare-and-swap
check. This mutation is part of the
[physical inventory feature preview](https://shopify.dev/changelog/physical-inventory-feature-preview).
Query
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
from {
... on InventoryBin {
id
name
}
}
to {
... on InventorySystemBin {
identifier
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}
Variables
{
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 2,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": null
}
},
"to": {
"systemBinIdentifier": "REMOVED"
}
}
],
"idempotencyKey": "c9d84a17-2f6e-4b35-a0c8-5e1b7d93f420"
}
cURL
curl -X POST \
https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) { inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) { inventoryBinMove { id name movements(first: 1) { nodes { items(first: 10) { nodes { quantity from { ... on InventoryBin { id name } } to { ... on InventorySystemBin { identifier } } } } } } } userErrors { field message code } } }",
"variables": {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 2,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": null
}
},
"to": {
"systemBinIdentifier": "REMOVED"
}
}
],
"idempotencyKey": "c9d84a17-2f6e-4b35-a0c8-5e1b7d93f420"
}
}'
React Router
import { authenticate } from "../shopify.server";
export const loader = async ({request}) => {
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
from {
... on InventoryBin {
id
name
}
}
to {
... on InventorySystemBin {
identifier
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}`,
{
variables: {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 2,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": null
}
},
"to": {
"systemBinIdentifier": "REMOVED"
}
}
],
"idempotencyKey": "c9d84a17-2f6e-4b35-a0c8-5e1b7d93f420"
},
},
);
const json = await response.json();
return json.data;
}
Ruby
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
from {
... on InventoryBin {
id
name
}
}
to {
... on InventorySystemBin {
identifier
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}
QUERY
variables = {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 2,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": null
}
},
"to": {
"systemBinIdentifier": "REMOVED"
}
}
],
"idempotencyKey": "c9d84a17-2f6e-4b35-a0c8-5e1b7d93f420"
}
response = client.query(query: query, variables: variables)
Node.js
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
from {
... on InventoryBin {
id
name
}
}
to {
... on InventorySystemBin {
identifier
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}`,
"variables": {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 2,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": null
}
},
"to": {
"systemBinIdentifier": "REMOVED"
}
}
],
"idempotencyKey": "c9d84a17-2f6e-4b35-a0c8-5e1b7d93f420"
},
},
});
Shopify CLI
shopify app execute \
--query \
'mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
from {
... on InventoryBin {
id
name
}
}
to {
... on InventorySystemBin {
identifier
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}' \
--variables \
'{
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 2,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": null
}
},
"to": {
"systemBinIdentifier": "REMOVED"
}
}
],
"idempotencyKey": "c9d84a17-2f6e-4b35-a0c8-5e1b7d93f420"
}'
Direct API Access
const response = await fetch('shopify:admin/api/unstable/graphql.json', {
method: 'POST',
body: JSON.stringify({
query: `
mutation InventoryBinMoveCreate($locationId: ID!, $items: [InventoryBinMoveItemInput!]!, $idempotencyKey: String!) {
inventoryBinMoveCreate(locationId: $locationId, items: $items) @idempotent(key: $idempotencyKey) {
inventoryBinMove {
id
name
movements(first: 1) {
nodes {
items(first: 10) {
nodes {
quantity
from {
... on InventoryBin {
id
name
}
}
to {
... on InventorySystemBin {
identifier
}
}
}
}
}
}
}
userErrors {
field
message
code
}
}
}
`,
variables: {
"locationId": "gid://shopify/Location/275072021",
"items": [
{
"inventoryItemId": "gid://shopify/InventoryItem/30322695",
"quantity": 2,
"from": {
"bin": {
"binId": "gid://shopify/InventoryBin/522906105",
"changeFromQuantity": null
}
},
"to": {
"systemBinIdentifier": "REMOVED"
}
}
],
"idempotencyKey": "c9d84a17-2f6e-4b35-a0c8-5e1b7d93f420"
},
}),
});
const { data } = await response.json();
console.log(data);
Response
{
"inventoryBinMoveCreate": {
"inventoryBinMove": {
"id": "gid://shopify/InventoryBinMove/1036221431",
"name": "#BM1002",
"movements": {
"nodes": [
{
"items": {
"nodes": [
{
"quantity": 2,
"from": {
"id": "gid://shopify/InventoryBin/522906105",
"name": "Area 1"
},
"to": {
"identifier": "REMOVED"
}
}
]
}
}
]
}
},
"userErrors": []
}
}