I want to add multiple emails at once through Hubspot API. I used a foreach loop to add emails but, after 30 seconds, it is showing execution time is exceeded. Is there a bulk way to add a property through Hubspot API?
foreach ($leads as $lead) {
$data['email'] = $lead['email'];
$data['firstname'] = $lead['name'];
$hubspot = new HubSpot($autoDetails[3]->api_creds_required);
$hubspot->contacts()->create_contact($data);
$email = $hubspot->contacts()->get_contact_by_email($lead['email']);
$result = $hubspot->lists()->add_contacts_to_list($email->vid, $autoDetails[0]);
}
As recommended in Hubspot's docs, you'll want to use their Batch API, which allows you to create or update up to 100 contacts in one request.
You might also want to check out this open source PHP Hubspot wrapper, which supports this same endpoint.
Related
I'm trying to get the role and email address of persons whom I shared my google drive file.
//this->drive is object of service_drive
$permissions = $this->drive->permissions->listPermissions($file->id);
foreach ($permissions->getPermissions() as $permission){
echo $permission['emailAddress'];
}
this is returning me null, is there anyway I can know completely about the person or at least email address and his role ?
Yes, you can get info as the email, name or role of the people you share your files with using the Permissions: list endpoint. Try this API can help you to play around with the info you want to retrieve using the fields parameters, which uses partial responses.
Translating the explanation from above to PHP code, this is what you would need to do:
// Build a parameters array
$parameters = array();
// Specify what fields you want
$parameters['fields'] = "permissions(*)";
// Call the endpoint
$permissions = $service->permissions->listPermissions($file->id, $parameters);
// print results
foreach ($permissions->getPermissions() as $permission){
echo $permission['emailAddress'];
}
I am using Twitch's API to request some details about a user, in particular I need to get their: twitch user, channel, live channel
I am having no problem getting any of their details, I have it set up so I can get a bulk amount of users with one request. The same with their live channels. But with just getting channel information, according to Twitch's API I must send a request per user. I can't see anyway to get a bulk list of channels
For example, using the code posted below, I can get 10-100s of users twitch user data in one simple request
But when I try to send too many requests I get blocked from their API
Code for getting bulk twitch user data
public static function setTwitchUserBulk($users)
{
// Key by their twitch_id
$users = $users->keyBy('twitch_id');
$twitch_key = env('TWITCH_KEY');
$url = 'https://api.twitch.tv/helix/users?';
foreach($users as $user) {
$url .= 'login='.$user->twitch_username.'&';
}
$data = \App\CustomHelper\ZarlachTwitchHelper::_basicCURL($url, array(
'Client-ID' => $twitch_key,
));
$data = json_decode($data, true);
if(isset($data['data'])) {
$data = $data['data'];
foreach($data as $twitchUser) {
if(isset($users[$twitchUser['id']])) {
// ... handle and store their data
}
}
}
}
According to Twitch's API, I must use this URL to get their channel
GET https://api.twitch.tv/kraken/channels/<channel ID>
Where as, when I get their twitch user, I can simply keep adding parameters onto the url to set the users i want to fetch
GET https://api.twitch.tv/kraken/users?login=<user IDs>
Good day,
Im creating reminder app that calls a number in certain time, currently I was using an uploaded mp3 file on my server:
here the code:
$sid = "ACxxxxxxxxxx";
$token = "2xxxxxxxxx";
$client = new Client($sid, $token);
$call = $client->calls->create(
"$phone_number_to","$phone_number_from",
array("url" =>
"https://xxxxx.com/asset/mp3/reminder.mp3")
);
$csid = $call->sid;
the above code works, but now I wanted to use the text to speech feature on twilio to have a more customized voicemail per reminder..
how do I do this using $client-> api? Im not really familiar on how TwiML works though, maybe thats why im confused.
thanks!
You change this line of your current code "url" => "https://xxxxx.com/asset/mp3/reminder.mp3" so that the URL points at the url hosting the script you want to use to generate your dynamic TwiML.
Then use the php TwiML library to generate the TwiML, it's pretty straightforward. We have a database with all out customers details in, I use code something along these lines to get their details based on caller ID and have Twilio greet them by first name:
$booked = SELECT * FROM table WHERE phone = $caller;
$name = explode(" ", $booked->name);
$firstname = $name[0];
$response->say("Hello $firstname. Thanks for calling......");
It's ok but it's a bit robotic. We ended up extracting the 50 most common first names from the database and having a voiceover artist record greetings for each one. For callers with one of those 50 names we serve a specific mp3 file, everyone else gets the robot.
I've seen some Twilio experts answer other questions on here before about using Twilio's service so I'm hoping this catches the eye of one of them. :)
Essentially, I need to create a system whereby two callers can connect (a sales agent and a customer) with the capability for a manager to listen in to a live call. From my research into Twilio's API I believe the only way to accomplish this is to have each call be a conference call, and allow the managers to join that call in 'muted' mode, thereby only allowing them to listen to the call between the agent and customer.
I'm developing in PHP and I believe I have 90% of the puzzle solved, however I'm have trouble with one small detail.
I'll lay out the logical flow below so you can see what I'm trying to do:
1) Customer or Sales Agent dials a number.
2) Conference room gets dynamically generated and the person dialing out is placed into that room.
3) I use the REST API to make a call request to the other number, then direct them into the conference room that was already generated with the first person waiting.
I have steps 1 and 2 completed and working fine, step 3 is where the problem occurs. When I use the API to generate the second call to bring the other person into the conference room the request goes through the same application that was used to generate the first call, thereby creating an infinite loop of making new calls and generating new rooms. I have attached my code below to help explain the issue.
public function index()
{
if (isset($_REQUEST['PhoneNumber'])) {
// The agent is making a call (outgoing)
$data['callerId'] = $this->users->getPhoneNumber($_REQUEST['Caller']);
$userIdExplode = explode(':', $_REQUEST['Caller']);
$data['userId'] = $userIdExplode[1];
$callTarget = $this->security->xss_clean($_REQUEST['PhoneNumber']);
$data['numberOrClient'] = "<Number>" . $callTarget . "</Number>";
$data['phoneIsOnline'] = $this->users->isPhoneOnline($data['userId']);
// Call log information
$data['ani'] = $data['callerId'];
$data['dnis'] = $callTarget;
} elseif (isset($_REQUEST['To'])) {
// The agent is receiving a call (incoming)
$callTarget = $this->security->xss_clean($_REQUEST['To']);
$data['userId'] = $this->users->getIdByPhoneNumber($callTarget);
$data['numberOrClient'] = "<Client>" . $data['userId'] . "</Client>";
$data['phoneIsOnline'] = $this->users->isPhoneOnline($data['userId']);
// Call log information
$data['ani'] = $_REQUEST['From'];
$data['dnis'] = $_REQUEST['To'];
}
// Log the new call and receive it's log ID
$data['callLogId'] = $this->call->logNewCall($data['ani'], $data['dnis'], $data['userId']);
// Load the TWIML (Twilio XML) to bring the caller into a conference room
$this->load->view('twilio/connections_twiml', $data);
// Bring the destination number into the same conference room as the origin number
$this->dialToConference($data['ani'], $data['dnis'], $data['callLogId']);
}
public function dialToConference($caller, $callee, $confNum)
{
// Twilio capability library (capable of incoming and outgoing calls)
include APPPATH . 'libraries/twilio/Services/Twilio.php';
// Twilio account codes required for the client
$accountSid = $this->config->item('twilio_accountSid');
$authToken = $this->config->item('twilio_authToken');
$client = new Services_Twilio($accountSid, $authToken);
$call = $client->account->calls->create(
$caller,
$callee,
BASE_URL . 'twilio/twilio_connections/loadConferenceTwiml?conferenceId=' . $confNum
);
}
I am sending emails via SendGrid with this inside the x-smtpapi header
$json_string = array(
'unique_args' => array (
'email_id' => 1
)
);
It all seems to send okay, inside SendGrid I can view the "email_id" in the Email activity under Unique Args.
However when I try to use the API to look at this email, I cannot find a way to actually get these unique arguments from the API.
I am using this to try and get the headers returned with the bounced emails.
$request = 'https://api.sendgrid.com/api/bounces.get.json&api_user=username&api_key=password'
All I get is just the email addresses that have bounced, not the header information (the unique arguments)
I want to know, is it possible to get the unique arguments from the API. I have read it multiple times to no avail.
I hope this makes sense.
Thanks
At present there's no way request to lookup specific events by unique_arg with the Web API.
However, the SendGrid Event Webhook will give you granular data on each event, such as a bounce as it happens. The Event Webhook POSTs data to your server every time an action is taken upon an email (e.g. open, click, bounce).
Once you receive it, you're responsible for storing this, although it's not a typical API it gives very specific data on events which you can then compile and rehash however you like.
To get started using the webhook, you'll do something like the following, and have SendGrid POST to the following script:
<?php
$data = file_get_contents("php://input");
$events = json_decode($data, true);
foreach ($events as $event) {
// Here, you now have each event and can process them how you like
process_event($event);
}
[Taken from the SendGrid Webhook Code Example]