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
  • 6,387
  • 3
  • 41
  • 56
Aragorn
  • 5,021
  • 5
  • 26
  • 37

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
  • 9,516
  • 1
  • 18
  • 27
  • .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
  • 216,225
  • 63
  • 350
  • 396