api/permissions DELETE (Does not work for external request).

Mateuus4 years ago

Hi.
I am creating an application and need to remove a notification assigned to a device.

API
api/permissions

Basic Auth
Admin Account

Method POST works.
but method DELETE is not working.

my default.xml
<entry key='web.origin'>*</entry>

Is working "POST"
let permissiondata = {deviceId: this.device.id, notificationId: notification.id}; this.traccarApi.permissionsPost(permissiondata,"body").toPromise();

is not working "DELETE"
let permissiondata = {deviceId: this.device.id, notificationId: notification.id}; this.traccarApi.permissionsDelete(permissiondata,"body").toPromise();

I made a request on this site reqbin.com and POST works again, but DELETE does not work.

I'm forgetting something?

Anton Tananaev4 years ago

What's the response?

Mateuus4 years ago

Status:
400 (Bad Request)
NullPointerException(Permission: 33 < PermissionsResource: 74 < ...)

Anton Tananaev4 years ago

Looks like your request is incorrect. Please provide full HTTP request that you are sending.

Mateuus4 years ago

full code: https://pastebin.com/4jukwVt9

public permissionsDelete(body: Permission, observe?: 'body', reportProgress?: boolean): Observable<any>;
public permissionsDelete(body: Permission, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
public permissionsDelete(body: Permission, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
public permissionsDelete(body: Permission, observe: any = 'body', reportProgress: boolean = false ): Observable<any> {

    if (body === null || body === undefined) {
        throw new Error('Required parameter body was null or undefined when calling permissionsDelete.');
    }

    let headers = this.defaultHeaders;

    // authentication (basicAuth) required
    if (this.configuration.username || this.configuration.password) {
        headers = headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password));
    }

    // to determine the Accept header
    let httpHeaderAccepts: string[] = [
        'application/json'
    ];
    const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
    if (httpHeaderAcceptSelected != undefined) {
        headers = headers.set('Accept', httpHeaderAcceptSelected);
    }

    // to determine the Content-Type header
    const consumes: string[] = [
        'application/json'
    ];
    const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
    if (httpContentTypeSelected != undefined) {
        headers = headers.set('Content-Type', httpContentTypeSelected);
    }

    return this.httpClient.delete<any>(`${this.basePath}/permissions`,
        {
            withCredentials: this.configuration.withCredentials,
            headers: headers,
            observe: observe,
            reportProgress: reportProgress
        }
    );
}
Mateuus4 years ago
Anton Tananaev4 years ago

Are you going to provide HTTP request?

BerndFfm4 years ago

Mateuus :

Video unavailable
This video is private.

Mateuus4 years ago

Anton Tananaev
Sorry, I'm a little confused. Do you want the result of the request? or the http request code?
http request code: https://pastebin.com/5b7aurGX

I just put the public video.
https://www.youtube.com/watch?v=kT3Ezw0tAII

in the video I'm using eqbin.com to send an http request. to test themethod 'post' works, but 'delete' is not working. using the http://demo.traccar.org/api

Mateuus4 years ago
Mateuus4 years ago

Thanks for the help, I managed to fix it here.

 public apiPermissionsDelete(deletePerm: any) {
    let headers = this.defaultHeaders;

    // authentication (basicAuth) required
    if (this.configuration.username || this.configuration.password) {
        headers = headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password));
    }

    // to determine the Accept header
    let httpHeaderAccepts: string[] = [
        'application/json'
    ];
    const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
    if (httpHeaderAcceptSelected != undefined) {
        headers = headers.set('Accept', httpHeaderAcceptSelected);
    }

    // to determine the Content-Type header
    const consumes: string[] = [
        'application/json'
    ];
    const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
    if (httpContentTypeSelected != undefined) {
        headers = headers.set('Content-Type', httpContentTypeSelected);
    }

    // authentication (basicAuth) required
    if (this.configuration.username || this.configuration.password) {
        headers = headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password));
    }

    const options = {
        headers: headers,
        body: {
          deviceId: deletePerm.deviceId,
          notificationId: deletePerm.notificationId,
        },
      };
      
      this.httpClient
        .delete(`${this.basePath}/permissions`, options)
        .subscribe((s) => {
          console.log(s);
        });
 }