I cannot figure out how to create a new contact group and assign it to the contact using google people api in php. An error
"person.memberships is a read only field."
occurs at $person->setMemberships():
$contactGroup=new Google_Service_PeopleService_ContactGroup();
//$contactGroup->setGroupType('USER_CONTACT_GROUP');
$contactGroup->setName('Some group');
$contactGroup->create();
$cgm=new Google_Service_PeopleService_ContactGroupMembership();
$cgm->setContactGroupId('groupID');
$membership=new Google_Service_PeopleService_Membership();
$membership->setContactGroupMembership($cgm);
$person=new Google_Service_PeopleService_Person();
$groupMemberships=array(($membership));
$person->setMemberships(array($groupMemberships));//error happens here
Anyone could help with a proper example of creating contact group and assigning it to the contact?
The following code assumes you have instantiated a Google_Client object, and have already created a person and know their ID.
Resource ID example,
$person_id = 'people/1234567890abcde';
Create a contact group,
$peopleService = new Google_Service_PeopleService($client);
$newContactGroup = new Google_Service_PeopleService_ContactGroup;
$newContactGroup->setName('New contact group');
$createContactGroupRequest = new Google_Service_PeopleService_CreateContactGroupRequest;
$createContactGroupRequest->setContactGroup($newContactGroup);
$contactGroup = $peopleService->contactGroups->create($createContactGroupRequest);
$contact_group_id = $contactGroup->getResourceName();
Add a person to contact group,
$peopleService = new Google_Service_PeopleService($googleClient);
$modifyContactGroupMembersRequest = new Google_Service_PeopleService_ModifyContactGroupMembersRequest;
$modifyContactGroupMembersRequest->setResourceNamesToAdd($person_id);
$peopleService->contactGroups_members->modify($contact_group_id, $modifyContactGroupMembersRequest);
You can't set members of the contact group in the creation call. You need to create the contact group in one call, then in a second call add it using members.modify api call.
Related
I am adding AWeber as an autoresponder in a web application. Using AWeber API, I am able to add a new subscriber to list with a known name which is in this case is firstlist:
$app = new MyApp();
$app->findSubscriber('whtever#aol.com');
$list = $app->findList('firstlist');
$subscriber = array(
'email' => 'someemail#gmail.com',
'name' => 'Name here'
);
$app->addSubscriber($subscriber, $list);
Function definition for findList() is:
function findList($listName) {
try {
$foundLists = $this->account->lists->find(array('name' => $listName));
return $foundLists[0];
}
catch(Exception $exc) {
print $exc;
}
}
As I am developing a public application, so I need to provide users an option to select from their available lists.
Please guide me how I can retrieve all the lists name.
You are returning $foundLists[0] so it will return single list. Try to return foundLists and check what it returns.
This may help you: https://labs.aweber.com/snippets/lists
In short, I pulled the lists by first finding the Aweber User Id so that I could use it in the URL https://api.aweber.com/1.0/accounts/<id>/lists
To find the User ID, I first got the account.
$this->aweber->getAccount($token['access'], $token['secret']);
Then, I retrieve the user's information.
$aweber_user = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts');
From that, I grabbed the user ID with...
$id = $aweber_user->data['entries'][0]['id'];
Once I had the user ID, I could then retrieve their lists with...
$lists = $this->aweber->loadFromUrl('https://api.aweber.com/1.0/accounts/'.$id.'/lists');
This example is more of a procedural approach, of course, I recommend utilizing classes.
I am using API version 1.3 of mailchimp to create Campaign programmatically in PHP.
I am using MCAPI class method campaignCreate() to create campaign. Campaign is created successfully and it returns campaign id in response which is string.
But i need Web id (integer value of campaign id) so that I can use it to open that campaign using link on my website.
For example: lets say I want to redirect user to this link - https://us8.admin.mailchimp.com/campaigns/show?id=941117 and for that i need id value as 941117 when new campaign is created.For now i am getting it as string like 6ae9ikag when new campaign is created using mailchimp API
Please let me know if anyone knows how to get campaign web id (integer value) using Mailchimp API in PHP
Thanks
I found an answer so wanted to share here.Hope it helps someone
I get campaign id as a string when createCampaign() method of MCAPI class is used.
You need to use below code to get web id (integer value of campaign id)
$filters['campaign_id'] = $campaign_id; // string value of campaign id
$campaign = $api->campaigns($filters);
$web_id = $campaign['data'][0]['web_id'];
This worked for me.
Thanks
<?php
/**
This Example shows how to create a basic campaign via the MCAPI class.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$type = 'regular';
$opts['list_id'] = '5ceacbda08';
$opts['subject'] = 'Test Newsletter Mail';
$opts['from_email'] = 'guna#test.com';
$opts['from_name'] = 'guna';
$opts['tracking']=array('opens' => true, 'html_clicks' => true, 'text_clicks' => false);
$opts['authenticate'] = true;
$opts['analytics'] = array('google'=>'my_google_analytics_key');
$opts['title'] = 'Test Newsletter Title';
$content = array('html'=>'Hello html content message',
'text' => 'text text text *|UNSUB|*'
);
$retval = $api->campaignCreate($type, $opts, $content);
if ($api->errorCode){
echo "Unable to Create New Campaign!";
echo "\n\tCode=".$api->errorCode;
echo "\n\tMsg=".$api->errorMessage."\n";
} else {
echo "New Campaign ID:".$retval."\n";
}
$retval = $api->campaignSendNow($retval);
?>
The web_id is returned by mailchimp when a call is made to the creation end point.
$mcResponce = $mailchimp_api->campaigns->create(...);
$web_id = $mcResponce['web_id'];
See the documentation.
This is the essential bit of PHP:
// Add subscription
$subscription = new Recurly_Subscription();
$subscription->plan_code = $planCode;
$subscription->currency = 'USD';
$subscription->quantity = 1;
if ($couponCode != "") { $subscription->coupon_code = $couponCode; }
$subscription->account = new Recurly_Account();
$subscription->account->account_code = $customerID;
$subscription->billing_info = new Recurly_BillingInfo();
$subscription->account->billing_info->token_id = $token;
$subscription->create();
When this code runs, $token has the tokenID created by an earlier call to recurly.token (...) with the billing info.
The account already exists on Recurly -- the account ID, first and last names, but no billing info. This is because we allow people to signup for a complimentary service before subscribing. So I want to create the subscription on the extant account. Initially, following the code examples, the create() call was subscription->account->create(). But that failed because the account existed already.
This sounds like an issue with the old PHP library, which did not support tokenization of billing information. An upgrade to the PHP client library should fix this issue.
I can record a contact from php toolkit, now i should attach contact to an existing opportunity, is this possible with the same way as adding custom field?
$records[0] = new stdclass();$records[0]->FirstName = 'Irish';
$records[0]->LastName = 'Paul';
$records[0]->Phone = '(510) 555-5555';
$records[0]->myCustomField__c= 'value1; value2';
Now to attach this with opportunity, how should i do?
Thank you
I am working of CIM (Customer information manager) and i have created customer profile using CIM function. But i want to get customer profile using customer id instead of customer profile id.
$cim = new AuthnetCIM('***MASKED***', '***MASKED***', AuthnetCIM::USE_DEVELOPMENT_SERVER);
$cim->setParameter('email', 'fakeemail#example.com');
$cim->setParameter('description', 'Profile for Joe Smith'); // Optional
$cim->setParameter('merchantCustomerId', '7789812');
//create profile function
$ss=$cim->createCustomerProfile();
//and get profile by..
$profile_id = $cim->getProfileID();
You can't. You can only get the profile using the profile ID. This means you'll want to store that ID in your database and associate it with the customer's record so whenever you need to get their profile you know what their Profile ID is.
Actually it is possible if you must, however I would still recommend storing it if possible, but this alternative might be of help.
Authorize.Net defines a unique customer profile by the composite key (Merchant Customer Id, Email, and Description), thus you must ensure this is unique. The CreateCustomerProfile(..) API method will enforce uniqueness and return an error if you attempt to create the same composite key again, as it should. However, the message in this response will contain the conflicting customer profile id, and since your composite key is unique, and Authorize.Net enforces uniqueness of this composite key, then this must be the Authorize.Net customer profile id of your customer.
Code sample in C#
private long customerProfileId = 0;
var customerProfile = new AuthorizeNet.CustomerProfileType()
{
merchantCustomerId = "123456789",
email = "user#domain.com",
description = "John Smith",
};
var cpResponse = authorize.CreateCustomerProfile(merchantAuthentication, customerProfile, ValidationModeEnum.none);
if (cpResponse.resultCode == MessageTypeEnum.Ok)
{
customerProfileId = cpResponse.customerProfileId;
}
else
{
var regex = new Regex("^A duplicate record with ID (?<profileId>[0-9]+) already exists.$", RegexOptions.ExplicitCapture);
Match match = regex.Match(cpResponse.messages[0].text);
if (match.Success)
customerProfileId = long.Parse(match.Groups["profileId"].Value);
else
//Raise error.
}