Proper syntax for a POST call to a URL - php

I am having difficulty with the proper layout for this piece of code I have been talking with another IT support person and we are both at a bit of a loss
I am trying to utilize an API call and I am trying to come up with the proper syntax
I am using a PHP POST call and CURL along with an array of variable names and values for the most part it works
The problem is that a few variable names are not recognized and the other support person thought we needed to change things up a bit
The documentation states there may be a change we need to setup these variable ahead of time
the structure needs to be something like this CDATA block:
<profileFieldValues>
<fieldValue id="_sys_firstname">
<value>Jeff</value>
</fieldValue>
<fieldValue id="_sys_lastname">
<value>Johnson</value>
</fieldValue>
</profileFieldValues>
WE are using a structure like this
$fields = array(
'restype' => '2',
'username' => 'abc123',
...,
)
So what would the profileFieldValues block of code be written to work in the $fields array?
We were trying something like this but it was not correct
'profileFieldValues'=>"fieldValue id[]=>('_sys_firstname=>'value'=>'Charlie','_sys_lastname=>'value'=>'Brown')",
we received an error with this:
The user profile field elements are not properly formatted

Related

Need to pass dynamic values inside CURLOPT_POSTFIELDS

I have to make a post request and have done the same using postman for testing. Now, the code base is using php and I have never used php ever before. Upon checking the code section in postman, I got this:
CURLOPT_POSTFIELDS =>'{"datalist":[{
"Firstname":"firstname",
"Lastname":"lastname4",
"Email":"lead#test2.com",
"Phone":"9899999999",
"leadsource":"Website",
"address":"lakeview",
"pincode":"440010",
"Grade":"Class 1",
"utmcampaign":"summer_sale",
"utmcontent":"video_ad",
"utmmedium":"organic_social",
"utmterm":"social_media",
}
]}'
The problem is that I have to pass dynamic values instead of firstname, lastname4 etc.
The values I have are stored as such $lead['name'].
So, basically I have to pass $lead['name'] instead of lastname4 but I am not able to figure out the syntax.
You can use json_encode on an array to build the desired JSON string
$arr=array(
'datalist'=>array( array(
'Firstname'=>$lead['name'],
'Lastname'=>$lead['last'],
'Email'=>$lead['email'],
'Phone'=>$lead['phone'],
'leadsource'=>$lead['website'],
/*... etc */
)
) );
CURLOPT_POSTFIELDS=json_encode( $arr );

PHP and Protobuf FieldMasks for Google API

I found the documentation just fine, but for the life of me I can't figure out how to set up the FieldMasks in PHP to update a CloudSchedulerClient.
The command should be like this:
$client->updateJob($job, $updateMask); but no matter what I set the $updateMask variable to, my code keeps saying Expect Google\Protobuf\FieldMask. If for instance I wanted to update the description of a cron job to "test", 'description' => 'test', how should I go about that?
If you share some code, that would be helpful.
The error suggests that you are not providing the proper type. Your code should look something like this:
use Google\Protobuf\FieldMask;
$updateMask = new FieldMask([
'paths' => ['description']
]);
$client->updateJob($job, $updateMask);

Yii mass assignment from $_GET not working as expected

I'm trying to perform a mass assignment of 2 variables I'm sending via GET to another model::controller (from project::actionCreate to client::actionCreate)
In the _form view for project::actionCreate I've got the following:
<?php echo " ".Chtml::link('+New client',array('client/create',array('Client' => array('redir'=>Yii::app()->controller->route,'redirId'=>$model->id))));?>
With the goal of creating an array "Client" with attributes "redir" and "redirId".
In client::actionCreate I want to do something like
if(isset($_GET['Client']))
{
$model->attributes=$_GET['Client'];
}
Now I noticed that my $_GET var puts client inside subarray 0, so I've tried this with
$_GET[0]['Client']
as well, but no luck. However if I manually assign the variables like this:
$model->redir = $_GET[0]['Client']['redir'];
$model->redirId = $_GET[0]['Client']['redirId'];
Then it works.
Any idea what is up? The goal is to allow someone to create a new client while creating/updating a project record, by sending them to client::actionCreate, but redirecting them back to their original project::actionCreate if they were linked there from my "+New Client" link.
I think the client array is put inside subarray 0 because you've added an array around the parameters. Try removing the array like the following:
<?php
Chtml::link('+New client',array('client/create', 'Client' => array('redir'=>Yii::app()->controller->route,'redirId'=>$model->id)));
?>
I don't know what your model looks like but if the fields aren't assigned they are probably not safe. You can make them safe by adding them to the rules part of your model. Or you could try the following, by specifying the false parameter it will be possible to assign values to unsafe attributes. (http://www.yiiframework.com/doc/api/1.1/CModel#setAttributes-detail)
$model->setAttributes($_GET['Client'], false);
I am not sure creating a link like you want is possible. I have asked something similar some time ago Yii link with [ as a parameter I just could never get the link to how I wanted it. In the end I just created the link the old fashion way, not using CHTML.

Three JSON strings in one AJAX request conflicting in Zend

I have three different request for my ajax:
$result = Map_Model_Map_Factory::getCityByRegionAlias($alias);
$resultCountUsers = User_Model_User_Factory::countUserByRegion($alias);
$resultCountPartners = User_Model_User_Factory::countPartnersByRegion($alias);
First request works pretty well. But second and third conflicts with each other. If $this->_helper->json($resultCountUsers); comes first, then it works:
$this->_helper->json($resultCountUsers);
$this->_helper->json($resultCountPartners);
$this->_helper->json($result);
I get what I need countUsers: "1" but I don't have countPartners. And vice versa, if $this->_helper->json($resultCountPartners); comes first, then I get countPartners without countUsers.
Maybe somebody know, what's going on and how I can receive that.
I don't use Zend, but there is clearly a problem: you are not providing attribute names for the JavaScript object. I wonder whether you are overwriting each response with the next one.
See what effect this has in your AJAX viewer:
$this->_helper->json(
array(
'resultCountUsers' => $resultCountUsers,
'resultCountPartners' => $resultCountPartners,
'result' => $result,
)
);

How to mail to a static list segment with mailchimp API

Once I've identified identified the email addresses of my list segment (using get_emails() custom function, I am setting up my list segment as follows:
$batch = get_emails();
//now create my list segment:
$api->listStaticSegmentAdd(WEDDING_LIST_ID, 'new_wedding_guests');
$api->listStaticSegmentMembersAdd(WEDDING_LIST_ID, 'new_wedding_guests', $batch);
//do I build vars for a campaign?
$options = array (
'list_id' => WEDDING_LIST_ID, //What value id's my list segment?
'subject' => 'Alpha testing.',
'from_email' => 'wedding#juicywatermelon.com',
'from_name' => 'Pam & Kellzo',
'to_name' => $account->name,
);
From here can I use a basic campaign and send it?
$content['text'] = "Some text.";
$content['html'] = get_link($account);
$cid = $api->campaignCreate('regular', $options, $content);
$result = $api->campaignSendNow($cid);
I'm not sure if I'm understanding the api documentation correctly. I also tried 'list_id' => 'new_wedding_guests'; which failed to create a campaign.
Thanks!
I'll assume this is test code and just make the cursory mention of how you probably don't need to be creating a new Static Segment every time. However, your call to add members is not going to work. Per the listStaticSegmentMembersAdd documentation, you should be passing the static segment id, not the name of it. Also note that the docs cross-reference themselves when input params can come from other calls - that parameter there is a good example (it also happens to be returned by listStaticSegmentAdd).
Your options for campaignCreate look like a good start. The documentation for it has examples below - those examples are included in the PHP MCAPI wrapper you likely downloaded. As per above, the list_id you need is the one for the list you used in the listStaticSegment calls (also linked in the documentation).
Now the real key - further down in the campaignCreate docs is the segment_opts parameter - that is how you control segmentation. Follow the link it gives you and you'll find tons of info on the ways you can do segmentation, including using a static_segment.
Hopefully all of that made sense, if not, take a step back and check out these links (and play with segmentation in the app), then it should:
Introduction to MailChimp List Management
How can I send to a segment of my list?
Our Release Info on how Static Segments are used

Categories