Giuseppe Parrello

 

Come inviare un evento IFTTT


In questa pagina fornisco i codici script allo scopo di inviare un evento IFTTT. Prego tener conto dei seguenti requisiti:

Assicuratevi di tenere per voi gli URL di webhook, non condivideteli sui social network, poiché chiunque può utilizzare l'URL per avviare la vostra applet IFTTT.


Linguaggio Bash

#!/bin/bash

apikey=""
event="button_pressed"
value1="My value 1"
value2="My value 2"
value3="My value 3"

request_body=$(cat <<EOF
  {
  "value1": "$value1",
  "value2": "$value2",
  "value3": "$value3"
  }
EOF
)

echo $request_body

header="Content-Type: application/json"

/opt/bin/curl -v -i -X POST -H "$header" -d "$request_body" "https://maker.ifttt.com/trigger/$event/with/key/$apikey"

 

Linguaggio PHP

<?php

$apikey = "";
$event  = "button_pressed";
$value1 = "My value 1";
$value2 = "My value 2";
$value3 = "My value 3";

$ch = curl_init();

$postdata = json_encode([
                         "value1" => $value1,
                         "value2" => $value2,
                         "value3" => $value3,
                         ]);

$header = array();
$header[] = "Content-Type: application/json";

curl_setopt($ch,CURLOPT_URL, "https://maker.ifttt.com/trigger/$event/with/key/$apikey");
curl_setopt($ch,CURLOPT_HTTPHEADER, $header);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($ch);

print_r($result);
print_r("\r\n\r\n");

curl_close($ch);
?>

 

Linguaggio Python

import requests

apikey = ""
event  = "button_pressed"
value1 = "Test001-value1"
value2 = "Test001-value2"
value3 = "Test001-value3"

url     = "https://maker.ifttt.com/trigger/%s/with/key/%s" % (event, apikey)
payload = { "value1" : value1, "value2" : value2, "value3" : value3 }
headers = {}
res     = requests.post(url, data=payload, headers=headers)