Search code examples
angulartypescriptwebhooksifttt

POST to IFTTT using Angular 2


I am trying to send a http POST to https://maker.ifttt.com/trigger/event_name/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxx using a IFTTT maker webhook using Angular 2.

The request is being received but the body is not.

  post(): Promise<string> {
let headers = new Headers({ 'Content-Type': 'application/json'});
let options = new RequestOptions({ headers: headers });
console.log(options)
let body = { "value1": "21223232"};
console.log(body)
return this.http.post(this.webhookUrl, body, options)
         .toPromise()
         .then(this.extractData)
         .catch(this.handleError);

There should be value1: 21223232 and printable with {{Value1}} but I am getting no luck.

Also worth noting:

curl -X POST -H "Content-Type: application/json" -d '{"value1":"21223232"}' https://maker.ifttt.com/trigger/event_name/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxx

works

Has anyone experienced this before?


Solution

  • I finally solved this using

    let headers = new Headers({ 'Content-Type': 'application/json' });
    let body = new FormData();
    body.append('value1', "21223232");
    return this.http.post(this.webhookUrl,body,headers)
             .toPromise()
             .then(this.extractData)
             .catch(this.handleError);
    

    This is using Ionic 2 FormData()