I am submitting a contact form to HubSpot using their api (https://developers.hubspot.com/docs/methods/forms/submit_form), which is working out great, except that every time I do it, HubSpot autogenerates a new form in its site under Marketing -> Forms, with a name like #form_5dd7ee368739f. It says that this is a non-Hubspot form and gives this explanation:
What is a non-HubSpot form
Non-HubSpot forms are HTML forms on your
website that weren't created in HubSpot. Based on your settings,
data for these forms is automatically collected in HubSpot. Learn
more.
"Learn more" isn't a link; I can't click on it. The submission of the api request is recorded both in this new form that it autogenerated each time the form is submitted, as well as in the form that I built in HubSpot that supposed to handle this request. Here is my code:
<?php
// wp-config.php
define('HUBSPOT_PORTAL_ID', getenv('hubspot_portal_id'));
define('HUBSPOT_CONTACT_FORM_GUID', getenv('hubspot_contact_form_guid'));
define('HUBSPOT_CONTACT_FORM_ENDPOINT', "https://forms.hubspot.com/uploads/form/v2/".HUBSPOT_PORTAL_ID."/{form_guid}");
?>
<?php
// hubspot.php
function hubspot_form_submit($page_url, $page_name, $endpoint, $data) {
$hs_context = array(
'ipAddress' => $_SERVER['REMOTE_ADDR'],
'pageUrl' => $page_url,
'pageName' => $page_name,
);
if (array_key_exists('hubspotutk', $_COOKIE)) {
$hs_context['hutk'] = $_COOKIE['hubspotutk'];
}
$data['hs_context'] = $hs_context;
$data_string = "";
foreach ($data as $key => $value) {
if (is_string($value)) {
$value = urlencode($value);
}
else if (is_array($value)) {
$value = json_encode($value);
}
$data_string = $data_string.$key."=".$value."&";
}
$data = rtrim($data_string, "&");
$ch = #curl_init();
#curl_setopt($ch, CURLOPT_POST, true);
#curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
#curl_setopt($ch, CURLOPT_URL, $endpoint);
#curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
#curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = #curl_exec($ch);
if(curl_error($ch)) {
$result = curl_error($curl);
}
$status_code = #curl_getinfo($ch, CURLINFO_HTTP_CODE);
#curl_close($ch);
return $result;
}
?>
<?php
// contact.php
require_once("inc/hubspot.php");
$hubspot_form_submission = hubspot_form_submit(
"https://www.example.com/contact/",
"Contact",
str_replace("{form_guid}", HUBSPOT_CONTACT_FORM_GUID, HUBSPOT_CONTACT_FORM_ENDPOINT),
array(
"firstname" => $form->data["first_name"],
"lastname" => $form->data["last_name"],
"email" => $form->data["email"],
"phone" => $form->data["phone"],
"preferred_contact_method" => $form->data["contact_method"],
"message" => $form->data["comments"],
)
);
?>
Anyone know how I can prevent HubSpot from autogenerating these forms? Otherwise my forms box will quickly become filled up with hundreds of autogenerated forms that I will keep having to delete. Something to note: the actual form that I created for this purpose is located within a folder, whereas the autogenerated forms are always located outside of any folders, if that makes any difference.
Found the problem: the client had enabled the use of Non-HubSpot forms in their settings, so all that is required to fix it is just to turn this functionality off. The documentation is here:
https://knowledge.hubspot.com/forms/use-non-hubspot-forms
The setting is located in
Settings -> Marketing -> Forms -> Non-HubSpot Forms
Related
We post a message to a slack channel every time a customer does a specific task. We want to change the bot Icon based on what is being posted in the channel.
Is this possible?
public static function send_to_slack($message,$title = null){
$body = array();
$body['text'] = '';
$body['icon_url'] = '';
if(!empty($title)) $body['text'] .= "*$title*\n";
$body['text'] .= $message;
$iconURL = "https://img.icons8.com/emoji/96/000000/penguin--v2.png";
$body['icon_url'] .= $iconURL;
$json = json_encode($body);
//Test Slack Channel
$slack = "SLACKURL"
$response = wp_remote_post( $slack, array(
'method' => 'POST',
'body' => $json,
)
);
if ( is_wp_error( $response ) ) {
return true;
} else {
return true;
}
}
From Slack:
You cannot override the default channel (chosen by the user who installed your app), username, or icon when you're using Incoming Webhooks to post messages. Instead, these values will always inherit from the associated Slack app configuration.
*** UPDATE
I just ran into this situation. My old app was using the old web hooks. I had to create a new integration and ran into this issue. The simple solution is to install the slack app called "Incoming Webhooks". It's made by slack. It will allow you to generate an older style webhook that will allow you to post to any channel.
Found the correct way. Make sure you enable chat:write.customize in Slack oAuth Scope.
public static function send_to_slack($message,$title = null){
$ch = curl_init("https://slack.com/api/chat.postMessage");
$data = http_build_query([
"token" => "BOT-TOKEN",
"channel" => "CHANNELID", //"#mychannel",
"text" => $message, //"Hello, Foo-Bar channel message.",
"username" => "MySlackBot",
"icon_url" => $iconURL
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
I have this code below, it works perfectly, but I can use a proxy to change all the data (I also can change the receiver email) :/
How can I make it a POST checkout method? Now it's a GET method
<?php
public function checkout()
{
$query = [];
$query['cmd'] = '_cart';
$query['upload'] = 1;
$query['business'] = $this->getCredential();
foreach ($this->getItems() as $id => $item)
{
$id = $id + 1;
$query['item_name_' . $id] = $item['name'];
$query['amount_' . $id] = $item['amount'];
$query['quantity_' . $id] = $item['quantity'];
}
$query['custom'] = $this->getReference();
$query['<first_name>'] = $this->first_name;
$query['<last_name>'] = $this->last_name;
$query['<email>'] = $this->customer_email;
$query['notify_url'] = $this->getNotificationURL();
$query['return'] = $this->getReturnURL();
$query['cancel_return'] = $this->getCancelURL();
$query['rm'] = '2';
$query['cbt'] = 'Retornar para o site';
$query['lc'] = $this->getLocation();
$query['currency_code'] = $this->getCurrency();
$query_string = http_build_query($query);
return "https://". ($this->isSandbox() ? 'sandbox' : 'www' ) .".paypal.com/cgi-bin/webscr?".$query_string;
}
I also tried the code below, but when I click to finish the payment, it return me to the return URL with the token and payer_id, but don't pay :C
public function checkout()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api-m.paypal.com/v2/checkout/orders');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: ' . $this->getAccessToken(),
'Prefer: return=representation'
]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode([
'brand_name' => 'yStore Plugins',
'intent' => 'CAPTURE',
'purchase_units' => $this->getItems(),
'application_context' => [
'notify_url' => $this->getNotificationURL(),
'cancel_url' => $this->getCancelURL(),
'return_url' => $this->getReturnURL()
]
]));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = json_decode(curl_exec($curl));
curl_close($curl);
return $response->links[1]->href;
}
Follow the Set up standard payments guide which in its 'Add and modify the code' section explains that you should make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. For PHP you can use the Checkout-PHP-SDK (not any older or deprecated SDK). When accessed by a browser, both routes you create should only output JSON data (no additional HTML or text which cannot be parsed as JSON). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.
Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server , which has important client-side error handling.
Iv'e written a method to subscribe users to MailChimp. Whats 'special' about it is that it automatically subscribe the users to groups within the list, and segments within the list, based on the users' cart items, wishlist items, and the item and / or category that he has subscribed from.
The integration with MailChimp is straight forward - I get the data > send curl > get response > handle response.
I'm looking for a way to constant update the users' groups and segments, based on their actions in my store.
Now, the only accepted statuses MailChimp can get are 'subscribed', 'pending', and 'clean'. All of them aren't updating, only inserting new subscribers. If the email is already subscribed, nothing is being updated, not even data that is different than what the subscriber has in its profile in my MailChimp lists.
Here's my code for reference:
protected static function subscribeToMailchimp($email, $fullname)
{
$params = EkerbaseJoomla::getPluginParams('system', 'ekerbaseusers');
$interests = self::getUserInterestsObject();
$apikey = $params->mailChimpApiKey;
$listId = $params->mailChimpListId;
$interestCategoryId = $params->mailChimpInterestCategoryId;
$auth = base64_encode( 'user:' . $apikey );
$apiUrl = 'https://'.substr($params->mailChimpApiKey, -3).'.api.mailchimp.com/3.0/lists/'.$listId;
$possibleGroups = json_decode(file_get_contents($apiUrl . '/interest-categories/' . $interestCategoryId . '/interests?apikey=' . $apikey))->interests;
$segments = json_decode(file_get_contents($apiUrl . '/segments?apikey=' . $apikey))->segments;
$data = [
'apikey' => $apikey,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' =>
[
'FNAME' => $fullname
]
];
if( ! empty($interests->categories) ) {
$data['interests'] = [];
foreach( $possibleGroups as $group ) {
if( in_array($group->name, $interests->categories) ) {
$data['interests'][$group->id] = true;
}
}
}
if( ! empty($interests->items) ) {
$data['segments'] = [];
foreach( $segments as $segment ) {
if( in_array($segment->name, $interests->items) ) {
$data['segments'][$segment->id] = true;
}
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiUrl . '/members/');
curl_setopt($ch, CURLOPT_HTTPHEADER,
[
'Content-Type: application/json',
'Authorization: Basic '.$auth
]
);
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/3.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
$response = json_decode($result);
switch( $response->status ) {
case 'subscribed':
$responseMessage = JText::_('EKERBASE_SUCCESS_NEWSLETTER');
$responseStatus = 'success';
$responseResult = 'mailchimp subscribing succeeded';
break;
default:
$responseStatus = 'error';
$responseMessage = $response->title;
$responseResult = 'mailchimp subscribing failed';
if( $response->title === 'Member Exists' ) {
$responseMessage = JText::_('EKERBASE_NEWSLETTER_ALREADY_SUBSCRIBER');
}
break;
}
return EkerbaseAjax::buildJsonResponse($responseMessage, $responseStatus, $responseResult);
}
If your integration is adding entirely new subscriber as expected, and the issue appears isolated to cases where the method is updating an existing sub's record, the issue may pertain to the HTTP method, and/or the api endpoint.
As v3 of MailChimp's API only allows subscribers to be initialized when using the POST method(which looks like it may be hard coded into cURL here), and is likely why entirely new subscribers are being added without issue.
This said, when wanting to add or update new subscribers using PUT would be recommended, and is specified in their docs.
Add or update a list member
more on http methods and their API
Additionally, along with this alternate method usage, to ensure existing subscribers are updated, you'll also need to append the MD5 hash of the lower case version of their email to to the endpoint. This only needs to be done for existing subs.
e.g. /members/{lowercase_email_MD5_hash}
Which should be provided in the response if you're first checking with MailChimp whether or not a subscriber exist, if you'd like to recycle that.
I've tried to add a thumbnail to the facebook app link, but can't even find documentation about it. Is it possible?
The current code (PHP/Laravel) gives me a working link, which looks like this: https: // fb.me/1234567890. It writes the app name as well when posted on Facebook, but with no image/thumbnail. I've tried putting an "image" or "thumbnail" parameter in http_build_query, but with no luck.
$url = "https://graph.facebook.com/v2.6/app/app_link_hosts";
$ch = curl_init($url);
# create form post data
$metadata = "?item=" . $request->itemid;
$deepLinkURL = "APP://" . $metadata;
//echo $deepLinkURL;
$androidArray = json_encode(array(array("url" => $deepLinkURL,
"package" => "com.app.package",
"app_name" => "APPNAME")
)
);
$iosArray = json_encode(array(array("url" => $deepLinkURL,
"app_store_id" => 45345345,
"app_name" => "APPNAME")
)
);
$webFallbackArray = json_encode(array("should_fallback" => false));
$formQuery = http_build_query(array("access_token" => "1234567890|XXXXXXXXXXXXXXXX",
"name" => "APPNAME",
"android" => $androidArray,
"ios" => $iosArray,
"thumbnail" => "http://i.imgur.com/upnywSR.jpg",
"web" => $webFallbackArray)
);
$path = base_path() . "/vendor/phpunit/phpunit/build/ca.pem";
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_CAINFO, $path);
# options
curl_setopt($ch, CURLOPT_POST, true); //1
curl_setopt($ch, CURLOPT_POSTFIELDS, $formQuery);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
# get response
$resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$jsonResponse = json_decode(curl_exec($ch), true);
curl_close($ch);
# decode response from facebook
$appLinkId = "";
# get appLinkId
foreach ($jsonResponse as $key => $val) {
# get status
if($key == "id") {
$appLinkId = $val;
}
}
# if response is good, need to request canonical URL from appLinkId
$errorMessage = "";
$canonicalUrl = "";
if(!empty($appLinkId)) {
# create another instance of cURL to get the appLink object from facebook using the ID generated by the previous post request
$getAppLinkUrl = "https://graph.facebook.com/" . $appLinkId;
$ch2 = curl_init($getAppLinkUrl);
# cURL options
$queryString = http_build_query(array("access_token" => "206722406330430|XRV38UNZsFfRNNF1EkfikzDWkpk",
"fields" => "canonical_url",
"pretty" => true)
);
/////////////////////
$path = base_path() . "/vendor/phpunit/phpunit/build/ca.pem";
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch2, CURLOPT_CAINFO, $path);
/////////////////
curl_setopt($ch2, CURLOPT_URL, $getAppLinkUrl . "?" . $queryString);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
# get response
// $urlResponseJson = curl_exec($ch2);
$urlJsonResponse = json_decode(curl_exec($ch2), true);
curl_close($ch2);
# decode response from facebook
# parse response to get canonical URL
foreach ($urlJsonResponse as $key => $val) {
# get canonical URL
if($key == "canonical_url") {
$canonicalUrl = $val;
}
}
# check for result
if(empty($canonicalUrl)) {
$errorMessage = "Unable to retreive URL.";
}
} else {
$errorMessage = "Unable to publish appLink.";
}
# encode response back to your app
if(empty($errorMessage)) {
$response = json_encode(array("result" => "success",
"canonical_url" => $canonicalUrl));
} else {
$response = json_encode(array("result" => "failed",
"errorMessage" => $errorMessage));
}
return $response;
I've tried to add a thumbnail to the facebook app link, but can't even find documentation about it. Is it possible?
No.
As https://developers.facebook.com/docs/applinks/hosting-api says,
If your application doesn't have a website for content you want to share to Facebook, you don't have public web URLs which you can annotate to support App Links. For these types of apps, Facebook provides an App Links Hosting API that will host App Links for you.
So if you have public web URLs that you want to share, then you should rather annotate those with the meta tags for App Links – then it will take the thumbnail you specified for those URLs via og:image.
If that is not an option, then you could still try and specify a thumbnail when you share the canonical URL of the App Link object, f.e. via the Feed dialog.
I'm trying to convert this PHP cURL function to work with my rails app. The piece of code is from an SMS payment gateway that needs to verify the POST paramters. Since I'm a big PHP noob I have no idea how to handle this problem.
$verify_url = 'http://smsgatewayadress';
$fields = '';
$d = array(
'merchant_ID' => $_POST['merchant_ID'],
'local_ID' => $_POST['local_ID'],
'total' => $_POST['total'],
'ipn_verify' => $_POST['ipn_verify'],
'timeout' => 10,
);
foreach ($d as $k => $v)
{
$fields .= $k . "=" . urlencode($v) . "&";
}
$fields = substr($fields, 0, strlen($fields)-1);
$ch = curl_init($verify_url); //this initiates a HTTP connection to $verify_url, the connection headers will be stored in $ch
curl_setopt($ch, CURLOPT_POST, 1); //sets the delivery method as POST
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields); //The data that is being sent via POST. From what I can see the cURL lib sends them as a string that is built in the foreach loop above
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); //This verifies if the target url sends a redirect header and if it does cURL follows that link
curl_setopt($ch, CURLOPT_HEADER, 0); //This ignores the headers from the answer
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //This specifies that the curl_exec function below must return the result to the accesed URL
$result = curl_exec($ch); //It ransfers the data via POST to the URL, it gets read and returns the result
if ($result == true)
{
//confirmed
$can_download = true;
}
else
{
//failed
$can_download = false;
}
}
if (strpos($_SERVER['REQUEST_URI'], 'ipn.php'))
echo $can_download ? '1' : '0'; //we tell the sms sever that we processed the request
I've googled a cURL lib counterpart in Rails and found a ton of options but none that I could understand and use in the same way this script does.
If anyone could give me a hand with converting this script from php to ruby it would be greatly appreciated.
The most direct approach might be to use the Ruby curb library, which is the most straightforward wrapper for cURL. A lot of the options in Curl::Easy map directly to what you have here. A basis might be:
url = "http://smsgatewayadress/"
Curl::Easy.http_post(url,
Curl::PostField.content('merchant_ID', params[:merchant_ID]),
# ...
)