Anchor to section titled 'undefined'

orderEditAddShippingLine
mutation

Requires write_order_edits access scope.

Adds a shipping line to an existing order. For more information on how to use the GraphQL Admin API to edit an existing order, refer to Edit existing orders.


Anchor to id
id
required

The ID of the calculated order to edit.

The shipping line to be added.


Was this section helpful?

The calculated order with the edits applied but not saved.

The calculated shipping line that's added during this order edit.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
Copy
mutation addShippingLine($id: ID!, $shippingLine: OrderEditAddShippingLineInput!) {
  orderEditAddShippingLine(id: $id, shippingLine: $shippingLine) {
    calculatedOrder {
      id
      totalOutstandingSet {
        presentmentMoney {
          amount
          currencyCode
        }
      }
      totalPriceSet {
        presentmentMoney {
          amount
          currencyCode
        }
      }
    }
    calculatedShippingLine {
      id
      title
      price {
        presentmentMoney {
          amount
          currencyCode
        }
      }
      stagedStatus
    }
    userErrors {
      field
      message
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation addShippingLine($id: ID!, $shippingLine: OrderEditAddShippingLineInput!) { orderEditAddShippingLine(id: $id, shippingLine: $shippingLine) { calculatedOrder { id totalOutstandingSet { presentmentMoney { amount currencyCode } } totalPriceSet { presentmentMoney { amount currencyCode } } } calculatedShippingLine { id title price { presentmentMoney { amount currencyCode } } stagedStatus } userErrors { field message } } }",
 "variables": {
    "id": "gid://shopify/CalculatedOrder/607673083",
    "shippingLine": {
      "title": "2-Day Shipping",
      "price": {
        "amount": 19.99,
        "currencyCode": "USD"
      }
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation addShippingLine($id: ID!, $shippingLine: OrderEditAddShippingLineInput!) {
    orderEditAddShippingLine(id: $id, shippingLine: $shippingLine) {
      calculatedOrder {
        id
        totalOutstandingSet {
          presentmentMoney {
            amount
            currencyCode
          }
        }
        totalPriceSet {
          presentmentMoney {
            amount
            currencyCode
          }
        }
      }
      calculatedShippingLine {
        id
        title
        price {
          presentmentMoney {
            amount
            currencyCode
          }
        }
        stagedStatus
      }
      userErrors {
        field
        message
      }
    }
  }`,
  {
    variables: {
      "id": "gid://shopify/CalculatedOrder/607673083",
      "shippingLine": {
        "title": "2-Day Shipping",
        "price": {
          "amount": 19.99,
          "currencyCode": "USD"
        }
      }
    },
  },
);

const data = await response.json();
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 addShippingLine($id: ID!, $shippingLine: OrderEditAddShippingLineInput!) {
    orderEditAddShippingLine(id: $id, shippingLine: $shippingLine) {
      calculatedOrder {
        id
        totalOutstandingSet {
          presentmentMoney {
            amount
            currencyCode
          }
        }
        totalPriceSet {
          presentmentMoney {
            amount
            currencyCode
          }
        }
      }
      calculatedShippingLine {
        id
        title
        price {
          presentmentMoney {
            amount
            currencyCode
          }
        }
        stagedStatus
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY

variables = {
  "id": "gid://shopify/CalculatedOrder/607673083",
  "shippingLine": {
    "title": "2-Day Shipping",
    "price": {
      "amount": 19.99,
      "currencyCode": "USD"
    }
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation addShippingLine($id: ID!, $shippingLine: OrderEditAddShippingLineInput!) {
      orderEditAddShippingLine(id: $id, shippingLine: $shippingLine) {
        calculatedOrder {
          id
          totalOutstandingSet {
            presentmentMoney {
              amount
              currencyCode
            }
          }
          totalPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
          }
        }
        calculatedShippingLine {
          id
          title
          price {
            presentmentMoney {
              amount
              currencyCode
            }
          }
          stagedStatus
        }
        userErrors {
          field
          message
        }
      }
    }`,
    "variables": {
      "id": "gid://shopify/CalculatedOrder/607673083",
      "shippingLine": {
        "title": "2-Day Shipping",
        "price": {
          "amount": 19.99,
          "currencyCode": "USD"
        }
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation addShippingLine($id: ID!, $shippingLine: OrderEditAddShippingLineInput!) {
    orderEditAddShippingLine(id: $id, shippingLine: $shippingLine) {
      calculatedOrder {
        id
        totalOutstandingSet {
          presentmentMoney {
            amount
            currencyCode
          }
        }
        totalPriceSet {
          presentmentMoney {
            amount
            currencyCode
          }
        }
      }
      calculatedShippingLine {
        id
        title
        price {
          presentmentMoney {
            amount
            currencyCode
          }
        }
        stagedStatus
      }
      userErrors {
        field
        message
      }
    }
  }
QUERY;

$variables = [
  "id" => "gid://shopify/CalculatedOrder/607673083",
  "shippingLine" => [
    "title" => "2-Day Shipping",
    "price" => [
      "amount" => 19.99,
      "currencyCode" => "USD",
    ],
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "id": "gid://shopify/CalculatedOrder/607673083",
  "shippingLine": {
    "title": "2-Day Shipping",
    "price": {
      "amount": 19.99,
      "currencyCode": "USD"
    }
  }
}
Hide code
Response
JSON
{
  "orderEditAddShippingLine": {
    "calculatedOrder": {
      "id": "gid://shopify/CalculatedOrder/607673083",
      "totalOutstandingSet": {
        "presentmentMoney": {
          "amount": "19.99",
          "currencyCode": "USD"
        }
      },
      "totalPriceSet": {
        "presentmentMoney": {
          "amount": "31.49",
          "currencyCode": "USD"
        }
      }
    },
    "calculatedShippingLine": {
      "id": "gid://shopify/CalculatedShippingLine/52c5ee83-d24a-4a4d-a048-b00ad90aa19f",
      "title": "2-Day Shipping",
      "price": {
        "presentmentMoney": {
          "amount": "19.99",
          "currencyCode": "USD"
        }
      },
      "stagedStatus": "ADDED"
    },
    "userErrors": []
  }
}