Error 404 "Not Found" when creating developer product

Okay so basically I’m doing a custom donations system following the Custom Developer Products tutorial, but when I try to create a developer product for my game, my glich app shows an error in console and the product isn’t created.


I don’t know how to solve this because I don’t know much JavaScript, so does anyone have any idea of how can I solve this? I found an image showing the type of errors that Noblox.js can throw, and I think the type of error is “Shop Id Not Found”, but I really have no idea.
image
Any help is appreciated, thanks.

Btw sorry if my english is bad.

2 Likes

Hi,

first, I suggest using the Scripting Support category when asking for help fixing something next time as this category is more focused on optimization, and improvements,…

Could you please show us your code, so we can see what you are doing wrong, also 404 means that something is missing, I am assuming (because I don’t see your code) that you are trying to create a product under a non-existing universe.

1 Like

I found out that I was getting the error because the Noblox.js module is outdated and it doesn’t reaches the new endpoints of Roblox Api. Anyway, here is my game code:

--!strict
local price = math.random(1000000)
local httpService = game:GetService("HttpService")
local url = "https://custom-robux-donations.glitch.me/requestProduct"
local res = httpService:RequestAsync({
	Url = url,
	Method = "POST",
	Headers = {
		["Content-Type"] = "application/json"
	},
	Body = httpService:JSONEncode({
		["universeId"] = 3757333888,
		["name"] = price,
		["price"] = price,
	});
})
print(res)

And here is my Glitch app code:

const express = require("express");
const rbx = require("noblox.js");

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

const port = process.env.PORT || 8080;
const serverKey = process.env.SERVERKEY || "";
const cookie = process.env.COOKIE || "";
const productCacheName = "./products.json";

const cookieRefreshInterval = 1 * 1000 * 60 * 60 * 24 * 0.5;

app.post("/requestProduct", function (req, res, next) {
  const universeId = parseInt(req.body.universeId);
  const name = req.body.name;
  const price = parseInt(req.body.price);

  if (universeId != serverKey) {
    console.log("Invalid server key supplied. Server key is " + serverKey + " and supplied key is " + universeId);

    return res.status(403).json({
      error: "You do not have permission to use this.",
    });
  }

  var productCache = require(productCacheName);
  var productId = productCache[price.toString()];

  if (productId) {
    return res.status(200).json({
      message: "[" + universeId + "] Product found " + name + " for " + price + " Robux.",
      productId: parseInt(productId),
    });
  }

  const args = {
    universeId: universeId,
    name: name,
    priceInRobux: price,
  };

  rbx.addDeveloperProduct(args).then(function (productDetails) {
      productId = productDetails.productId;

      productCache[price.toString()] = parseInt(productId);

      console.log("[" + universeId + "] Created product " + name + " for " + price + " Robux.");

      return res.status(200).json({
        message:"[" + universeId + "] Created product " + name + " for " + price + " Robux.", productId: parseInt(productId)});
    })
    .catch(function (err) {
      console.log("[" + universeId + "] Failed to create product " + name + " for " + price + " Robux: " + err.message);

      return res.status(400).json({
        error: err.message,
      });
    });
});

app.get("/*", function (req, res, next) {
  return res.status(200).json({});
});


async function cookieLogin(defaultCookie) {

  if (defaultCookie) {
    try {
      const isValidCookie = await rbx.setCookie(defaultCookie);

      if (isValidCookie) {
        return;
      } else {
        throw new Error("Invalid or expired");
      }
    } catch (err) {
      console.error(`Use of supplied cookie failed: ${err}`);
    }
  }

  throw new Error(
    "Cookie login failed, supplied and stored cookies are either missing or invalid."
  );
}

function logIn(newCookie) {
  cookieLogin(newCookie).then(function () {
      rbx.getCurrentUser({ option: "UserName" }).then(function (username) {
        console.log(`Logged in as ${username}`);
      });

      console.log(`Listening on port ${port}`);

      return app.listen(port);
    }).catch(function (err) {
      console.error(`Failed to log in. Error: ${err.message}`);

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

      errorApp.get("/*", function (req, res, next) {
        res.status(503).json({
          error: `Failed to log in. Error: ${err.message}`,
        });
      });

      return errorApp.listen(port);
    });
}

const server = logIn(cookie);

1 Like

That explains a lot, could you update to the latest Noblox.js version as the current version supports the new endpoints?

1 Like

I’m currently using the latest versino of Noblox.js, but it doesn’t work yet. I barely know nothing of JavaScript, but I know Noblox.js right now uses the a deprecated endpoint of develop.roblox.com to create developer products. However, I think the right endpoint is apis.roblox.com/developer-products/v1/universes/{universeId}/developerproducts, but I don’t want to try the base code of my glitch app because I don’t wanna mess it up.

Edit: I checked noblox github page and, indeed, it has been updated. I don’t know why I’m not up to date with that, but I’ll try to fix my code. Thanks.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.