MONEI / Shopify-api-node

Node Shopify connector sponsored by MONEI
https://monei.com/shopify-payment-gateway/
MIT License
952 stars 280 forks source link

undefined response for get order #429

Closed ekuzu closed 3 years ago

ekuzu commented 4 years ago

Hi I can get response directly via curl http://user:pass... But when i run codes below, getting res.body='' , res.statusCode=200

  shopify.order
    .get(order_id)
    .then((data) => {
      console.log(data)
    })
    .catch((error) => {
      console.log(error)
    })
capatina commented 3 years ago

Had a similar issue with accessScopes.list() and downgrading to 3.3.1 fixed it. After 3.3.2 it's not working.

lpinca commented 3 years ago

Run npm ls agent-base and see if one of your dependencies is using agent-base@<=4. If so it is a known issue and there is not much we can do about it.

maxfrigge commented 3 years ago

@lpinca I am having this too with agent-base@6.0.2.

According to the debugging proxy the response comes in as expected, but for some reason the body in got is empty.

EDIT: Downgrading to shopify-api-node@3.3.1 does fix it.

lpinca commented 3 years ago

I cannot reproduce:

$ node -v
v15.3.0
$ npm ls shopify-api-node
shopify@ /Users/luigi/gh-429
`-- shopify-api-node@3.5.4
$ cat index.js
'use strict';

const assert = require('assert');
const Shopify = require('shopify-api-node');

const shopify = new Shopify({
  shopName: 'quuz',
  apiVersion: '2020-10',
  apiKey: 'b68c3a4bf44cd240511e5f4114f0be4d',
  password: '2d170167fc62551920ca60fe40a5e548'
});

(async function () {
  const [orders, products] = await Promise.all([
    shopify.order.list(),
    shopify.product.list()
  ]);

  assert.deepStrictEqual(orders, []);
  assert.deepStrictEqual(products, []);

  const {
    id: productId,
    variants: [{ id: variantId }]
  } = await shopify.product.create({
    body_html: '<strong>Good snowboard!</strong>',
    product_type: 'Snowboard',
    title: 'Burton Custom Freestlye 151',
    vendor: 'Burton'
  });

  const { id: orderId } = await shopify.order.create({
    email: 'foo@example.com',
    fulfillment_status: 'fulfilled',
    send_receipt: true,
    send_fulfillment_receipt: true,
    line_items: [
      {
        variant_id: variantId,
        quantity: 1
      }
    ]
  });

  const order = await shopify.order.get(orderId);

  console.log(order);

  await Promise.all([
    shopify.order.delete(orderId),
    shopify.product.delete(productId)
  ]);
})().catch(console.error);
$ node index.js
{
  id: 2927639232547,
  email: 'foo@example.com',
  closed_at: '2020-12-08T01:38:47-05:00',
  created_at: '2020-12-08T01:38:46-05:00',
  updated_at: '2020-12-08T01:38:48-05:00',
  number: 16,
  note: null,
  token: '37a169ea48d1d6bc8a207fdef00318b9',
  gateway: '',
  test: false,
  total_price: '0.00',
  subtotal_price: '0.00',
  total_weight: 0,
  total_tax: '0.00',
  taxes_included: false,
  currency: 'EUR',
  financial_status: 'paid',
  confirmed: true,
  total_discounts: '0.00',
  total_line_items_price: '0.00',
  cart_token: null,
  buyer_accepts_marketing: false,
  name: '#1016',
  referring_site: null,
  landing_site: null,
  cancelled_at: null,
  cancel_reason: null,
  total_price_usd: '0.00',
  checkout_token: null,
  reference: null,
  user_id: null,
  location_id: null,
  source_identifier: null,
  source_url: null,
  processed_at: '2020-12-08T01:38:46-05:00',
  device_id: null,
  phone: null,
  customer_locale: null,
  app_id: 1612699,
  browser_ip: null,
  landing_site_ref: null,
  order_number: 1016,
  discount_applications: [],
  discount_codes: [],
  note_attributes: [],
  payment_gateway_names: [],
  processing_method: '',
  checkout_id: null,
  source_name: '1612699',
  fulfillment_status: 'fulfilled',
  tax_lines: [],
  tags: '',
  contact_email: 'foo@example.com',
  order_status_url: 'https://quuz.myshopify.com/19563841/orders/37a169ea48d1d6bc8a207fdef00318b9/authenticate?key=219583113df0f4be06443d909669b905',
  presentment_currency: 'EUR',
  total_line_items_price_set: {
    shop_money: { amount: '0.00', currency_code: 'EUR' },
    presentment_money: { amount: '0.00', currency_code: 'EUR' }
  },
  total_discounts_set: {
    shop_money: { amount: '0.00', currency_code: 'EUR' },
    presentment_money: { amount: '0.00', currency_code: 'EUR' }
  },
  total_shipping_price_set: {
    shop_money: { amount: '0.00', currency_code: 'EUR' },
    presentment_money: { amount: '0.00', currency_code: 'EUR' }
  },
  subtotal_price_set: {
    shop_money: { amount: '0.00', currency_code: 'EUR' },
    presentment_money: { amount: '0.00', currency_code: 'EUR' }
  },
  total_price_set: {
    shop_money: { amount: '0.00', currency_code: 'EUR' },
    presentment_money: { amount: '0.00', currency_code: 'EUR' }
  },
  total_tax_set: {
    shop_money: { amount: '0.00', currency_code: 'EUR' },
    presentment_money: { amount: '0.00', currency_code: 'EUR' }
  },
  line_items: [
    {
      id: 6379885297699,
      variant_id: 32978997477411,
      title: 'Burton Custom Freestlye 151',
      quantity: 1,
      sku: '',
      variant_title: null,
      vendor: 'Burton',
      fulfillment_service: 'manual',
      product_id: 4838584942627,
      requires_shipping: true,
      taxable: true,
      gift_card: false,
      name: 'Burton Custom Freestlye 151',
      variant_inventory_management: null,
      properties: [],
      product_exists: true,
      fulfillable_quantity: 0,
      grams: 0,
      price: '0.00',
      total_discount: '0.00',
      fulfillment_status: 'fulfilled',
      price_set: [Object],
      total_discount_set: [Object],
      discount_allocations: [],
      duties: [],
      admin_graphql_api_id: 'gid://shopify/LineItem/6379885297699',
      tax_lines: []
    }
  ],
  fulfillments: [
    {
      id: 2778011009059,
      order_id: 2927639232547,
      status: 'success',
      created_at: '2020-12-08T01:38:46-05:00',
      service: 'manual',
      updated_at: '2020-12-08T01:38:46-05:00',
      tracking_company: null,
      shipment_status: null,
      location_id: 42043015,
      line_items: [Array],
      tracking_number: null,
      tracking_numbers: [],
      tracking_url: null,
      tracking_urls: [],
      receipt: {},
      name: '#1016.1',
      admin_graphql_api_id: 'gid://shopify/Fulfillment/2778011009059'
    }
  ],
  refunds: [],
  total_tip_received: '0.0',
  original_total_duties_set: null,
  current_total_duties_set: null,
  admin_graphql_api_id: 'gid://shopify/Order/2927639232547',
  shipping_lines: [],
  customer: {
    id: 2965119139875,
    email: 'foo@example.com',
    accepts_marketing: false,
    created_at: '2020-05-21T15:21:53-04:00',
    updated_at: '2020-12-08T01:38:47-05:00',
    first_name: null,
    last_name: null,
    orders_count: 1,
    state: 'disabled',
    total_spent: '0.00',
    last_order_id: 2927639232547,
    note: null,
    verified_email: true,
    multipass_identifier: null,
    tax_exempt: false,
    phone: null,
    tags: '',
    last_order_name: '#1016',
    currency: 'EUR',
    accepts_marketing_updated_at: '2020-05-21T15:21:54-04:00',
    marketing_opt_in_level: null,
    tax_exemptions: [],
    admin_graphql_api_id: 'gid://shopify/Customer/2965119139875'
  }
}
maxfrigge commented 3 years ago

Thanks so much for taking the time to further investigate!

This seems to depend on node version as well. I was able to reproduce with node v14.0.0, but upgrading to node v14.15.1 fixed it. It also works fine in node v12.20.0 and node v15.3.0.

lpinca commented 3 years ago

Yes, please use the latest release of one of the supported release lines. Bug fixes are regularly applied by Node.js core team.