0

I'm trying to make a simple PUT call to google sheets API. I followed some of the http.put syntax, but keep getting the error: this.http.put(...).map is not a function.

My code block:

return this.http
           .put(url, JSON.stringify(data), {headers: headers})
           .map(
                (res: any) => {
                   res.json();
                   console.log ("transaction data updated to google seets:"+res.json());
                }
           );
M.javid
  • 5,881
  • 3
  • 38
  • 54
Aragorn
  • 4,534
  • 3
  • 25
  • 35

2 Answers2

1

Are you using HTTPClient Module?. Here is the Way of Performing PUT method which is similar to POST method.

return this.http.put<Hero>(this.heroesUrl, data, httpOptions)
    .pipe(
      map(res => {
         console.log(res);
         return res;
      },
      catchError(this.handleError('updateHero', hero))
    );
Suresh Kumar Ariya
  • 8,892
  • 1
  • 16
  • 25
  • .pipe(map(..)) made the error go away, I'm still getting 401 though, but that's a different error and I think I can work that out. Thanks – Aragorn Sep 30 '18 at 14:21
1

Did you import ?

import { map } from 'rxjs/operators';

EDIT

You need to import the above, also i would recommend you to use HttpClient instead of HttpModule which would remove the res.json(), your code will look like,

set the options as,

return this.http.put(url, JSON.stringify(formData), this.options)
.pipe(map(response => response.json()));
Sajeetharan
  • 203,447
  • 57
  • 330
  • 376