How can I mark an fulfillment order as fulfilled using latest Shopify API in NodeJS

I already have built a custom app using the latest Node template (https://github.com/Shopify/shopify-app-template-node).

I can manage the product via product API with this code:

app.get("/api/products/count", async (_req, res) => {
  const countData = await shopify.api.rest.Product.count({
    session: res.locals.shopify.session,
  });
  res.status(200).send(countData);
});

But the fulfillment API is not working as expected; I need to make this work, My code is below:

app.post("/api/fulfillment", async (_req, res) => {
  const fulfillment = await shopify.api.rest.Fulfillment({
    session: res.locals.shopify.session,
  });
  fulfillment.line_items_by_fulfillment_order = [
    {
      fulfillment_order_id: _req?.data?.f_order?.id,
    },
  ];
  fulfillment.tracking_info = {
    number: _req?.data?.f_order?.t_number,
    url: _req?.data?.f_order?.t_url,
  };
  await fulfillment.save({
    update: true,
  });

  res.json("response");
  res.status(200).end();
});​

It is giving ‘fulfillment.save’ is not a function error.

Thanks in advance :slightly_smiling_face:

1 Like

Hi Rousnay,

It’s possible that you need to be making calls to /admin/api/2023-04/fulfillments.json rather than "/api/version-number/fulfillment" in the code you’ve shared. There are some examples of post-fulfillments in our docs here, and there’s also a forum conversation on marking fulfilled orders as fulfilled here.

Try out with modifying the examples in our docs and update here if you’re still running into issues.