MONEI / Shopify-api-node

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

[api] Update fulfillment endpoints #563

Closed tkalliom closed 1 year ago

tkalliom commented 1 year ago
coveralls commented 1 year ago

Coverage Status

Coverage: 100.0%. Remained the same when pulling 34bd5de9481ad53411797529b24bcdde0fd3b978 on tkalliom:fulfillment-api-changes into 6c2a0868c2185aba6b1d5ad6765554f94e4e15a1 on MONEI:master.

FlavioAandres commented 1 year ago

@tkalliom Hey guys, I'm trying to migrate the use cases for the new 2023-01 API update, and I just noticed we need to use the following:

Do you know if this library is supporting this change?? Thanks!!! Ref: https://shopify.dev/api/release-notes/2022-07

lpinca commented 1 year ago

@FlavioAandres the /orders/{order_id}/fulfillments.json seems to be still supported. See https://shopify.dev/api/admin-rest/2023-01/resources/fulfillmentorder#get-orders-order-id-fulfillment-orders.

Can you test it?

const shopify = new Shopify({
  shopName: 'xxx',
  apiVersion: '2023-01',
  accessToken: 'xxx'
});

const fulfillments = await shopify.fulfillment.list(orderId);
lpinca commented 1 year ago

@FlavioAandres I misread your comment, sorry. You can use:

const fulfillment = await shopify.fulfillment.createV2(params);
lpinca commented 1 year ago

Can you please split the commit in two?

lpinca commented 1 year ago

Thank you.

FlavioAandres commented 1 year ago

@tkalliom Thanks for adding those changes, are really useful. @lpinca Do you have an idea when these changes can be released to NPM?

lpinca commented 1 year ago

@FlavioAandres soon. I would also like to include https://github.com/MONEI/Shopify-api-node/pull/560 and https://github.com/MONEI/Shopify-api-node/pull/564 in the next release.

kristiandm commented 1 year ago

Hello, I'm kinda new to using this library so I apologize if my question is a bit weird. Can someone explain to me how to use createV2? we've been using create for a while but because of the 2023-01 change were trying to make createV2 work. What is the difference in using create and createV2 regarding the params? and how does createV2 know which order is for fulfillment without the orderId parameter like the create function has?

edit: I tried using it this way

const shopify = new Shopify({ shopName: merchant.domain, apiVersion: '2023-01', accessToken: merchant.shopifyToken, });

    shopify.fulfillment.createV2({
              notify_customer: false,
              location_id: inventoryLocation?.id,
              order_id: order.orderId,
              line_items_by_fulfillment_order: [
                {
                  fulfillment_order_id: order.id,                    
                    ...(targetMerchant.serviceType === ServiceType.MARKETPLACE
                      ? {
                        fulfillment_order_line_items:  order.items.map((item: OrderItems) => {
                            return { id: toNumber(item.id) };
                          }),
                        }
                      : null) 
                }
              ]
            })

            but I received this error: "Shopify Open Fulfillment: {"errors":"The api_client does not have the required permission(s)."} , Order ID: 5b1707b0-5908-49a4-9372-9343c163715c , Merchant ID: 55530553543 , Error Message: Response code 403 (Forbidden)"