I have test-driving for Mailchimp API v3 using your PHP wrapper. It's working great for me But when I'm creating a request using POST for "Create Segment" getting an error (attach screenshot):
Request Code is (through associative array) -
$api_key = "xxxxxxxxxxxxxxxx-us11";
$list_id = "1xx2xx3xx4xx";
$MailChimp = new MailChimp($api_key);
$result = $MailChimp->post('lists/' . $list_id . '/segments', array('name' => 'Testing Data',
'options' => array('match' => 'all',
'conditions' => array('field' => 'type', 'op' => 'is', 'value' => 'Testing'))
));
This request call returning following error -
array (size=2) 'field' => string 'options.conditions' (length=18)
'message' => string 'Schema describes array, object found instead'
(length=44)
I will also tried to create Request (through associative array) -
Method 1:
$api_key = "xxxxxxxxxxxxxxxx-us11";
$list_id = "1xx2xx3xx4xx";
$MailChimp = new MailChimp($api_key);
$result = $MailChimp->post('lists/' . $list_id . '/segments', array('name' => 'Testing Data',
'options' => array('match' => 'all',
'conditions' => array(array('field' => 'type', 'op' => 'is', 'value' => 'Testing')))
));
Method 2:
$api_key = "xxxxxxxxxxxxxxxx-us11";
$list_id = "1xx2xx3xx4xx";
$MailChimp = new MailChimp($api_key);
$result = $MailChimp->post('lists/' . $list_id . '/segments', array('name' => 'Testing Data 4',
'options' => array('match' => 'all',
'conditions' => array(array('field' => 'type'), array('op' => 'is'), array('value' => 'Testing')))
));
Both method will create segment on mailchimp account but not have any conditions. See screenshot -
How to override this problem?
You are missing the condition_type param. It should be selected from the list provided by MailChimp in the endpoint documentation.
For example, IF the field "type" from your MailChimp list is a text field you should use 'condition_type': 'TextMerge'. In this case, conditions should have the following format:
[
{
'condition_type': 'TextMerge',
'field': 'type',
'op': 'is',
'value': 'Testing'
}
]
However, MailChimp MAY have a bug in this endpoint, since TextMerge works only on the EMAIL field. I have also stumbled upon this problem recently:
Mailchimp api v3 - can't create segment based on a TEXT merge field
https://github.com/drewm/mailchimp-api/issues/160
Related
I use Onesignal notifications for the app.
I don't have a problem sending the notifications but wanted to send these notifications using API help and this library.
php-onesignal library
The notifications I sent must be opened on the relevant page in the application. For this reason, I do not know how to write the URL in the code section below.
require_once(dirname(__FILE__).'/vendor/autoload.php');
use CWG\OneSignal\OneSignal;
$appID = '92b9c6bb-89d2-4cbc-8862-a80e4e81a251';
$authorizationRestApiKey = 'MWRjMTg2MjEtNTBmYS00ODA4LWE1M2EtM2YyZjU5ZmRkNGQ5';
$deviceID = '69aeecc1-7b58-44d1-8000-7767de437adf';
$api = new OneSignal($appID, $authorizationRestApiKey);
$retorno = $api->notification->setBody('Ola')
->setTitle('Titulo')
->addDevice($deviceID)
->send();
I entered the addTag section as in the Onesignal panel, but I could not run it.
$retorno = $api->notification->setBody('Ola')
->setTitle('Titulo')
->addTag('url', 'http://www.example.com/news/testtitle')
->send();
print_r($retorno);
How can I use it here in the Url section of the "ADDITIONAL DATA" field?
Can I solve this problem with addTag?
The following will send a notification with the $data['data'] as additional, as you want.
$data = [
'headings' => ['en' => 'Case 123'],
'contents' => ['en' => 'Case assigned ' . date('d-m-Y H:i')],
'data' => [
'type' => 'new',
'user_id' => 123,
'url' => 'http://www.example.com/news/testtitle'
],
];
OneSignal::sendNotificationCustom([
'app_id' => 1234,
'api_key' => abcd,
'included_segments' => ['All'],
'headings' => $data['headings'],
'contents' => $data['contents'],
'data' => $data['data'],
]);
I am trying to consume soapclient based API of https://developer.signicat.com/documentation/signing/get-started-with-signing/full-flow-example/
There are tow methods of it
1- you have to upload a document and it returns you an SDS ID, this part works fine
2- then you need to use this SDS ID in second part of API to create a sign request method name is createRequest(),
This is where I am getting problem, I have passed all the parameters but still getting an error on one parameter which is xsi:type I am not sure how to pass this parameter from php array.
Here is the sample XML
<document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ref-sds-id="090520195vbxk9uuw4dks9tjm2pmpy7sx3na397xz6qclxtepaslnb00q7" send-to-archive="false" xsi:type="sds-document">
<sign-text-entry/>
<description>Loan contract.pdf</description>
</document>
here xsi:type="sds-document" this part is causing the issue
My Code:
$url = 'https://preprod.signicat.com/ws/documentservice-v3?wsdl';
$soap_setting = array(
"trace" => 1,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS + SOAP_USE_XSI_ARRAY_TYPE
);
$client = new SoapClient($url,$soap_setting);
$subject_type = $client->__getTypes();
$functions = $client->__getFunctions();
$subject = array(
'national-id'=> '198003010306',
'first-name' => 'Oskar',
'last-name' => 'Johansson',
'email' => 'kamran#creativerays.com'
);
$notification = array(
'recipient' => 'http://localhost/sign/php/',
'type' => 'URL',
'message' => 'Please seign ${taskUrl}',
'header'=> 'Test',
'notification-id' => '001'
);
$sdsdocument = array(
'ref-sds-id' => '100520193oz5vev0onyueul43ury4vz8g1hsnhr7w69pcwnoan96ojbtbb',
'send-to-archive' => true,
'description'=> 'test',
'sign-text-entry'=> 'test',
'xsi:type' => 'sds-document'
);
$documentaction = array(
'document'=> $sdsdocument,
'type'=> 'sign',
'optional'=> true,
'send-result-to-archive'=> true
);
$tasks = array(
'subject'=> $subject,
'document-action'=> $documentaction,
'notification'=> $notification,
'on-task-postpone'=> 'http://localhost/sign/php/?requestId=${requestId}&taskId=${taskId}&status=taskpostponed',
'on-task-complete'=> 'http://localhost/sign/php/?requestId=${requestId}&taskId=${taskId}&status=taskcomplete',
'on-task-cancel'=> 'http://localhost/sign/php/?requestId=${requestId}&taskId=${taskId}&status=taskcancelled',
'configuration'=> 'default',
'signature' =>array('method'=>'nbid-sign'),
'id'=> 'task00001',
'bundle'=> False
);
$request = array(
'language'=> 'en',
'task'=> $tasks
);
$tparam = array(
'service'=>'demo',
'password'=>'Bond007',
'request' =>$request
);
$create = $client->createRequest($tparam);
echo '<pre>';
print_r($create);
echo $client->__getLastRequestHeaders();
echo '</pre>';
The Error I am getting:
Fatal error: Uncaught SoapFault exception: [soap:Client] Failed to register new document action request: Document with id null must have subtype archive-document, sds-document, result-document, upload-document or provided-document
I'm using ZF2 Twitter package to get user info by username and retrieve it's location, but the returned object doesn't give me the "derived" property, that should have the detailed data about location I want to use.
public function twitterAction()
{
$config = array(
'access_token' => array(
'token' => 'MY TOKEN',
'secret' => 'MY SECRET',
),
'oauth_options' => array(
'consumerKey' => 'MY CONSUMER KEY',
'consumerSecret' => 'MY COMSUMER SECRET',
),
'http_client_options' => array(
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => array(
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
),
),
);
$twitter = new Twitter($config);
$response = $twitter->account->accountVerifyCredentials();
if (!$response->isSuccess()) {
die(var_dump($response->getErrors()));
}
$params = $this->params()->fromRoute();
$profile = $params['profile'];
$user = $twitter->users->show($profile);
$coordinates = $user->derived->geo->coordinates;
return new JsonModel(
[
'placeName' => $user->derived->locality . ' - ' $user->derived->region,
'link' => 'http://www.google.com/maps/place/'.$coordinates[0].','.$coordinates[1]
]
);
}
I'm using the twitter api page as reference
this is the response I get if I return the user
{
'placename: ': '-',
'link: ': 'http://www.google.com/maps/place/,',
}
How can I retrieve this data?
From that page:
Profile Geo data will be included in Twitter's PowerTrack, Replay, Volume Stream, Search, and Historical PowerTrack APIs.
I think that means the geo data is only available for paying customers of PowerTrack. If you're just a regular developer, you can't get it.
I got some example scripts from Facebook App Management to use the Marketing API. When I run the script, I just get this error by curl:
'Unsupported post request. Object with ID \'105101623679981\' does not exist, cannot be loaded due to missing permissions, or does not support this operation.
I already tried to deactivate the Sandbox Mode and go public, tried many different scripts in different languages and also other keys.
Any Ideas?
This is the Script:
<?php
//Add all those Uses and the autoloader
$access_token = '<my_very_long_accessToken';
$ad_account_id = '<my_account_id>'; //<-- This is the Object in the Error Code
$app_secret = '<my_app_secret>';
$page_id = '<my_page_id>';
$app_id = '<my_app_is>';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
);
$params = array(
'objective' => 'PAGE_LIKES',
'status' => 'PAUSED',
'buying_type' => 'AUCTION',
'name' => 'My Campaign',
);
$campaign = (new AdAccount($ad_account_id))->createCampaign(
$fields,
$params
);
$campaign_id = $campaign->id;
echo 'campaign_id: ' . $campaign_id . "\n\n";
$fields = array(
);
$params = array(
'status' => 'PAUSED',
'targeting' => array('geo_locations' => array('countries' => array('US'))),
'daily_budget' => '1000',
'billing_event' => 'IMPRESSIONS',
'bid_amount' => '20',
'campaign_id' => $campaign_id,
'optimization_goal' => 'PAGE_LIKES',
'promoted_object' => array('page_id' => $page_id),
'name' => 'My AdSet',
);
//...
Yeah. I got it. It has to be "act_"
So bad. The Script is really crappy. So many Errors. And it's created by facebook!
I am trying to create an Adfly shortener website for my associates to use using PHP. I thought this would be simple, but I am having some trouble getting this to work
$longURL = $_GET['longurl'];
$shortURL = shortAdfly($longURL);
// Print the result
print_r($shortURL);
// Adf.ly shortener
function shortAdfly($ToConvert) {
urlencode($ToConvert);
$apiUrl = 'http://api.adf.ly/api.php?' . http_build_query([
'key' => 'My API Key',
'uid' => 'My User ID',
'advert_type' => 'int',
'domain' => 'adf.ly',
'url' => $ToConvert ]);
$short_url = file_get_contents($apiUrl);
return $short_url;
}
Building URL query strings by hand is like encoding JSON by hand; you just shouldn't do it. Use the tools provided
$apiUrl = 'http://api.adf.ly/api.php?' . http_build_query([
'key' => 'your-api-key',
'uid' => 1234567,
'advert_type' => 'int',
'domain' => 'adf.ly',
'url' => $ToConvert
]);
return file_get_contents($apiUrl);