hubspot webhook trouble in PHP - php

I have been asked to deal with web hook concept. I am very new to this concept and i will need your help. I was asked to provide a URL to a company so they can send json data from their website.
So far i found this :
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
$result=curl_exec($ch);
// Closing
curl_close($ch);
// Will dump a beauty json :3
var_dump(json_decode($result, true));
so is URL same as this PHP file? I am really confused. Thank You

Update: I have created an article to help with this
You don't need to use curl for a HubSpot webhook, the webhook should trigger some kind of action on your server and receive posted data ready for massaging and manipulating. A webhook could be, when a contact fills out a form or completes a specific action within HubSpot and you push that data to your custom script on a stand alone server. You should start with how to handle JSON data in a POST request. http://edwin.baculsoft.com/2011/12/how-to-handle-json-post-request-using-php/
That article should help out a bit...
Since you don't normally know what that posted data from HubSpot looks like just yet, you can use a service like requestbin to view the data that is being posted.. Note: they might have a cap on the amount of JSON it can handle in the request so you might need to find another service that gives you the complete JSON data or create a script on your server that saves the request to a file. For requestbin, you would create a workflow in hubspot with the action being a webhook and set the type to post and the url to the url that you received when creating a new requestbin.
Once you know what the JSON data structure is that is coming into your server, you can start to go to work on manipulating that data.

It's hard to be sure from the info you are providing, but you are probably coming at this the wrong way around.
You probably need to write a php script that will be the target of a webhook. Here is a post that should get you started:
Catching json data from hubspot webhook

Related

Unable to find what kind of CURL Post Request

I've recieved the following data which I need to post to server
and I cant find out how exactly I need to do it in PHP.
I need to send numbers, but I cant see any parameter thier asking me to send it from.
any ideas how I could send this data?
AFAIK you need this:
$postdata = file_get_contents("php://input");
Details:
http://php.net/manual/en/wrappers.php.php
Or maybe the other way:
RAW POST using cURL in PHP
(I am bit lost in your question.)
The main idea there:
curl_setopt($ch, CURLOPT_POSTFIELDS, "numbers\nnumbers\n..." );

Curl Requests in PHP - Using an API

I'm trying to figure out how to use the Cheddar API (http://cheddarapp.com/developer) in my PHP application.
Cheddar's API uses curl requests - which have been fine for me using in terminal but not in my index.php.
I'd like to create a button that when clicked, creates a task in a list call Colors. If a list does not exist, it'll create the list.
Have anybody used Cheddar's API or even included curl requests in PHP or even how to include them in Javascript which I'm guessing you use for things of this matter.
Update
Here's the Curl request for creating a task in Cheddar: https://cheddarapp.com/developer/tasks#create.
I'd like to make a button that onclick, it will create a task. Is it not as a simple as creating a function in Javascript and using onclick on an anchor?
I am using now days curl Php
$LOCAL_REST_URL = 'whateverurlofyourrestapi'
$json_part = { pass the data for post }
you will get your response in $buffer in json format iterate it use the response
As u said how to make a curl request i would like to give you a simple POST example
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$LOCAL_REST_URL);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,20);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS,$json_part);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
Where $json_partis the request body and $LOCAL_REST_URL is is your rest url
I am hoping this post will help you
You could run your terminal program with shell_exec from php.
Or transcript the curl-code to curl-requests from php, http://se2.php.net/manual/en/ref.curl.php

Replace nuSOAP with cURL

I have a PHP script that syncs data with a third party service, and I would like to, if possible, replace nuSOAP with cURL as I have heard cURL is faster. The web service I am calling just takes simple HTTP post and returns it, so the cURL parameters shouldn't be too involved.
I need to pass 4 things, a user id, password, organization id, and the name of the web service to receive data from.
Which part of the cURL options do I pass them? I was trying to pass them in the header, but I am not sure if that is correct. I kept receiving 'Bad Request (Invalid Number)' error.
Edit: I am setting the HTTPHEADER but it looks like its still setting it to text/html.
Since, i have a thought that you have some basic understanding of cURL. I am giving you some shallow information.
If you are just posting some information to a page make use of
curl_setopt($agent, CURLOPT_POST, true);
curl_setopt($agent, CURLOPT_POSTFIELDS, $post_data);
where $post_data will be the information you post to the page , something like
$post_data="name=stanley&feedback=good";
Or
If you are trying to make an authentication to a page, Just use
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt(CURLOPT_USERPWD, '[username]:[password]');
If you say 'The web service I am calling just takes simple HTTP post', assuming it doesn't use SOAP, you would do it by:
curl_setopt($handle,CURLOPT_POST,true);
curl_setopt($handle,CURLOPT_POSTFIELDS,array(
'user_id' => 'user',
'password' => 'pass' //etc, all the key/value pairs you need.
));
However, if it is a SOAP service, you would have to make a SOAP request, and which for it would take we cannot tell you without a WSDL. Any of the PHP XML packages would do to create it, possibly for simple things even normal string manipulation.
A help in the built-in soapclient (not nusoap) would be to do a request with SOAPClient and just examine the output of __getLastRequest().

Pass data to another form and get response

I want to pass data (a 16 digit key) to another site which will validate the key and return a response. I want to grab the response and check if it's a valid key on my side so I can do some extra stuff with it.
Is this possible? If not, why can't it be done?
EDIT:
Ok here's the process. I am grabbing this key from a user input, which can be accessed by grabbing the POST data. After, the data needs to be sent into another form with 1 input field on another site. Ideally, this will produce a result that I can grab on my end.
Some sample test code to give you an idea of calling a remote site behind the scenes:
$key = $_POST['key']
// Create a curl handle to the remote checking server
$ch = curl_init('http://remoteurl/?key=' . $key);
// Execute
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Get the reply back
$reply = curl_exec($ch);
curl_close($ch);
// Do stuff with the reply
if ($reply == '...')
// Save $key?!
Ya, it's possible and there are many ways to accomplish it.
cURL is probably going to be your best bet.
Or you could use sockets and directly connect to the target machine on port 80 and throw an HTTP request with form data on it for ultimate control.
Or you could also do it on the client side with javascript.

PHP cross domain requests

I am a green programmer and I was originally trying to make cross domain requests in JS. I quickly learned that this is not allowed. Unlike similar questions posted on here, I would like to see if I can use PHP to make them for me instead of JSONP requests. Is this possible?
Simple workflow...
BROWSER: POST to my PHP the request-payload & request-headers
PHP: POST to Other Domain's URL the request-payload & request-headers
Other Domain: Process Request and send response
PHP: Send the Response-Content and Response-Header Info back to the browser
Here is what I am trying to work with http://msdn.microsoft.com/en-us/library/bb969500%28v=office.12%29.aspx
My goal is to make a Communicator Web Access Client that is web based and mobile friendly.
A link to a working example would be awesome!
CURL yould be your option in this case, something simple as:
<?php
$ch = curl_init('http://otherdomain.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$result = curl_exec($ch);
var_dump($result);
?>
In this case, $result would contain the html code of the site. Please be aware that it doesn't going to execute any javascript as if you were visiting the site on the browser.
You are talking about web services and seems that the goal is process payments. Any major payment gateway have APIs prepared for that. In any case you can study by your own. Here a good starting point http://ajaxonomy.com/2008/xml/web-services-part-1-soap-vs-rest

Categories