I am trying to create a prospect in hubspot by submission of the form.
Following is the code that i have written.
<?php
function send_lead() {
$hubspotutk = $_COOKIE['hubspotutk'];
$ip_addr = $_SERVER['REMOTE_ADDR'];
$hs_context = array(
"hutk" => $hubstoputk,
'ipAddress' => $ip_addr,
'pageName' => 'Test Form'
);
$hs_context_json = json_encode($hs_context);
//Need to populate these varilables with values from the form.
$str_post ="email=" . urlencode($_POST["email"])
. "&hs_context=" . urlencode($hs_context_json); //Leave this one be :)'
//replace the values in this URL with your portal ID and your form GUID
$endpoint = 'https://forms.hubspot.com/uploads/form/v2/portal-id/form-id';
$ch = #curl_init();
#curl_setopt($ch, CURLOPT_POST, true);
#curl_setopt($ch, CURLOPT_POSTFIELDS, $str_post);
#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);
$response = #curl_exec($ch); //Log the response from HubSpot as needed.
#curl_close($ch);
echo $response;
}
?>
I get an empty response. Can anyone tell me whats wrong with my code?
A response of 204 is received from Hubspot when the form submission is successful. A 204 is a response with no content.
Hubspot form api reference can be found here: http://developers.hubspot.com/docs/methods/forms/submit_form
Spelling mistake in the variable name. Use $hubspotutk in the $hs_context array.
Related
My code is working fine but take so much time for show result because i have above 1500 products.
So any one modify my code or best way to show results
$results = $proxy->catalogProductList($sessionId);
$productData = new stdClass();
$productData->additional_attributes = array('short_description','cost');
foreach($results as $value){
$results_product = $proxy->catalogProductInfo($sessionId,$value->product_id,null,$productData);
$pro_imag = $proxy->catalogProductAttributeMediaList($sessionId, $value->product_id);
echo "";
echo "".$sno++."".$value->product_id."".$value->sku."".$value->name."".$results_product->additional_attributes[0]->value."".abs($results_product->additional_attributes[1]->value)."".abs($results_product->price)." url."' width='80px' height='80px'> ";
echo "";
}
Try the following code and use magento site for easy api examples like following, example SOAP V2 (Complex Filter)
<?php
$client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');
$session = $client->login('apiUser', 'apiKey');
$complexFilter = array(
'complex_filter' => array(
array(
'key' => 'type',
'value' => array('key' => 'in', 'value' => 'simple,configurable')
)
)
);
$result = $client->catalogProductList($session, $complexFilter);
var_dump ($result);
I am looking to get per sms rate by passing "To" mobile number for related country to display in my application, please suggest best solution, Thanks.
Twilio evangelist here.
Unfortunately today we don't have a way via the API to find out the price of an SMS before sending it. You can get the price of an individual message after its sent via the API by making a request to the Messages endpoint:
/2010-04-01/Accounts/{AccountSid}/Messages/{MessageSid}
We also publish a csv that contains all of our SMS pricing. You can find that here:
https://www.twilio.com/help/faq/sms/where-can-i-see-all-of-twilios-sms-pricing-in-one-place
Hope that helps.
i was looking for a similar solution today and i had to code mind myself. Hope this gives you the idea. Though this method will cost you $0.005 per query.
If you can get another provider(s) to query a mobile number and get it's Mobile Network Code (MNC) then this solution becomes free.
<?php
$entry_number="+1239393939"; //The mobile num to query
$account_sid = 'your twilio SID';
$auth_token = 'your auth token';
// STEP 1, GETTING THE MNC(This costs $0.005)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://lookups.twilio.com/v1/PhoneNumbers/'.$entry_number.'?Type=carrier',
CURLOPT_USERPWD => ''.$account_sid.':'.$auth_token.'',
CURLOPT_USERAGENT => 'Number lookup'
));
$response = curl_exec($curl);
curl_close($curl);
$array = json_decode($response);
$country_code=$array->country_code;
$mnc=$array->carrier->mobile_network_code;
$network_name=$array->carrier->name;
// END OF STEP ONE, (You can var_dump($response); to see entire response
// STEP 2, Checking the price (This step is free)
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://pricing.twilio.com/v1/Messaging/Countries/'.$country_code.'',
CURLOPT_USERPWD => ''.$account_sid.':'.$auth_token.'',
CURLOPT_USERAGENT => 'Number lookup'
));
$response = curl_exec($curl);
curl_close($curl);
$array = json_decode($response);
$pricing= $array->outbound_sms_prices;
foreach ($pricing as $data=>$value)
{
if ($value->mnc == $mnc){
foreach ($value->prices as $data1=>$value1)
{
if ($value1->number_type == 'mobile'){
$current_price=$value1->current_price; // ECHO this line to show price
}
}
}
}
?>
i'm trying to upload a file in BOX_API with php and Zend framework. But i'm missing somethin. It's the first time that i use an interface like this o i've read the manual. But it is confusig for me. My question are two:
-First, why do you have to pass to the post call only the name of the file and not the whole file with the right header for file upload? File upload in a form is not like passing the name of the file through a post call;
-secondly and consequently, do i have to make a form for file upload or simply a textarea where to write the name of the file to be passed to the BOX-API?
UPDATE:
This is the code of my upload form:
$form = new Zend_Form;
$form->setAction('/imball-reagens/public/upload')
->setMethod('post');
$file = new Zend_Form_Element_File('file');
$file->setLabel('Choose a file to upload:');
$file->addValidator('alnum');
$file->setRequired(true);
$form->addElement($file);
$access_token = new Zend_Form_Element_Hidden(array('name' => 'access_token', 'value' => $result->access_token));
$form->addElement($access_token);
$refresh_token = new Zend_Form_Element_Hidden(array('name' => 'refresh_token', 'value' => $result->refresh_token));
$form->addElement($refresh_token);
$form->addElement('submit', 'upload', array('label' => 'Upload File'));
echo $form;
And this s the POST cal to the box API which comes after the form:
$access_token= $this->getRequest()->getParam('access_token');
$client = new Zend_Http_Client('https://upload.box.com/api/2.0/files/content');
$client->setMethod(Zend_Http_Client::POST);
$client->setHeaders('Authorization: Bearer '.$access_token);
$data = $_FILES["file"]["name"];
$client->setParameterPost(array(
'filename' => '#'.$data,
'parent_id' => '0'
));
$response = $client->request()->getBody();
$this->view->response= $response;
$result = json_decode($response);
The error it throws is below:
{"type":"error","status":400,"code":"invalid_request_parameters","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Invalid input parameters in request","request_id":"172518183652dcf2a16af73"}
Tricky to debug without seeing all of the code, but in the bit you pasted it looks like you are passing $_FILES["file"]["name"] to the API - this only contains the original name of the file which was uploaded by the user - you need to pass the location to the file on the server which is sending the data to the Box API client so that it can grab it and send it to the Box server - this should be stored in $_FILES["file"]["tmp_name"].
I would recommend changing the code to this and trying again:
$access_token= $this->getRequest()->getParam('access_token');
$client = new Zend_Http_Client('https://upload.box.com/api/2.0/files/content');
$client->setMethod(Zend_Http_Client::POST);
$client->setHeaders('Authorization: Bearer '.$access_token);
$data = $_FILES["file"]["tmp_name"];
$client->setParameterPost(array(
'parent_id' => '0'
));
$client->setFileUpload($data, 'filename');
$response = $client->request()->getBody();
$this->view->response= $response;
$result = json_decode($response);
I'm using the Twitter API 1.1 Get statuses method to return the latest tweet from an account on the client's website. This is working fine but I can't find any clear documentation on how to render any links that may be included (Both included usernames and included links) as clickable links?
I can see in the JSON response that any included links are in the XML but it's not clear to me how to go about adding clickable links into the rendered output. The documentation around the new API seems to be lacking practical examples.
Can anyone advise?
The code I'm using the pull out the latest tweet is as follows:
$token = 'TOKEN HERE';
$token_secret = 'TOKEN SECRET HERE';
$consumer_key = 'CONSUMER KEY HERE';
$consumer_secret = 'CONSUMER SECRET HERE';
$host = 'api.twitter.com';
$method = 'GET';
$path = '/1.1/statuses/user_timeline.json'; // api call path
$query = array( // query parameters
'screen_name' => 'SCREEN NAME HERE',
'count' => '1'
);
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_token' => $token,
'oauth_nonce' => (string)mt_rand(), // a stronger nonce is recommended
'oauth_timestamp' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_version' => '1.0'
);
$oauth = array_map("rawurlencode", $oauth); // must be encoded before sorting
$query = array_map("rawurlencode", $query);
$arr = array_merge($oauth, $query); // combine the values THEN sort
asort($arr); // secondary sort (value)
ksort($arr); // primary sort (key)
// http_build_query automatically encodes, but our parameters
// are already encoded, and must be by this point, so we undo
// the encoding step
$querystring = urldecode(http_build_query($arr, '', '&'));
$url = "https://$host$path";
// mash everything together for the text to hash
$base_string = $method."&".rawurlencode($url)."&".rawurlencode($querystring);
// same with the key
$key = rawurlencode($consumer_secret)."&".rawurlencode($token_secret);
// generate the hash
$signature = rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));
// this time we're using a normal GET query, and we're only encoding the query params
// (without the oauth params)
$url .= "?".http_build_query($query);
$oauth['oauth_signature'] = $signature; // don't want to abandon all that work!
ksort($oauth); // probably not necessary, but twitter's demo does it
// also not necessary, but twitter's demo does this too
function add_quotes($str) { return '"'.$str.'"'; }
$oauth = array_map("add_quotes", $oauth);
// this is the full value of the Authorization line
$auth = "OAuth " . urldecode(http_build_query($oauth, '', ', '));
// if you're doing post, you need to skip the GET building above
// and instead supply query parameters to CURLOPT_POSTFIELDS
$options = array( CURLOPT_HTTPHEADER => array("Authorization: $auth"),
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
// do our business
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json);
Thanks a lot for your response. I actually found a solution thanks to this blog post from the guys at Asheville - http://www.appliedtns.com/blog/tag/twitter/
It works fine for me.
// Parse any links found in our tweet
$formatted_text = preg_replace('/(\b(www\.|http\:\/\/)\S+\b)/', "<a target='_blank' href='$1'>$1</a>", $post->text);
$formatted_text = preg_replace('/\#(\w+)/', "<a target='_blank' href='http://search.twitter.com/search?q=$1'>#$1</a>", $formatted_text);
$formatted_text = preg_replace('/\#(\w+)/', "<a target='_blank' href='http://twitter.com/$1'>#$1</a>", $formatted_text);
Not sure if this exactly what you need but I am using the tmhOAuth library for my application, see https://github.com/themattharris/tmhOAuth-examples. Using code from Matt Harris' examples I loop through the response and build the output as in the code below. The links in the tweets are created by the library function entify_with_options($tweet).
// Decode response
$timeline = json_decode($this->tmhOAuth->response['response'], true);
if(!$timeline){
throw new Exception('Error: No response was found.');
}
else{
// Start building the output
foreach ($timeline as $tweet) :
... start of response processing
// Format and set tweet text
$tw_entified_tweet = tmhUtilities::entify_with_options($tweet);
// Format and set creation date for permalink
$tw_created_at_formatted = is_twitterlist_format_date($tweet['created_at']);
// Format and set permalink
$tw_permalink = str_replace(
array(
'%screen_name%',
'%id%',
'%created_at%'
),
array(
$tweet['user']['screen_name'],
$tweet['id_str'],
$tw_created_at_formatted,
),
'%created_at%'
);
... end response processing
endforeach;
}
The date format function is:
function is_twitterlist_format_date($created_date)
{
if ( is_null($created_date)) {
return '';
}
else{
// Format: March 4th, 9:19 am
return date('F jS, g:i a', strtotime($created_date));
}
}
Hope this is useful.
I am trying to create a fulfillment for an order using the API, and this fulfillment should include a tracking number. I am passing the tracking number with the request, and the request appears successful (the order is correctly fulfilled in the admin). However, the tracking number I pass is never present.
I am not including line items (to fulfill all items in the order), though I have tried it both ways (fulfilling one item at a time)
//$id, $key and $password are set previously
$endpoint = "https://{$key}:{$password}#mystore.shopify.com/admin/orders/{$id}/fulfillments.json";
$fulfillment = array(
'fulfillment' => array(
'tracking_number' => '12345'
)
);
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fulfillment));
res = curl_exec($ch);
After running the above code, $res contains something similar to this:
{"fulfillment":{"created_at":"2012-10-22T16:57:53-04:00","id":69428396,"order_id":143675378,"service":"manual","status":"success","tracking_company":null,"tracking_number":null,"tracking_url":"http://www.google.com/search?q=","updated_at":"2012-10-22T16:57:53-04:00","receipt":{},"line_items":[{"fulfillment_service":"manual","fulfillment_status":"fulfilled","grams":0,"id":233975006,"price":"19.00","product_id":108718266,"quantity":1,"requires_shipping":true,"sku":"","title":"Profound grid-enabled intranet","variant_id":248446746,"variant_title":null,"vendor":"Shopify","name":"Profound grid-enabled intranet","variant_inventory_management":null,"properties":[]},{"fulfillment_service":"manual","fulfillment_status":"fulfilled","grams":0,"id":233975008,"price":"19.00","product_id":108718276,"quantity":2,"requires_shipping":true,"sku":"","title":"Operative multi-tasking task-force","variant_id":248446754,"variant_title":null,"vendor":"Shopify","name":"Operative multi-tasking task-force","variant_inventory_management":null,"properties":[]}]}}
You can see in that response, the line items have fulfillment status set to fulfilled (correct) but tracking_number is null (incorrect).
Any help is greatly appreciated!
Need to specify content type for the request.
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json');