Back

Error 400 for function

  • 0
  • Self Hosted
ZeroH
14 Nov, 2023, 12:12

I've hosted my function. When I visit the associated app write domain, I get the error Error 400 Execution error: No permissions provided for action 'execute'

Type

general_argument_invalid

What's the fix?

TL;DR
The user is receiving an error 400 with the message "Execution error: No permissions provided for action 'execute'". They are using a function that uses Express, but it won't interface with the Appwrite functions runtime. They'll need to use a function entrypoint like the examples in the provided link. Alternatively, they can write an adapter to call their Express handlers from the Appwrite runtime.
Haimantika
14 Nov, 2023, 12:19

Are the permissions added correctly?

ZeroH
14 Nov, 2023, 12:20

Yes. I gave the app write full access to all my GitHub repos. If that's what you mean

Haimantika
14 Nov, 2023, 12:20

It should be any

ZeroH
14 Nov, 2023, 12:21

What should be any ?

Haimantika
14 Nov, 2023, 12:21

What do you see here?

Haimantika
14 Nov, 2023, 12:21

The permission, under the settings tab

ZeroH
14 Nov, 2023, 12:24

It wasn't checked but I've set it as any. The page isn't loading anymore

Haimantika
14 Nov, 2023, 12:25

Can you refresh once again? Or try a little later and then let me know if that works?

ZeroH
14 Nov, 2023, 12:26

Alright

loks0n
14 Nov, 2023, 12:36

What do you see in the execution logs?

loks0n
14 Nov, 2023, 12:37

Are you able to share the code for the function?

loks0n
14 Nov, 2023, 12:37

What runtime version are you using?

ZeroH
14 Nov, 2023, 12:37

Just a moment Luke. Brb

ZeroH
14 Nov, 2023, 13:12

I see failed under status in the execution log. Here is the code for the function

TypeScript
import express, { Request, Response } from "express";
const app = express();
import "dotenv/config";
import helmet from "helmet";
import "express-async-errors";
import connectDB from "./db/connect";
import cors from "cors";
// accessRoute middleware
import { accessRoute } from "./middleware/accessRoute";
// error handler middleware
import { errorHandler } from "./middleware/errorHandler";
import { notFound } from "./middleware/notFound";
// routers
import authRouter from "./routes/auth";
import planRouter from "./routes/plan";
import payStackRouter from "./routes/paystack";
import profileRouter from "./routes/profile";

app.set("trust proxy", 1);

// cors
app.use(helmet());
app.use(
  cors({
    origin: [
      "http://localhost:3001",
      "http://127.0.0.1:5500",
      "http://localhost:5500",
    ],
  })
);

// body parsing middleware / other middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(errorHandler);

// routes
app.get("/", (req: Request, res: Response): void => {
  res.send("<h1>Hello World!</h1>");
});
app.use("/api/v1/auth", authRouter);
app.use("/api/v1/plan", accessRoute, errorHandler, planRouter);
app.use("/api/v1/paystack", payStackRouter);
app.use("/api/v1/profile", profileRouter);

// 404 error handler middleware
app.all("*", notFound);

const PORT = process.env.PORT || 3000;

app.listen(PORT, async (): Promise<void> => {
  if (typeof process.env.MONGO_URI === "undefined") {
    throw new Error("MONGO_URI is not defined");
  }
  await connectDB(process.env.MONGO_URI);
  console.log(`Server is running on port ${PORT}...`);
});

I'm using Node 18.x

loks0n
14 Nov, 2023, 13:24

Your function is using express which won't interface with our Appwrite functions runtime. You'll need to use a function entrypoint like seen in the examples here: https://appwrite.io/docs/products/functions/development#life-cycle

Alternatively, if you want to use express, you may be able to write some kind adapter to call your express handlers from our runtime.

loks0n
14 Nov, 2023, 13:24

cc @ZeroH

ZeroH
14 Nov, 2023, 13:26

Noted. I'll try to make the necessary changes.

loks0n
14 Nov, 2023, 13:31

I did see this project which uses HonoJS server with appwrite runtime, maybe it can help you https://github.com/kit-t/lhci-server-appwrite/tree/main/functions/lighthouse-server/src

ZeroH
14 Nov, 2023, 13:32

I'll give this a read. Thanks

loks0n
14 Nov, 2023, 13:33

No worries! Good luck with your project <:appwriterocket:823996226894692403>

Haimantika
14 Nov, 2023, 13:35

Thanks for the help @Madhawa. @ZeroH feel free to ping us if the problem still exists 🙂

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more