Help for adding items to collection/database from external app?

Question:
Hey everyone, I don’t know much about coding but trying something simple with the help of AI… Adding names & scores to my collection/database via 3rd party tools (POST)

AI told me to create a backend “submitData.jsw”

// submitData.jsw
import wixData from 'wix-data';

export function addScore(player, score) {
  return wixData.insert("ScoreData", { player, score });
}

Also http-functions.js

// http-functions.js
import { ok, serverError } from 'wix-http-functions';
import { addScore } from 'backend/submitData.jsw';

export function post_addScore(request) {
  const { player, score } = request.query;
  if (player && score) {
    return addScore(player, parseInt(score))
      .then(() => ok({ "message": "Score added successfully!" }))
      .catch((error) => serverError({ "message": "Error adding score", "error": error }));
  } else {
    return serverError({ "message": "Missing player or score" });
  }
}

and to test via POSTMAN

  • Enter the API URL:
  • Set the URL to your Wix HTTP function. For example :
https://yourdomain.com/_functions/addScore
  • Add Query Parameters:
  • In the Params tab, add the following key-value pairs:
    • player: Enter the player name (e.g., JohnDoe)
    • score: Enter the score (e.g., 100)

I get 500 Internal Errors
and last time I tested I also got this
x-wix-function-user-error header missing exception

I thought it could be related to Oath but I could not manage to resolve it.

my database access is public, everyone can add

How can I add data to my collection with no authentication using post commands?
I have a game and using POST command I will add “player” & “score” that’s all I wanna do

Product:
Wix Studio

What are you trying to achieve:
Trying to add data to my collection with no authentication using post command.
I have a game and using POST command I will add “player” & “score” to my database called “ScoreData” that’s all I wanna do

What have you already tried:
tried many codes using backend function instructed by AI

Additional information:
[Include any other pertinent details or information that might be helpful for people to know when trying to answer your question.]

Hey Alper,

This super informative tutorial by @thewixwiz will show you how to set up HTTP functions on your website:

2 Likes

thank you for sharing these videos. Watching them

1 Like

Love these examples @Pratham :raised_hands:

@alperoz49 let us know how you get on and if you find a solution :slight_smile:


Side not, .web.js files are now used in favour of .jsw files in the backend - although it’s a more recent change, and I imagine most AI tools aren’t aware of this. Docs about it here if it’s any help :muscle: