Get Calendly Scheduled Appointments with Webhook Data - json

There's very few post here regarding Calendly so hopefully somebody can help with this issue. Below is the code I'm using and the issue is that Calendly only returns the webhook subscription data, not the actually appointments that customers schedule.
I want to receive data as described on their page here: https://developer.calendly.com/docs/sample-webhook-data but I only get webhook subscription data back, not the scheduled appointments.
$url = 'https://calendly.com/api/v1/hooks';
$webhook_url = 'MY URL HERE';
$curl_data = 'url='.$webhook_url.'&events[]=invitee.created&events[]=invitee.canceled';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS,$curl_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"X-TOKEN: MY TOKEN ID HERE"
));
$result = curl_exec($ch);
echo $result;
curl_close($ch);
//print_r(json_decode($result, true));<br><br>
$content = trim(file_get_contents("php://input"));<br>
$decoded = json_decode($content, true);<br><br>
echo $decoded;<br>
{"data":[{"type":"hooks","id":380871,"attributes":{"url":"MY URL HERE","created_at":"2019-04-17T11:07:36Z","events":["invitee.created","invitee.canceled"],"state":"active"}}]}

Once you set up your webhook, Calendly will send a POST request to your webhook URL. In other words, once an invitee books or cancels an invite, your webhook URL will receive the payload from Calendly for that specific event.
Webhooks are a little different from API endpoints. An API provides data at the time you send a request; e.g., "Give me a list of all of my users". Conversely, a webhook acts as a listener to some topic and is event-based; e.g., "Tell me when an invitee has booked a meeting (and tell me about the meeting).
Are you looking to get a list of all invitees/meetings? If so, we don't have an API endpoint for that now, but we'd love to hear what you're looking for and how we can help. You can reach out to us here (reference my name and I'll be able to sync up on your request).

Related

Understanding Microsoft api response for office 365

I'm trying to retreive information from MS Office 365 resource Calendar.
I use code shown below, and get a string returned. I would like to get it as a JSON feed. or array if JSON is not possible, as I plan to show the result on a 'fullcalendar'
Anyone know the trick.?
CODE:
$username = 'user#domain.com'; // User with delegate control.
$password = 'P#ssword';
$calendar = 'ressourceRoom#domain.com';
$URL = 'https://outlook.office365.com/api/v1.0/users/'.$calendar.'/calendarview?startDateTime=05/30/2016&endDateTime=06/13/2016';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$result= (curl_exec ($ch));
curl_close ($ch);
echo gettype($result)."<br /><br /><br />";
print_r($result);
RESULT (just beginning shown).:
string
{"#odata.context":"https://outlook.office365.com/api/v1.0/$metadata#Users('room#domain.com')/CalendarView","value":[{"#odata.id":"https://outlook.office365.com/api/v1.0/Users('room#domain.com')/Events('AAMkADBiMmM3NjE5LTUyMDUtNDY0Mi1hNjAyLTY2M2ZlYmM3OTkwOQBGAAAAAAAnzkQlYPmYQ4MtD6sjQqO8BwAaVyh143FwQZzopix2q_v7AAAAAAENAAAaVyh143FwQZzopix2q_v7AAAAAA0eAAA=')","#odata.etag":"W/\"GlcodeNxcEGc6KYsdqvr+wAAAAAMVg==\"","Id":"AAMkADBiMmM3NjE5LTUyMDUtNDY0Mi1jAyLTY2M2ZlYmM3OTkwOQBGAAAAAAAnzkQlYPmYQ4MtD6sjQqO8BwAaVyh143FwQZzopix2q_v7AAAAAAENAAAaVyh143FwQZzopix2q_v7AAAAAA0eAAA=","DateTimeCreated":"2016-06-06T12:07:57.398966Z","DateTimeLastModified":"2016-06-06T12:07:57.8833477Z","ChangeKey":"GlcodeNxcEGc6KYsdqvr+wAAAAAMVg==","Categories":[],"StartTimeZone":"Romance Standard Time","EndTimeZone":"Romance Standard Time","ResponseStatus":{"Response":"Accepted","Time":"2016-06-06T12:07:57.6489687Z"},"iCalUId" ....
The HTTP response you get from the Office 365 REST already return the JSON format string. Based on the code, it seems you were developing with PHP. We need to convert the JSON format string to the JSON object via the library based on the language we were developing.
For example, we can use json_decode($string) to convert String into Array/Object in PHP. Refer to here for more detail.

Subscription Profiles not supported by Recurring Payment APIs while updating plan price

I am using paypal api for recurring billing. i want to update plan price using paypal api. for this i am using
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(array(
'USER' => 'ddsds_da_api',
'PWD' => '123412432134',
'SIGNATURE' => 'sgdsdshds',
'METHOD' => 'UpdateRecurringPaymentsProfile',
'VERSION' => '108',
'PROFILEID' => 'I-FYYMDB55ADSH',
'NOTE' => 'Uma nota opcional, explicando o motivo da mudança',
'AMT' => 120,
'CURRENCYCODE' => 'BRL'
)));
$response = curl_exec($curl);
curl_close($curl);
$nvp = array();
if (preg_match_all('/(?<name>[^\=]+)\=(?<value>[^&]+)&?/', $response, $matches)) {
foreach ($matches['name'] as $offset => $name) {
$nvp[$name] = urldecode($matches['value'][$offset]);
}
}
print_r($nvp);
But i am getting this error Subscription Profiles not supported by Recurring Payment APIs Here is my error
<pre>Array
(
[PROFILEID] => I-FYYMDB55ADSH
[TIMESTAMP] => 2015-03-16T15:48:07Z
[CORRELATIONID] => 33216e1739dde
[ACK] => Failure
[VERSION] => 76.0
[BUILD] => 15735246
[L_ERRORCODE0] => 11592
[L_SHORTMESSAGE0] => Subscription Profiles not supported.
[L_LONGMESSAGE0] => Subscription Profiles not supported by Recurring Payment APIs.
[L_SEVERITYCODE0] => Error
)
Please let me know what i did wrong.
As answered in the PayPal Community Help Forum
by PayPal_Frank Administrator answerd: 04-02-2012 11:08 AM
...
The basic subscription button profile IDs are not support by the
GetRecurringPaymentsProfileDetails API. This API would only work for
subscriptions or recurring payment profiles created via the
CreateRecurringPaymentsProfile API through Express Checkout which is
our API based checkout solution. Website Payments Pro is not required
to use Express Checkout. I know this can be frustrating and we
recommend that merchants collect basic subscription information via
IPN to store in their own database or view the information on their
PayPal account. This has also been submitted as a feature request by
our Merchant Technical Services team.
https://www.x.com/developers/paypal/forums/general-support/there-any-api-or-methods-which-i-can-get-...
...
You only can check the Status of such an Agreement when you use a url like:
$url = 'https://api.paypal.com/v1/payments/billing-agreements/'.$z_res[0]['id_agreement']."/transactions?start_date=".substr($logdbarray['Deal_Start'],0,10)."&end_date=".substr($now,0,10);
Here you will get a list of trsansactions. When the last transaction in not status:canceled then the agreement still runs. You will get dates of transactions as well so you can define if you agree to use your paid service or not.

GET and POST Methods

I have one application (checkpoint firewall)
That sends formats a URL from variables to form a request using the GET method
https://api.example.com/http/sendmsg?api_id=$APIID&user=
$USERNAME&password=$PASSWORD&to=$PHONE&text=$MESSAGE
how ever the website I want to use is a basic form using the POST method with the following source.
<html>
<form method="post">
Number:<input type="text" name="number"/><br/>
Message:<textarea cols="40" rows="4" name="message"></textarea><br/>
<input type="submit" value="send"/>
</form>
</html>
I can change the format of the URL as much as I like with in reason, as you can possible guess this is sending SMS text messages.
is there any way to format a URL with the POST method, or create an intermediate webpage that can translate the request?
thank you
EDIT
So this was the kind of thing I had in mind
$number = ($_GET["number"]);
$message = ($_GET["message"]);
//for testing the get method echo variables on screen
echo("Number: " . $number . "<br />");
echo("Message: " . $message . "<br />");
//use curl to post variables to second website
$vars = "number-" . $number . "&message=2 . message;
$ch = curl_init( '10.43.23.53' );
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $vars);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
print_r(curl_getinfo($ch));
this script is hosted by a web site so application A can use its GET method to supply the variables, and the script will re-post them to application B via post. However it does not work and I don't get any result from the response ?
$apiKey = 'your-api-key-here';
$user = 'your-username-here';
$password = 'your-password-here';
$number = isset($_POST['number']) ? $_POST['number'] : null;
$message = isset($_GPOST['message']) ? $_POST['message'] : null;
$url = sprintf('https://api.example.com/http/sendmsg?api_id=%s&user= %s&password=%s&to=%s&text=%s',
$apiKey, $user, $password, urlencodee($message)
);
// validating message etc. left to OP
$response = file_get_contents($url);
You will not be able to send a POST as a GET, they are different methods and a POST requires variables to be sent with the request that are not available in a GET request.
You could in theory create an intermediary which takes the initial GET request and forms a suitable POST requests and send it on to the target server. The actual implementation of this is outside of the scope of this question.

Need a good HTML parser on php

Found this one http://simplehtmldom.sourceforge.net/ but it has failed to work
extracting this page http://php.net/manual/en/function.curl-setopt.php
and parse it to plain html, it failed and returned a partial html page
This is what I want to do,
Go to a html page and get the components individual( the contents of all div and p in a hierarchy )
I like the features of simplehtmldom any such parser is required which is good at all code(best and worst).
I often use DOMDocument::loadHTML, which works not too bad, in the general cases -- and I like querying the documents, once they are loaded as DOM, with Xpath.
Unfortunatly, I suppose that, in some cases, if the HTML page is really to badly-formed, some parsing problems can occur... That's when you start understanding that respecting web-standards is a great idea...
Building on Pascal MARTIN's response...
I use a combination of CURL and XPATH. Below is a function I use in one of my classes.
protected function _get_xpath($url) {
$refferer='http://www.whatever.com/';
$useragent='Googlebot/2.1 (http://www.googlebot.com/bot.html)';
// create curl resource
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_REFERER, $refferer);
curl_setopt($ch, CURLOPT_URL, $url);
//return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// $output contains the output string
$output = curl_exec($ch);
//echo htmlentities($output);
if(curl_errno($ch)) {
echo 'Curl error: ' . curl_error($ch);
}
else {
$dom = new DOMDocument();
#$dom->loadHTML($output);
$this->xpath = new DOMXPath($dom);
$this->html = $output;
}
// close curl resource to free up system resources
curl_close($ch);
}
You can then parse the document structure using evaluate and extract the information you want
$resultDom = $this->xpath->evaluate("//span[#id='headerResults']/strong");
$this->results = $resultDom->item(0)->nodeValue;
I found the best one for my use here it is - http://querypath.org/

How to convert zipcode to longitude and latitude?

I want to find the longitude and latitude of place with a the help to a zipcode.
Can anyone tell me how to do that?
An example in actionscript what be very much helpful for me. Because i am making a project in Flex.
Regards
Zee
Do you have access to a long/lat database? if not, i believe you can use the google maps API to do that lookup.
Oh .. I just noticed Chris' answer. I am not familiar with geonames. You might also want to get familiar with "http://freegeographytools.com/" which has a ton of geocoding, gps, etc. resources for a whole range of projects.
Ahhh ... I just visited Eric's blog post. That is excellent! I will definitely hook up with google for more details in a future project.
If you are looking for on demand geocoding, use Google. They provide a simple pox web service version.
I wrote a blog about this a while back. Check out this link for step by step instructions for using this simple geocoding.
Cheers,
Eric
I got my solve you can also
function getLatLong($code) {
$mapsApiKey = 'ABQIAAAAsV7S85DtCo0H9T4zv19FoRTdT40ApbWAnDYRE0-JyP5I6Ha9-xT9G5hCQO5UtOKSH5M3qhp5OXiWaA';
$query = "http://maps.google.co.uk/maps/geo?q=".urlencode($code)."&output=json&key=".$mapsApiKey;
$data = file_get_contents($query);
// if data returned
if($data) {
// convert into readable format
$data = json_decode($data);
$long = $data->Placemark[0]->Point->coordinates[0];
$lat = $data->Placemark[0]->Point->coordinates[1];
return array('Latitude'=>$lat, 'Longitude'=>$long);
} else {
return false;
}
}
There are several places to get zip code databases, in several formats. Load it into your favorite RDBMS, and query away.
Alternatively, you can use someone else's web service to look up the value for you. Other answers have posted possible web services; also, geocoder.us appears to have support for ZIP code lookup now as well.
There is now a better solution for this using the most recent Google Maps API (v3). The following is a slightly modified example from multiple sources. I have to give most of the credit to them. It's PHP, using cURL to retrieve the data from Google, but you could also use Ajax.
function address_lookup($string){
$string = str_replace (" ", "+", urlencode($string));
$details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$string."&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);
// If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
if ($response['status'] != 'OK') {
return null;
}
$geometry = $response['results'][0]['geometry']['location'];
$array = array(
'lat' => $geometry['lat'],
'lng' => $geometry['lng'],
'state' => $response['results'][0]['address_components'][3]['short_name'],
'address' => $response['results'][0]['formatted_address']
);
return $array;
}
$zip= '01742';
$array = address_lookup($zip);
print_r($array);
The easiest way out is using GoogleMap Api. Say you have a zipcode in a varible $zipcode.
$latlongUrl = 'http://maps.googleapis.com/maps/api/geocode/json?components=postal_code:'.$zipcode;
$data = file_get_contents($latlongUrl); // you will get string data
$data = (json_decode($data)); // convert it into object with json_decode
$location = ($data->results[0]->geometry->location); // get location object
$location is the object with Latitude and Longitude value.