How do i set temperature by using plain REST not firebase api - nest-api

I could not find any information on how to set the target temperature or set Away mode. Has anyone successfully gotten it to work?
https://developer-api.nest.com/devices.json?auth=asdasdasd
^ Provides the information but how do we modify the temperature or away mode??

Keep the auth in the querystring, and PUT the JSON-formatted change to the appropriate endpoint. eg (PHP):
To set target temperature:
$ch = curl_init("https://developer-api.nest.com/devices/thermostats/$THERMOSTAT_ID?auth=$AUTH");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"target_temperature_c": 21.5}');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);
To set Away mode:
$ch = curl_init("https://developer-api.nest.com/structures/$STRUCTURE_ID?auth=$AUTH");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"away":"away"}');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
echo curl_exec($ch);

Related

Telegram bot on IIS: sendPhoto is not working

function sendTelegramSMS($text,$tgimage) {
$botToken="tokenCODE";
$website="https://api.telegram.org/bot".$botToken;
$chatId='1242433';
//image
$params=[
'chat_id'=>$chatId,
'text'=> $text,
'photo'=> '#'.$tgimage,
];
$ch = curl_init($website . '/sendPhoto');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
//message
$params=[
'chat_id'=>$chatId,
'text'=> $text,
];
$ch = curl_init($website . '/sendMessage');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, ($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
}
$thefile= '/auth/prova.png';
sendTelegramSMS($reservation,$thefile);
This code works for sending messages (//message part), but doesn't work to send photos (//image part)...
i've tried a bounch of directory structure, nothing happen.
Hosted on Win10 with IIS.

Docusign download unsigned enveloppe with tabs

Hello I'm using the docusign rest api and I have a use case where I must download an envelope document in pdf for manual signing the problem is when an envelope isn't signed I get the envelope document empty (without pre-filled fields) but when it's signed I get the document with all the fields,
the result expected is the document with all pre-filled fields.
Here is my code:
$curl = curl_init($loginInfo['baseUrl'] . "/envelopes/" . 'f487cf56-3a07-4cd3-ace7-XXXXXXXXXXXX' . "/documents" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
curl_close($curl);
//var_dump($xml);
//
// STEP 3 - download the documents
//
foreach( $response["envelopeDocuments"] as $document ) {
print_r($document);
$docUri = $document["uri"];
$curl = curl_init($loginInfo['baseUrl'] . $docUri );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"X-DocuSign-Authentication: $header" )
);
$data = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
file_put_contents('f487cf56-3a07-4cd3-ace7-XXXXXXXX' . "-" . $document["name"], $data);
curl_close($curl);
Thank you !
For people searching, you can't do it until the envelope is completed, the fields aren't attached to the document until it's signed.

Fetching signature image for logged in user using docusign rest api

I have a project in which I have created a form containing fileds:-
1.) Name
2.) Signature
In signature column there is button "Add Signature" when click on button it opens popup to enter docusign email and password. Once click on login it get's signature image url of the user. But the problem with my code is I am not getting image.
My issue is I want to display signature image after authentication in my project. Please suggest me what is wrong in my code.
My project url is:-
http://surgimedik.esoftech.in/out/out.AddDocument.phpfolderid=1&showtree=1#popup1
admin / admin
You can check below url where I am getting image url. when you hit it it asks for login itstead of showing image.
http://surgimedik.esoftech.in/docusign/test.phpemail=akash#esoftech.org&pwd=Terminate#12345
<?php
$email = $_REQUEST["email"];
$password = $_REQUEST["pwd"];
$integratorKey = '4a394221-7742-4f39-8a90-9021732676e8';
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
$url = "https://demo.docusign.net/restapi/v2/login_information?include_account_id=true";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status != 200) {
echo "error calling webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$userId = $response["loginAccounts"][0]["userId"];
curl_close($curl);
$url_sig = "https://demo.docusign.net/restapi/v2/accounts/$accountId/users/$userId/signatures";
$curl_sig = curl_init($url_sig);
curl_setopt($curl_sig, CURLOPT_HEADER, false);
curl_setopt($curl_sig, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_sig, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response1 = curl_exec($curl_sig);
$status_sig = curl_getinfo($curl_sig, CURLINFO_HTTP_CODE);
if ($status_sig != 200) {
echo "error calling webservice, status is:" . $status_sig;
exit(-1);
}
$response1 = json_decode($json_response1, true);
$signatureId = $response1["userSignatures"][0]["signatureId"];
$url_sig1 = "https://demo.docusign.net/restapi/v2/accounts/$accountId/users/$userId/signatures/$signatureId";
$curl_sig1 = curl_init($url_sig1);
curl_setopt($curl_sig1, CURLOPT_HEADER, false);
curl_setopt($curl_sig1, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_sig1, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response11 = curl_exec($curl_sig1);
$status_sig1 = curl_getinfo($curl_sig1, CURLINFO_HTTP_CODE);
if ($status_sig1 != 200) {
echo "error calling webservice, status is:" . $status_sig1;
exit(-1);
}
$result = json_decode($json_response11);
echo "https://appdemo.docusign.com" . $result->signatureImageUri;
You are using the wrong api.
Use the getImageUserSignatures api
GET /v2/accounts/{accountId}/users/{userId}/signatures/{signatureId}/signature_image

Import .pbix (power BI) file into the workspace using php (multipart form-data post)

I want to import local pbix fle to created workspace in azure power bi account. I already created workspaceId using REST API. However when i try to import pbix file that gives 200 ok status instead of 202 accepted response with Id.
Here is the reference code i followed enter link description here
POST https://api.powerbi.com/v1.0/collections/mypbiapp/workspaces/32960a09-6366-4208-a8bb-9e0678cdbb9d/imports?datasetDisplayName=mydataset01
Authorization: AppKey MpaUgrTv5e... Content-Type: multipart/form-data;
boundary="A300testx"
--A300testx Content-Disposition: form-data
{the content (binary) of .pbix file}
--A300testx--
I used php curl request to called Rest API and below shows the code which i tried,
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.powerbi.com/v1.0/collections/XXXXXX/workspaces/XXX-XXX-XXX-XXXXXXXX/imports?datasetDisplayName=mydataset01');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postData = array(
'datafile' => '#C:\Users\Desktop\report1.pbix',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
"Authorization: AppKey R97v4Fe5=="
) );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
echo $response = curl_exec($ch);
curl_close ( $ch );
As a response I'm getting status code as 200 ok with json
{"id":"0331a80d-6f23-4626-9624-1f6b98ce373a"}
However this new dataset was not created in workspaceID. Please help me to find the issue here.
Here is the answer for multipart form-data post with php curl, This code works for me
$name = 'report1';
$file = 'report1.pbix';
$boundary = "----------BOUNDARY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.powerbi.com/v1.0/collections/XXXXXX/workspaces/XXX-XXX-XXX-XXXXXXXX/imports?datasetDisplayName=mydataset01');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postdata .= "--" . $boundary . "\r\n";
$postdata .= "Content-Disposition: form-data; name=\"" . $name . "\"; filename=\"" . $file . "\"\r\n";
$postdata .= "Content-Type: application/octet-stream\r\n\r\n";
$postdata .= file_get_contents($file);
$postdata .= "\r\n";
$postdata .= "--" . $boundary . "--\r\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, $$postdata);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array (
"Authorization: AppKey R97v4Fe5==",
'Content-Type: multipart/form-data; boundary='.$boundary,
'Content-Length: ' . strlen($postdata)
) );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
echo $response = curl_exec($ch);
curl_close ( $ch );
Here is a ready to use version of the given solution
public function import($access_key, $workspace_collection_name, $workspace_id, $file_path, $file_name, $display_name, $nameConflict = 'Overwrite')
{
$boundary = "----------BOUNDARY";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.powerbi.com/v1.0/collections/$workspace_collection_name/workspaces/$workspace_id/imports?datasetDisplayName=$display_name&nameConflict=$nameConflict");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postdata = '';
$postdata .= "--" . $boundary . "\r\n";
$postdata .= "Content-Disposition: form-data; name=\"" . $file_name . "\"; filename=\"" . $file_path . "\"\r\n";
$postdata .= "Content-Type: application/octet-stream\r\n\r\n";
$postdata .= file_get_contents($file_path);
$postdata .= "\r\n";
$postdata .= "--" . $boundary . "--\r\n";
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: AppKey " . $access_key,
'Content-Type: multipart/form-data; boundary=' . $boundary,
'Content-Length: ' . strlen($postdata)
));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
if (curl_error($ch)) {
return 'curl error';
}
curl_close($ch);
return $response;
}

Clickbank api for getting the receipt information

I have tried creating a small class for clickbank which fetches the receipt information from the clickbank. I thought, it might be helpful for someone. In function get_payment_info($tries, $receipt) tries has been used because clickbank doesn't recognize transaction immediately after it happens.
<?php
define('CLICKBANK_DEV_KEY','DEV-KEY');
define('CLICKBANK_API_KEY','API-KEY');
Class ClickBank
{
/*
* $tries how many times to check for receipt
* because when you come back from clicbank it sometimes shows it invalid
*
* $receipt
*
* #return empty array if receipt not valid
* receipt info array if receipt is valid
*/
function get_payment_info($tries, $receipt){
$receipt_info = array();
while($tries>0 && count($receipt_info)==0){
$receipt_info = $this->get_receipt_info($receipt);
$tries--;
}
return $receipt_info;
}
function get_receipt_info($receipt){
$receipt_info = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.clickbank.com/rest/1.2/orders/$receipt");
curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_GET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Authorization:".CLICKBANK_DEV_KEY.":".CLICKBANK_API_KEY));
$result = curl_exec($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
if($curl_info['http_code']==200){
$receipt_info = json_decode($result);
}
return $receipt_info;
}
}
$clickbank = new ClickBank();
$receipt = $_GET['cbreceipt'];
// it will return you transaction details
$transaction_info = $clickbank->get_payment_info(10, $receipt);

Resources