Podio's API documentation differs from podio-php's when it comes to creating new Items.
Based on Podio's tutorial, I would have to format each value according to its type, whereas podio-php describes using PodioItemFieldCollection to handle that for you. I prefer the latter option, but I keep getting this error:
Invalid value "1" (string): Not a valid option
I don't see much difference in my code versus the example given by podio-php. What's causing this error?
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id" => "my-text-field", "values" => "FooBar")),
new PodioProgressItemField(array("external_id" => "my-number-field", "values" => 75))
));
$atts = array(
'app' => new PodioApp($app_id),
'fields' => $fields
);
$item = new PodioItem($atts);
No errors caught up to here. But when I try to save...
$response = $item->save();
Invalid value "1" (string): Not a valid option
The $app_id was being passed in as a string. I've had this issue now with a few different ID values returned in an API response. I explicitly cast the value as an integer and the error went away:
$atts = array(
'app' => new PodioApp((int)$app_id),
'fields' => $fields
);
Related
UPDATE:
As it turns out, I need to enable this setting for data to show up, and using tabs is the correct thing to do.
When an envelope is sent, write the initial value of the field for all recipients
=================================================================
Not sure why this one is not mentioned in API properly ... but how does one go about filling template's custom data label with template?
So, I create a template like this:
$envelope_definition = new EnvelopeDefinition([
'status' => 'sent',
'template_id' => $args['template_id'],
]);
then I create a signer:
$signer = new TemplateRole([
'email' => $args['signer_email'],
'name' => $args['signer_name'],
'role_name' => 'signer',
]);
Here is where the disconnect happened, where do I add a pre-defined template value? I tried two things so far:
1. Add tabs to $signer like so, but by doing so, it ereases all field value in the final document,
new Tabs([
"text_tabs" => [
new Text([
"tab_label" => "price",
"value" => "123456789",
]),
],
]),
Call $envelope_definition->setCustomFields() , like this :
$envelope_definition->setCustomFields(new CustomFields([
'text_custom_fields' => [
'price' => new Text([
'tab_label' => 'price',
'custom_tab_id' => 'price',
'value' => '123456789',
]),
],
]));
It will throw me a C# error, which I don't understand at all:
Error while requesting server, received a non successful HTTP code [400] with response Body: O:8:\"stdClass\":2:{s:9:\"errorCode\";s:20:\"INVALID_REQUEST_BODY\";s:7:\"message\";s:718:\"The request body is missing or improperly formatted. Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[API_REST.Models.v2_1.textCustomField]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'customFields.textCustomFields.price', line 1, position 45.\";}"
API docs seems to be focusing on creating template and values adhoc ... anyone have something that works? Thanks a lot!
You can find valid PHP example here which shows how to prepopulate template tab values while creating an envelope.
You didn't follow the example correctly.
You didn't create a \DocuSign\eSign\Model\TextCustomField object.
Here it is from Amit's link:
# Create an envelope custom field to save the our application's
# data about the envelope
$custom_field = new \DocuSign\eSign\Model\TextCustomField([
'name' => 'app metadata item',
'required' => 'false',
'show' => 'true', # Yes, include in the CoC
'value' => '1234567']);
$custom_fields = new \DocuSign\eSign\Model\CustomFields([
'text_custom_fields' => [$custom_field]]);
$envelope_definition->setCustomFields($custom_fields);
I have a Podio app which is populated by the php API via a form on a website.
Using the Create Item snippet works for text fields, currency values, etc but have been I unable to untangle the documentation as to how to set a category field.
The category field, "attending", is a simple yes/no choice.
The method shown here generates a server error when combined with Create Item snippet as below:
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id" => "title", "values" => $name)),
new PodioTextItemField(array("external_id" => "email", "values" => $email)),
));
$item = new PodioItem(array(
'app' => new PodioApp(intval($app_id)),
'fields' => $fields,
));
pseudo code: if attending = yes, $attending = 1, else $attending = 2 //id's of yes and no in category field
$item->fields['attending']->values = $attending;
$item->save();
What am I missing? Thanks.
For those still searching for an answer: The trick is to use an array.
Perform the evaluation of $attending before opening the Collection and then simply
add this line into the PodioItemFieldCollection.
new PodioCategoryItemField(array(
'external_id' => 'attending', 'values' => array($attending))),
So the whole snippet would look like this
($foo == 'yes') ? $attending = 1: $attending = 2 ; // evaluating $foo for yes
$fields = new PodioItemFieldCollection(array(
new PodioTextItemField(array("external_id" => "title", "values" => $name)),
new PodioTextItemField(array("external_id" => "email", "values" => $email)),
new PodioCategoryItemField(array(
'external_id' => 'attending', 'values' => array($attending))) // must be an array
));
$item = new PodioItem(array(
'app' => new PodioApp(intval($app_id)),
'fields' => $fields,
));
$item->save();
You can find examples at: http://podio.github.io/podio-php/fields/#category-field
If it's still not working, place podio-php into debug mode so you can see what data is being sent to Podio: http://podio.github.io/podio-php/debug/
I have an item with a referenced field to another app. A call has an assigned client.
I use this library: http://podio.github.io/podio-php/
I followed this article: http://podio.github.io/podio-php/fields/
I want to update an existing item by changing the item_id of its field that's referencing another app. The item_id already exists in the other app.
Here's what I tried (this happens when a Webhook is triggered):
$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
AND
$item = PodioItem::get($_POST['item_id']);
$item->fields['client']->values = array('item_id' => $id_client);
$item->save(array(
'hook' => false,
'silent' => true
));
Where 'client' is the external id of the field and $id_client is an integer number.
Here's the error I get:
[18-Aug-2014 17:33:30 UTC] PHP Notice: Indirect modification of overloaded property PodioItem::$field has no effect in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66
[18-Aug-2014 17:33:30 UTC] PHP Warning: Creating default object from empty value in /home1/magikweb/public_html/dev/magik-net/helpdesk/webhook/call.php on line 66
If anyone could explain to me why this isn't working I'd be really grateful. The provided documentation is not clear on that subject.
Thank you!
SOLUTION
I got it to work this way, credits to Andreas:
if(!isset($item->fields['client']->values[0]->item_id)){
$item->fields['client'] = new PodioAppItemField();
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
}
You're getting this error because the client field doesn't exist on your item yet. So you're trying to set values for something that doesn't exist.
You need to do something like (untested, but should work):
$item = PodioItem::get($_POST['item_id']);
if (!isset($item->fields['client'])) {
$item->fields['client'] = new PodioAppItemField();
}
$item->fields['client']->values = array(
array('item_id' => $id_client)
);
$item->save(array(
'hook' => false,
'silent' => true
));
When you get an item from Podio you won't get all fields in the app, only that ones that have values for that particular item. So you have to check if your particular field is present before trying to set values on it.
I am trying to use a WSDL web service with php/soap. And it always gives a deserializing error which is exactly:
Error in deserializing body of request message for operation 'Test'. OperationFormatter encountered an invalid Message body. Expected to find node type 'Element' with name 'Test' and namespace ''. Found node type 'Element' with name 'parameters' and 'namespace'
When I test the WSDL source with WcfTestClient software nothing goes wrong and it returns with desired results.
When I compare the request XML which created by SOAP and XML which created by WcfTestClient software, I see that difference may be the problem. It seem like something wrong with namespace and prefixes, but I don't know how to solve it, or maybe it is something else causes the problem.
The request XMLs is this: http://pastebin.com/eysnG89F.
In case you need PHP code, this is the code I am using.
try{
$soap_options = array(
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => TRUE
);
$soap = new SoapClient(
'http://url.to/web/service.svc?wsdl', $soap_options
);
$a = $soap->Test(
array("login" =>
array(
"FirmaId" => 15,
"KullaniciAdi" => "Asdf",
"Parola" => "Xyxy",
)
)
);
var_dump($a);
} catch (Exception $e) {
var_dump($e);
}
I cant find the exact cause and solution but this seems like working.
First, when you give object instead of array for the wsdl method, you can get rid of item, value nodes. Node will be created by object name
$a = $soap->Test(
(object)array("login" =>
(object)array(
"FirmaId" => 15,
"KullaniciAdi" => "Asdf",
"Parola" => "Xyxy",
)
)
);
After that i realized an < parameters> node instead of < WsdlMethod> node created in request xml. With overriding __doRequest method and replacing strings, can get rid this problem but still cant see the response. Need to wrap < wsdlMethodResponse> node with < parameter> via str_replace and finally get desired response.
As i said this may be a temporary solution. But working for me :)
I'm using Zend_Validate to validate some form input (Zend Framework version is 1.8.2). For some reason, using the Zend_Filter_Input interface as described here does not work:
$data = $_POST;
$filters = array('*' => array('StringTrim'));
$validators = array('driverName' => array('NotEmpty','messages' => 'This should override the default message but does not!'));
$inputFilter = new Zend_Filter_Input($filters,$validators,$data);
$messages = $inputFilter->getMessages();
debug($messages); //show me the variable contents
Output from debug($messages):
Array
(
[driverName] => Array
(
[isEmpty] => You must give a non-empty value for field 'driverName'
)
)
No matter what I do, I cannot override that message. If I use the validator directly, i.e.:
$notEmpty = new Zend_Validate_NotEmpty();
$notEmpty->setMessage('This WILL override the default validation error message');
if (!$notEmpty->isValid($_POST['driverName'])) {
$messages = $notEmpty->getMessages();
debug($messages);
}
Output from debug($messages):
Array
(
[isEmpty] => Please enter your name
)
Bottom line. I can get validators to work, but without the benefits of the Zend_Filter_Input interface method of validation I might as well write my own validation class!
Does anyone have a clue as to why this is happening, and how to fix it?
Could it be a bug?
The messages key in the validator array must be passed an array of key/value pairs, where the key is the validation message constant, and the value is your custom error message. Here's an example:
$validators = array(
'excerpt' => array(
'allowEmpty' => true,
array('StringLength', 0, Ctrl::getOption('blog/excerpt/length')),
'messages' => array(Zend_Validate_StringLength::TOO_LONG => 'The post excerpt must not exceed '.Ctrl::getOption('blog/excerpt/length').' characters.')
),
);
However, in your case, the error message you are receiving is coming from the the allowEmpty meta command of Zend_Filter_Input. This isn't really a standard validator. You can set it like so:
$options = array(
'notEmptyMessage' => "A non-empty value is required for field '%field%'"
);
$input = new Zend_Filter_Input($filters, $validators, $data, $options);
// alternative method:
$input = new Zend_Filter_Input($filters, $validators, $data);
$input->setOptions($options);
If you need a different not empty message per field, I'd recommend setting allowEmpty => true and adding a NotEmpty validator with a custom message.
For your reference, the correct message key for the NotEmpty validator is Zend_Validate_NotEmpty::IS_EMPTY
The MESSAGES argument takes an array, not a string. Try this:
$validators = array('driverName' =>
array('NotEmpty',
'messages' => array(
0 => 'This should override the default message but does not!'
)
)
);
It's a bug, it's in the JIRA of Zend Framework...