No records returned Sync Table pack

Hey all, I’m pretty new to this however, I’m trying to build a sync table from some api data, all looks like it is working and the data is visible in the logs, however, my table sync is saying no records returned.

Am I doing something wrong in my code:

import * as coda from "@codahq/packs-sdk";

export const pack = coda.newPack({
  networkDomains: ["APILINK"],
});

// User-configurable parameter for the email address
const emailParameter = coda.makeParameter({
  type: coda.ParameterType.String,
  name: "email",
  description: "Please enter your email address",
});

const verificationCodeParameter = coda.makeParameter({
  type: coda.ParameterType.String,
  name: "verificationCode",
  description: "Enter the verification code sent to your email",
});

// Define the schema for your table
const transactionSchema = coda.makeObjectSchema({
  type: coda.ValueType.Object,
  properties: {
    connection: {type: coda.ValueType.String},
    internalTransactionId: {type: coda.ValueType.String},
    bookingDateTime: {type: coda.ValueType.String},
    transactionAmount: {type: coda.ValueType.String},
    transactionCurrency: {type: coda.ValueType.String},
    creditorName: {type: coda.ValueType.String},
    remittance: {type: coda.ValueType.String},
    account_type: {type: coda.ValueType.String},
    account_id: {type: coda.ValueType.String},
  },
  displayProperty: "internalTransactionId",
  idProperty: "internalTransactionId",
  identity: {
    name: "Transaction",
  },
});

// Formula to redirect the user to n8n, which will then redirect to Flutterflow
pack.addFormula({
  name: "RedirectToSignUp",
  description: "Signup for BankTables.",
  resultType: coda.ValueType.String,
  parameters: [],
  execute: async function ([], context) {
    return "LINK";
  },
});

// Formula to initiate email verification
pack.addFormula({
  name: "InitiateEmailVerification",
  description: "Initiates the email verification process by sending a verification code to the user's email.",
  resultType: coda.ValueType.String,
  parameters: [emailParameter],
  execute: async function ([email], context) {
    // Trigger the n8n flow to send a verification code to the user's email
    const response = await context.fetcher.fetch({
      method: "GET",
      url: `LINK/initiate_email_verification?email=${email}`,
    });
    const data = response.body;
    return data.message || "Failed to initiate email verification.";
  },
});

// Define the sync formula for transactions
const syncTransactionsFormula: coda.SyncFormulaDef<string, string, [typeof emailParameter, typeof verificationCodeParameter], typeof transactionSchema> = {
  name: "SyncTransactions",
  description: "Syncs transactions to a Coda table.",
  parameters: [emailParameter, verificationCodeParameter],
  execute: async function ([email, verificationCode], context) {
    const verifyResponse = await context.fetcher.fetch({
      method: "GET",
      url: `LINK/verify_email_code?email=${email}&code=${verificationCode}`,
    });
    const verifyData = verifyResponse.body;
    
    if (verifyData.verified !== true) {
        throw new Error("Verification code is incorrect.");
    }

    // Return the transactions data for syncing
    return verifyData.data;
  },
};

// Add the sync table to the pack
pack.addSyncTable({
  name: "Transactions",
  schema: transactionSchema,
  formula: syncTransactionsFormula,
  identityName: "Transaction",
});

Hi @Wayne_Simpson1 - I think the problem may be this:

return verifyData.data

When returning data from a sync table formula, you need to wrap it in an object, with the row data in the result key.

return {
  result: verifyData.data,
}
1 Like