Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

477
Visualizações
Make Shopify API Post Request using Next.js and Koa Router (405 Method not allowed)

I'm not sure if this is a Shopify related issue or a general coding issue, but when I send a request to the API for Next.js or how Shopify has exemplified, I get a 405 error. I am using Koa Router (that was what Shopify has prebuilt with their Auth boilerplate setup) and MongoDB.

server.js

import addTest from "../helpers/add";

...

      router.post("/api/add", async (ctx) => {
        try {
          /* Get the shop from the authorization header to prevent users from spoofing the data */
          shopDomain = await getShopUrlFromSession(ctx.req, ctx.res);
          if (shopDomain) {
            addTest(ctx.req, ctx.res);
          }
          res.status(201).send(response[0]);
        } catch (error) {
          res.status(500).send(error.message);
        }
      });

add.js

    import connectMongo from "../../../utils/connectMongo";
    import { Shopify } from "@shopify/shopify-api";
    import Test from "../../../models/testModel";
    export default async function addTest(req, res) {
      try {
        console.log("CONNECTING TO MONGO");
        await connectMongo();
        console.log("CONNECTED TO MONGO");
        const session = await Shopify.Utils.loadCurrentSession(req, res, true);
        const client = new Shopify.Clients.Graphql(
          session.shop,
          session.accessToken
        );
        const shopId = `https://${session.shop}`;
        console.log("CREATING DOCUMENT");
        const test = await Test.create(req.body);
        console.log("CREATED DOCUMENT");
        res.json({ test });
      } catch (error) {
        console.log(error);
        res.json({ error });
      }
    }
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda