Refund Calculate Endpoint Not Finding Line Item

Solved
almax120
Shopify Partner
9 0 0

I'm unable to calculate a refund. I created and completed a checkout using the payment api, then attempted to refund it.

 

Data:

 

{
  refund: {
    shipping: {
      full_refund: true,
    },
    refund_line_items: [
      {
        line_item_id: "0e3bb1d0d8a5cfd8767162c8b1f2aedb",
        quantity: 1,
        restock_type: "cancel",
      },
    ],
},
}

 

--

response:

{
errors: {
line_item_id: "expected String to be a id",
},
}

response headers:
"x-request-id": "59255b96-8e3a-431c-910c-03cc51e75c8a",

 

 

I used the line item id retrieved from the checkout. When I use the variant id as the line item id, i get a line_item cannot be blank error.

I do not know why the calculate endpoint isn't working.

0 Likes
_JB
Shopify Staff
Shopify Staff
823 97 178

Hey @almax120,

The line_item.id should be an integer. I'm not sure how you're getting that hash for the line_item id, but try your GET again and double-check the response. The id should be the first field for each line_item object:

19-21-ter0v-xj2e3.png

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
almax120
Shopify Partner
9 0 0

@_JB this is what i get from calling: GET /checkouts/${checkoutId}.json

 

 

 

{
  completed_at: "2021-04-16T21:57:15-05:00",
  created_at: "2021-04-16T21:56:39-05:00",
  currency: "USD",
  presentment_currency: "USD",
  customer_id: 5182528815271,
  customer_locale: "en",
  device_id: null,
  discount_code: null,
  email: "...",
  legal_notice_url: null,
  location_id: null,
  name: "#20317010526375",
  note: "",
  note_attributes: {
  },
  order_id: 3797761130663,
  order_status_url: "https://dev-rap-snacks.myshopify.com/53088682151/checkouts/6563b46286ce4f17fc19cb398e2bf6e3/thank_you",
  order: {
    id: 3797761130663,
    name: "#1017",
    status_url: "https://dev-rap-snacks.myshopify.com/53088682151/checkouts/6563b46286ce4f17fc19cb398e2bf6e3/thank_you",
  },
  payment_due: "31.29",
  payment_url: "https://deposit.us.shopifycs.com/sessions",
  payments: [
    {
      id: 2553010028711,
      unique_token: "qVej7DigxWne34Td1Kz4mD",
      payment_processing_error_message: null,
      fraudulent: false,
      transaction: {
        amount: "31.29",
        amount_in: null,
        amount_out: null,
        amount_rounding: null,
        authorization: "pi_1Ih4LMR3q41EROwzjZXY1PU5",
        created_at: "2021-04-16T21:57:11-05:00",
        currency: "USD",
        error_code: null,
        parent_id: null,
        gateway: "shopify_payments",
        id: 4761638371495,
        kind: "sale",
        message: "Transaction approved",
        status: "success",
        test: true,
        receipt: {
          id: "pi_1Ih4LMR3q41EROwzjZXY1PU5",
          object: "payment_intent",
          amount: 3129,
          amount_capturable: 0,
          amount_received: 3129,
          canceled_at: null,
          cancellation_reason: null,
          capture_method: "automatic",
          charges: {
            object: "list",
            data: [
              {
                id: "ch_1Ih4LMR3q41EROwzMtYqtuXL",
                object: "charge",
                amount: 3129,
                application_fee: "fee_1Ih4LNR3q41EROwzLZCW3zLf",
                balance_transaction: {
                  id: "txn_1Ih4LNR3q41EROwzwosu8O8w",
                  object: "balance_transaction",
                  exchange_rate: null,
                },
                captured: true,
                created: 1618628232,
                currency: "usd",
                failure_code: null,
                failure_message: null,
                fraud_details: {
                },
                livemode: false,
                metadata: {
                  shop_id: "53088682151",
                  shop_name: "dev-rap-snacks",
                  transaction_fee_total_amount: "121",
                  transaction_fee_tax_amount: "0",
                  payments_charge_id: "1804428116135",
                  order_transaction_id: "4761638371495",
                  manual_entry: "false",
                  order_id: "c20317010526375.1",
                  email: "...",
                },
                outcome: {
                  network_status: "approved_by_network",
                  reason: null,
                  risk_level: "normal",
                  risk_score: 9,
                  seller_message: "Payment complete.",
                  type: "authorized",
                },
                paid: true,
                payment_intent: "pi_1Ih4LMR3q41EROwzjZXY1PU5",
                payment_method: "pm_1Ih4LMR3q41EROwzTmJVMtBk",
                payment_method_details: {
                  card: {
                    brand: "mastercard",
                    checks: {
                      address_line1_check: null,
                      address_postal_code_check: null,
                      cvc_check: null,
                    },
                    country: "US",
                    description: "MasterCard Prepaid Card (Non-US)",
                    ds_transaction_id: null,
                    exp_month: 4,
                    exp_year: 2022,
                    fingerprint: "W42R39dc2U266g0i",
                    funding: "credit",
                    iin: "555555",
                    installments: null,
                    issuer: "CIAGROUP",
                    last4: "4444",
                    moto: null,
                    network: "mastercard",
                    network_transaction_id: "MCCSFYUUI0417",
                    three_d_secure: null,
                    wallet: null,
                  },
                  type: "card",
                },
                refunded: false,
                source: null,
                status: "succeeded",
                mit_params: {
                  network_transaction_id: "MCCSFYUUI0417",
                },
              },
            ],
            has_more: false,
            total_count: 1,
            url: "/v1/charges?payment_intent=pi_1Ih4LMR3q41EROwzjZXY1PU5",
          },
          confirmation_method: "manual",
          created: 1618628232,
          currency: "usd",
          last_payment_error: null,
          livemode: false,
          metadata: {
            shop_id: "53088682151",
            shop_name: "dev-rap-snacks",
            transaction_fee_total_amount: "121",
            transaction_fee_tax_amount: "0",
            payments_charge_id: "1804428116135",
            order_transaction_id: "4761638371495",
            manual_entry: "false",
            order_id: "c20317010526375.1",
            email: "...",
          },
          next_action: null,
          payment_method: "pm_1Ih4LMR3q41EROwzTmJVMtBk",
          payment_method_types: [
            "card",
          ],
          source: null,
          status: "succeeded",
        },
        location_id: null,
        user_id: null,
        transaction_group_id: null,
        device_id: null,
        payment_details: {
          credit_card_bin: null,
          avs_result_code: null,
          cvv_result_code: null,
          credit_card_number: "•••• •••• •••• 4444",
          credit_card_company: "Mastercard",
        },
      },
      credit_card: null,
    },
  ],
  phone: null,
  shopify_payments_account_id: "acct_1IW4AgR3q41EROwz",
  privacy_policy_url: null,
  refund_policy_url: null,
  requires_shipping: true,
  reservation_time_left: 0,
  reservation_time: null,
  source_identifier: null,
  source_name: "4932475",
  source_url: null,
  subscription_policy_url: null,
  subtotal_price: "26.39",
  shipping_policy_url: null,
  tax_exempt: false,
  taxes_included: false,
  terms_of_sale_url: null,
  terms_of_service_url: null,
  token: "6563b46286ce4f17fc19cb398e2bf6e3",
  total_price: "31.29",
  total_tax: "0.00",
  total_tip_received: "0.00",
  total_line_items_price: "29.99",
  updated_at: "2021-04-16T21:57:15-05:00",
  user_id: null,
  web_url: "https://dev-rap-snacks.myshopify.com/53088682151/checkouts/6563b46286ce4f17fc19cb398e2bf6e3",
  line_items: [
    {
      id: "0e3bb1d0d8a5cfd8767162c8b1f2aedb",
      key: "0e3bb1d0d8a5cfd8767162c8b1f2aedb",
      product_id: 6261908996263,
      variant_id: 38109590454439,
      sku: null,
      vendor: "Company 123",
      title: "Choker with Gold Pendant",
      variant_title: "",
      image_url: "https://cdn.shopify.com/s/files/1/0530/8868/2151/products/choker-with-gold-pendant_925x_a97d2b85-e75a-49de-933f-da37a10d2d9c.jpg?v=1612818896",
      taxable: true,
      requires_shipping: true,
      gift_card: false,
      price: "29.99",
      compare_at_price: null,
      line_price: "29.99",
      properties: {
      },
      quantity: 1,
      grams: 0,
      fulfillment_service: "manual",
      applied_discounts: [
      ],
      tax_lines: [
      ],
    },
  ],
  gift_cards: [
  ],
  tax_lines: [
  ],
  tax_manipulations: [
  ],
  shipping_line: {
    handle: "shopify-Economy-4.90",
    price: "4.90",
    title: "Economy",
    tax_lines: [
    ],
  },
  shipping_rate: {
    id: "shopify-Economy-4.90",
    price: "4.90",
    title: "Economy",
  },
  shipping_address: {
    id: 8764573843623,
    first_name: "Mine",
    last_name: "Dawg",
    phone: null,
    company: null,
    address1: "..."
  },
  credit_card: null,
  billing_address: {
    id: 8764573843623,
    first_name: "Mine",
    last_name: "Dawg",
    phone: null,
    company: null,
    address1: "..."
  },
  applied_discount: {
    amount: "3.60",
    title: "Marketplace Discount",
    description: "Exclusive discount for shoppers",
    value: "3.60",
    value_type: "fixed_amount",
    non_applicable_reason: null,
    applicable: true,
  },
}

 

 

 

0 Likes
_JB
Shopify Staff
Shopify Staff
823 97 178

This is an accepted solution.

Hey @almax120,

Thanks for clarifying. You'll need to query the order endpoint instead of checkout. A checkout is converted to an order once paid, and any subsequent actions will be done on the order endpoint.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
almax120
Shopify Partner
9 0 0

You are correct, that solved the line item issues.

 

Now, I receive a 406 (Not Acceptable) for this payload:

 

 

{
  refund: {
    shipping: {
      full_refund: true,
    },
    refund_line_items: [
      {
        line_item_id: 9924017389735,
        quantity: 1,
        restock_type: "cancel",
        location_id: 59818049703,
      },
    ],
  },
}

 

 

Request ID: "4cb6fe29-8d5f-4598-af3b-00da4e655c50"

 

The failure doesn't include any text for debugging.

 

I also tried the same request without restocking, and got the same failure.

0 Likes
_JB
Shopify Staff
Shopify Staff
823 97 178

Hey @almax120,

For that request the issue is in the endpoint URL:

/admin/api/2021-01//orders/order/30027219/refunds/calculate.json

 

The word orders is correct, but the singular form order should be removed. As well that order_id is likely incorrect as it's only 8 digits and recently created orders will be at least 13 digits. 

 

I also noticed the URL has a double backslash after the API version, though I did a test and it looks like the double backslash doesn't cause an error. Even though this isn't producing an error right now, I still recommend fixing it as there's no guarantee this won't cause an error in the future. 

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
almax120
Shopify Partner
9 0 0
Yep, its all good now. Thanks for your help!
0 Likes