Shopify / shopify-api-js

Shopify Admin API Library for Node. Accelerate development with support for authentication, graphql proxy, webhooks
MIT License
942 stars 390 forks source link

RestResourceError: Could not find a path for request when saving transaction #992

Closed fabioportieri closed 1 year ago

fabioportieri commented 1 year ago

Issue summary

RestResourceError: Could not find a path for request
22:21:49 │ remix │     at Function.getPath (/home/fabio/workspace/bulk-importer/node_modules/@shopify/shopify-api/rest/base.ts:201:13)
22:21:49 │ remix │     at Function.<anonymous> (/home/fabio/workspace/bulk-importer/node_modules/@shopify/shopify-api/rest/base.ts:110:23)
22:21:49 │ remix │     at Generator.next (<anonymous>)
22:21:49 │ remix │     at /home/fabio/workspace/bulk-importer/node_modules/tslib/tslib.js:169:75
22:21:49 │ remix │     at new Promise (<anonymous>)
22:21:49 │ remix │     at Object.__awaiter (/home/fabio/workspace/bulk-importer/node_modules/tslib/tslib.js:165:16)
22:21:49 │ remix │     at Function.request (/home/fabio/workspace/bulk-importer/node_modules/@shopify/shopify-api/rest/base.js:37:24)
22:21:49 │ remix │     at RemixResource.<anonymous> (/home/fabio/workspace/bulk-importer/node_modules/@shopify/shopify-api/rest/base.ts:266:44)
22:21:49 │ remix │     at Generator.next (<anonymous>)
22:21:49 │ remix │     at /home/fabio/workspace/bulk-importer/node_modules/tslib/tslib.js:169:75
22:21:49 │ remix │ Could not find a path for request

Expected behavior

save the transaction with no errors

Actual behavior

the error

fabioportieri commented 1 year ago

can be closed, this is the correct syntax

export async function createSaleTransactionForOrder(
  admin: AdminApiContext,
  session: Session,
  order: Order
): Promise<Transaction> {

  const transaction: Transaction = new admin.rest.resources.Transaction({
    session
  });

  transaction.order_id = order.id;
  transaction.kind = 'sale'; // Specify the transaction type as 'sale;
  transaction.amount = order.total_price;
  transaction.currency = order.currency;
  transaction.gateway = "Cash on Delivery (COD)";
  transaction.user_id = order.customer!.id;

  await transaction.save({
    update: true,
  });

  return transaction;
}