How to update a Podio category using PHP API - podio

I'm using a webhook to kick off a series of PHP scripts that take advantage of the Podio PHP API. I've tried using several different API calls but haven't been able to sort this out. This is a test file I'm using so the actual logic of what its doing doesn't make much sense. When I run the code below I get the error.
PHP Fatal error: Uncaught PodioBadRequestError: "Invalid value "status" (string): Not a valid option"
Request URL: http://api.podio.com/item/<removed>/value/<removed>
Stack Trace:
/data/www/default/contracts/lib/podio-php-master/lib/Podio.php(357):
Podio::request('PUT', '/item/<removed>...', Array)
/data/www/default/contracts/lib/podio-php-master/models/PodioItemField.php(55): Podio::put('/item/<removed>...', Array)
/data/www/default/contracts/test-category.php(25):
PodioItemField::update(<removed>, <removed>, Array, Array)
{main}
thrown in /data/www/default/contracts/lib/podio-php-master/lib/Podio.php on line 291`
Here is my code:
//dummy item_id
$item_id = 123456789;
//dummy field_id
$field_id = 987654321;
//Get the category field value
$item = PodioItem::get_field_value($item_id, $field_id);
//Create a variable with the text of the selected category option for validation
$button_value = $item[0]['value']['text'];
//Print the text of the selected option
print $button_value;
//Now that I have validated the current selection I want to change it
//These are the names of the attributes for my category
$my_attributes = array("status", "text", "id", "color");
//These are the values I want to update them to
$my_options = array("active","Generated",21,"DCEBD8");
//This should update the record in podio with the new values
PodioItemField::update($item_id, $field_id, $my_attributes, $my_options);
I reviewed all of the examples in the documentation but I feel like I'm missing something simple. Is anyone familiar with this that can tell me what I'm doing wrong? I've tried to comment the code to make it clear what I expect to be happing on each line but I can definitely clarify more if needed.

You are passing the attributes in the wrong method. To update the Category field you just pass the id of the option that you want to change in an array. So the $my_attributes array must be like,
$my_attributes = array(21);//id of the category option
And the $my_options array should like this,
$my_options = array('silent' => true, 'hook' => false);
This should update the item in Podio with the new values,
PodioItemField::update($item_id, $field_id, $my_attributes, $my_options);

Related

assert on network payload request in cypress

Im working on validating network payload request using cypress, I need to assert that property include an array with dynamically changing values as in the following example, I figured how to validate when there is only one array item that is not changing ["code 12332"],
expect(req.body.food.dogowner).to.be.instanceOf(Array)
expect(req.body.food.dogowner[0]).to.eq("code 12332")
but how do I do that if the property array keeps changing every time a user adds an item and the number of items added to the array git bigger (say 200 or more)
{
dogname :"time",
"dogact" :"some"
"dogcolor" :"something",
food:{
"foodone" :"chicken",
"foodtwo":"cheese",
}
dogowner :["code 12332" , "code 5445", " code 4555", "code 5554].......................................],
}
every time you check the request the code value array change and more codes are added to the payload array?
If you don't care about the value of the entire array, but just that it has a specific value, you could use Chai's include method.
expect(req.body.food.dogowner).to.be.instanceOf(Array)
expect(req.body.food.dogowner).to.include("code 12332")

Pymongo: insert_many() gives "TypeError: document must be instance of dict" for list of dicts

I haven't been able to find any relevant solutions to my problem when googling, so I thought I'd try here.
I have a program where I parse though folders for a certain kind of trace files, and then save these in a MongoDB database. Like so:
posts = function(source_path)
client = pymongo.MongoClient()
db = client.database
collection = db.collection
insert = collection.insert_many(posts)
def function(...):
....
post = parse(trace)
posts.append(post)
return posts
def parse(...):
....
post = {'Thing1': thing,
'Thing2': other_thing,
etc}
return post
However, when I get to "insert = collection.insert_many(posts)", it returns an error:
TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping
According to the debugger, "posts" is a list of about 1000 dicts, which should be vaild input according to all of my research. If I construct a smaller list of dicts and insert_many(), it works flawlessly.
Does anyone know what the issue may be?
Some more debugging revealed the issue to be that the "parse" function sometimes returned None rather than a dict. Easily fixed.

Amazon API -- Can I search Category ALL - Other than DVD etc?

I Am trying to build play with API code from Amazon -- I am a noob at this --
I have created a product search using the simple lookup code, and have gone though and set the search field form a form submission works fine, how ever I don't want to set a category Like I am currently below to say DVD, BABY MUSIC, I wish to set to ALL is this possible?
include("amazon_api_class.php");
$obj = new AmazonProductAPI(); -- I have edited this and added ALL as a category in here
try
{
$result = $obj->searchProducts($query,
AmazonProductAPI::BABY, -- I can change this to DVD or MUSIC and it works but if i set to ALL i get errors?
"TITLE"); - tryed changing this to KEYWORD doesnt work!
}
catch(Exception $e)
Any Help Would Be nice.
Thanks
Carl
OK --- updated -- ANd I belive I have to use KEYWORD when USING ALL so I have added this in
case "KEYWORD" : $parameters = array("Operation" => "ItemSearch",
"Title" => $search,
"SearchIndex" => $category,
"ResponseGroup" => "Small",
"MerchantId" => "All",
"Condition"=>"New",
'Keywords' => $searchTerm);
Warning: Invalid argument supplied for foreach() in /data/ADMINwhere2shoponline/www/include/amazon.php on line 23
still get this error?
carl
Carl,
You should be able to use ALL as the search parameter, but you need to make sure that the number of ItemPage you are requesting is not more than 5 or it will return an error. All other categories allow up to 10, but ALL is limited to 5.
Check that and see if you yet your problem resolved.

Check if an existing value is in a database

I was wondering how I would go about checking to see if a table contains a value in a certain column.
I need to check if the column 'e-mail' contains an e-mail someone is trying to register with, and if something exists, do nothing, however, if nothing exists, insert the data into the database.
All I need to do is check if the e-mail column contains the value the user is registering with.
I'm using the RedBeanPHP ORM, I can do this without using it but I need to use that for program guidelines.
I've tried finding them but if they don't exist it returns an error within the redbean PHP file. Here's the error:Fatal error: Call to a member function find() on a non-object in /home/aeterna/www/user/rb.php on line 2433
Here's the code that I'm using when trying this:
function searchDatabase($email) {
return R::findOne('users', 'email LIKE "' . $email . '"');
}
My approach on the function would be
function searchDatabase($email) {
$data = array('email' => $email);
$user = R::findOne('users', 'email LIKE :email, $data);
if (!empty($user)) {
// do stuff here
} // end if
} // end function
It's a bit more clean and in your function
Seems like you are not connected to a database.
Have you done R::setup() before R::find()?
RedBeanPHP raises this error if it can't find the R::$redbean instance, the facade static functions just route calls to the $redbean object (to hide all object oriented fuzzyness for people who dont like that sort of thing).
However you need to bootstrap the facade using R::setup(). Normally you can start using RB with just two lines:
require('rb.php'); //cant make this any simpler :(
R::setup(); //this could be done in rb.php but people would not like that ;)
//and then go...
R::find( ... );
I recommend to check whether the $redbean object is available or whether for some reason the code flow has skipped the R::setup() boostrap method.
Edited to account for your updated question:
According to the error message, the error is happening inside the function find() in rb.php on line 2433. I'm guessing that rb.php is the RedBean package.
Make sure you've included rb.php in your script and set up your database, according to the instructions in the RedBean Manual.
As a starting point, look at what it's trying to do on line 2433 in rb.php. It appears to be calling a method on an invalid object. Figure out where that object is being created and why it's invalid. Maybe the find function was supplied with bad parameters.
Feel free to update your question by pasting the entirety of the find() function in rb.php and please indicate which line is 2433. If the function is too lengthy, you can paste it on a site like pastebin.com and link to it from here.
Your error sounds like you haven't done R::setup() yet.
My approach to performing the check you want would be something like this:
$count = count(R::find('users', 'email LIKE :email', array(':email' => $email)));
if($count === 0)
{
$user = R::dispense('users');
$user->name = $name;
$user->email = $email;
$user->dob = $dob;
R::store($user);
}
I don't know if it is this basic or not, but with SQL (using PHP for variables), a query could look like
$lookup = 'customerID';
$result = mysql_fetch_array(mysql_query("SELECT columnName IN tableName WHERE id='".$lookup."' LIMIT 1"));
$exists = is_null($result['columnName'])?false:true;
If you're just trying to find a single value in a database, you should always limit your result to 1, that way, if it is found in the first record, your query will stop.
Hope this helps

Cannot add new Workitems using TFS API

Hi I am trying to add new workitems to the TFS repository using the API, but when I validate the workitem before it is saved, it returns an error. I previously got exceptions regarding the field definitions for a bug namely, Symptom, Steps to Reproduce and Triage. (Error code TF 26027). The code snippet is shown below: Can anyone tell me what's wrong here?
switch (workItemType)
{
case "Bug":
{
workItem.Title = values["Title"].ToString();
workItem.State = values["State"].ToString();
workItem.Reason = values["Reason"].ToString();
workItem.Fields["Priority"].Value = values["Priority"].ToString();
workItem.Fields["Severity"].Value = values["Severity"].ToString();
//workItem.Fields["Triage"].Value = values["Triage"].ToString();
workItem.Fields["Assigned To"].Value = values["Assigned To"].ToString();
//workItem.Fields["Symptom"].Value = values["Symptom"].ToString();
//workItem.Fields["Steps to Reproduce"].Value = values["Steps to Reproduce"].ToString();
// Validate the Work Item fields.
ArrayList result = workItem.Validate();
// If any invalid fields are returned, report an error.
if (result.Count > 0)
MessageBox.Show("An Error occurred while adding the Bug to the repository.");
else
workItem.Save();
}
break;
To find the available field definitions, you can iterate over the collection (FieldDefinitions). The Name and ReferenceName properties are the values you can index by into the collection.
the Field "Symptom" cannot be empty
Just reading the error message it looks like you are defining a field called "somefield" in your work item. I'm thinking that you have some old code hanging around elsewhere, maybe above the code snippet you posted, where you are defining a value for workItem.Fields["somefield"]
Old question, but hopefully helps someone. The field name is "Repro Steps"
.Fields["Repro Steps"].Value