0

Hey I'm using Directus with Ionic 3 for browser and I got a problem with HTTP PUT.

The error:

error: {code: 6, message: "Method Not Allowed"}

proto: Object

headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}

message: "Http failure response for http://example.com/backend/api/public/_/users?single=1&access_token=myToken&filter[id]=50: 405 Method Not Allowed"

name: "HttpErrorResponse"

ok: false

status: 405

statusText: "Method Not Allowed"

url: "http://example.com/backend/api/public/_/users?single=1&access_token=myToken&filter[id]=50"

This my code:

    updatePwd(user:any, userId: any){
    return this.api.put('users?single=1&access_token=myToken&filter[id]='+userId,user).map((res: any) => {
      return res;
    });
  }

The POST and GET work good like that

    newUser(user:any){
    return this.api.post('users?access_token=myToken',user).map((res: any) => {
      return res;
    });
  }

getUser(email:any){
    return this.api.get('users?single=1&access_token=myToken&filter[email]='+email).map((res: any) => {
      return res;
    });
  }

I'm new user of Directus and I don't know much about it. So what the problem here? I must config something or what?

Thanks in advance :)

Edit: I tried with PATCH and It works fine ^^

    updatePwd(userId: any, user:any){
    return this.api.patch('users/'+userId+'?&access_token=myToken',user).map((res: any) => {
      return res;
    });
  }
Ragnar Lodbrok
  • 163
  • 1
  • 3
  • 16
  • That may be a security setting on the web server you are trying to connect to. I don't know about other services, but I've worked with IIS in the past, and by default the PUT and DELETE HTTP verbs are blocked. You may need to contact whoever is in charge of the server to open that up for you. Or if you're the one setting up the server, update the settings to allow PUT and DELETE. – CodeMonkey Jan 23 '19 at 17:42
  • @CodeMonkey thanks for your reply, I'm the one setting up the server but how to allow PUT and DELETE please?? – Ragnar Lodbrok Jan 23 '19 at 17:57
  • Depends on the server you are using. If you're using .NET on IIS, check [this issue](https://stackoverflow.com/questions/12440277/how-do-i-enable-http-put-and-delete-for-asp-net-mvc-in-iis) and if it's apache, [try this](https://stackoverflow.com/questions/37484888/enable-put-and-delete-methods-on-apache-2-4) – CodeMonkey Jan 23 '19 at 18:45
  • 1
    @CodeMonkey Thanks, I will try this solution and I will come back ^^ – Ragnar Lodbrok Jan 23 '19 at 19:03
  • 1
    @CodeMonkey Hey, I tried Rijk reply and It works for me thank u both ^^ – Ragnar Lodbrok Jan 26 '19 at 17:33

1 Answers1

3

Directus uses PATCH instead of PUT for updating rows: https://docs.directus.io/api/reference.html#update-user

Rijk
  • 939
  • 7
  • 17