Click here to Skip to main content
14,495,113 members
Rate this:
Please Sign up or sign in to vote.
See more:

I have below code which is working fine for GET and POST but not for PUT in node js. I am using method overloading for GET and PUT. Below is my app.js code.

import { Router } from 'express';
const AuthRoutes = Router();
const AppRoutes = Router();
AuthRoutes.get('/customer/:customername', getCustomerbyname);'/calculate/:id', calculate);
AuthRoutes.put('/customer/:customername', saveCustomer);

Here my GET and POST is working fine but for PUT its giving me error. Below URL I am trying for PUT.


I dont know what I am missing here.

>Error - You don't have permission to access /domainname/customer/abc

Can you please help me if I am missing something here.Basically I am trying to do a PUT request by providing customer name in URL and other details in BODY section of request. So if customer with name exist, it will update it otherwise create it newly.

What I have tried:

Not sure why exactly this error. GET and POST is working fine.
Updated 24-Feb-20 23:03pm
Telstra 24-Feb-20 11:40am
Even if now I have changed PUT url to saveCustomer but still same error.
Kris Lantz 25-Feb-20 10:56am
Doesn't each type of request require the respective permission to do so? Have you verified that you have the permission to PUT?
Telstra 25-Feb-20 11:06am
So far I was doing only GET and POST. This is first service I am doing with PUT. I am following same code flow except change in HTTP verb. Still it says no permission. Do I need to install any NPM package for PUT
Kris Lantz 25-Feb-20 11:15am
There's no new packages to grab, and the verbage change from POST to PUT is usually the requirement, but I seem to recall that (in the little bit of web dev I did in college) that the account making the request had to have explicit permissions.
Telstra 25-Feb-20 11:22am
That account has a permission. Because it is already posting a data to service with no issues. Only PUT is not working.
Kris Lantz 25-Feb-20 11:46am
Your PUT command is creating a brand new resource; a new customer. From an operation standpoint, put and post are not the same.
Two of the API's I use daily allow me to post information, but I am not permitted to send those same requests with a 'put' command; I don't have permission.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100