0

I'm trying to call a Firebase Cloud Function from my React Native Expo app to send invoice emails. The function deploys successfully, but when I call it from the app, I get a FirebaseError: not-found error. Cloud Function (functions/index.js):

const functions = require('firebase-functions');
const express = require('express');
 const nodemailer = require('nodemailer');

 const sendInvoiceToXeroApp = express();
sendInvoiceToXeroApp.use(express.json());

 sendInvoiceToXeroApp.post('/', async (req, res) => {
    res.set('Access-Control-Allow-Origin', '*');
   res.set('Access-Control-Allow-Methods', 'POST, OPTIONS');
   res.set('Access-Control-Allow-Headers', 'Content-Type');

    if (req.method === 'OPTIONS') {
     res.status(204).send('');
      return;
   }

    const { invoiceData, signatureBase64, testEmail } = req.body;

  // Email sending logic here...

   res.status(200).json({ success: true });
  });

    exports.sendInvoiceToXero = functions.https.onRequest(sendInvoiceToXeroApp);

React Native Component:

  import { getFunctions, httpsCallable } from 'firebase/functions';

 const submitInvoice = async () => {
  try {
   const functions = getFunctions();
   const sendInvoice = httpsCallable(functions, 'sendInvoiceToXero');

  const result = await sendInvoice({ 
    invoiceData, 
    signatureBase64: signature,
    testEmail: '[email protected]'
    });

    console.log('Success:', result.data);
  } catch (error) {
    console.error('Error submitting invoice:', error);
    // ERROR: [FirebaseError: not-found]
   }
 };

What I've tried:

Deployed the function successfully with firebase deploy --only functions:sendInvoiceToXero Function shows as deployed in Firebase Console Verified Firebase config in app matches project Checked Firebase Functions region (using default us-central1)

The Error is this

ERROR Error submitting invoice: [FirebaseError: not-found]

Questions:

Why would the function be deployed but return "not-found" when called from the app? Do I need to configure something specific for Express-based Cloud Functions? Could this be a region mismatch issue between the app and function?

Firebase SDK versions:

firebase: 10.x @react-native-firebase/app: 21.x firebase-functions: 6.x (in Cloud Functions)

Any help would be appreciated!

1 Answer 1

0

You're trying to invoke an HTTP type function using the callable API. This isn't going to work. I strongly suggest reviewing those documentation links, and also understand the difference between http and callable functions. In order to proceed, you must make a choice:

  1. If you want to use a callable, write a callable type function (onCall) using the example in the documentation. You won't be able to use an express app for this.

  2. Don't use the callable API on the client, and instead make a normal HTTP request using the library of your choice (such as the native JavaScript fetch API).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.