0

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?

Scott Condron
  • 1,902
  • 16
  • 20

2 Answers2

0

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()

Scott Condron
  • 1,902
  • 16
  • 20
0

I think it would be cleaner as an observable, and or an @.ajax request.

data = new FormData().append();

$.ajax(
                {
                    'url' : targetUrl,
                    'crossDomain': true,
                    'type': 'POST',
                    'data': data
                }
            ).done(function (rsp) {
                //..code
            }).fail(function (rsp) {
                Error();
            }); 
James Warren
  • 3
  • 1
  • 6