1

I am using php wrapper, try create an item, all is ok, item is creating, but I can't change status, tried different ways, but can't find right way.

Need change status to "Closed" - http://prntscr.com/fsrwc3

Codes not works:

$fields = new PodioItemFieldCollection([
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
    'app' => new PodioApp($app_id),
    'fields' => $fields
]);
$item->save();

or

$fields = new PodioItemFieldCollection([
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
    'app' => new PodioApp($app_id),
    'fields' => $fields
]);
$item->save();
$get_item = PodioItem::get_basic($item->item_id);
$get_item->fields['status']->values = ['id'=>13];
$get_item->save();

After create item (after new PodioItem...), if I get fields after this code (just get $item->fields or PodioItem::get_basic...), I can see correct status, only in the code, only immediatly after create item, but if I get this item in the another code (just PodioItem::get_basic...) I will see default value, so code don't change status, looks like I just see some cache.

If I create item on the one script:

$fields = new PodioItemFieldCollection([
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>13]),
]);
$item = new PodioItem([
    'app' => new PodioApp($app_id),
    'fields' => $fields
]);
$item->save();

Then, in the another script update field, it will be change:

$get_item = PodioItem::get_basic('639637317');
$get_item->fields['status']->values = ['id'=>13];
$get_item->save();

Update - debug information:

Get log by test code -

PodioItem::create($app_id, ['fields' => ['status'=>[13], 'category'=>[3], 'contract-type'=>[4]]]);

(simple variant for creating an item, have the same problems like new PodioItem... )

All fields have category type, but:

status - have inline show type - don't chnages

category - have dropdown show type - Is changing

contract-type - have dropdown show type - Is changing

Log:

2017-07-08 11:07:22 200 POST /item/app/12152727/
2017-07-08 11:07:22 Request body: {"fields":{"status":[8],"category":[3],"contract-type":[4]}}
2017-07-08 11:07:22 Reponse: {
"presence": {
    "ref_type": "item",
    "ref_id": 641331142,
    "user_id": 4194774,
    "signature": "c165b85090e6ad28e74ae4baf93ee56113f88bc9"
},
"app": {
    "status": "active",
    "sharefile_vault_url": null,
    "name": "Projects",
    "default_view_id": null,
    "url_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new",
    "icon_id": 378,
    "link_add": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/new",
    "app_id": 12152727,
    "current_revision": 141,
    "item_name": "Project",
    "link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects",
    "url": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects",
    "url_label": "projects",
    "config": {
        "item_name": "Project",
        "icon_id": 378,
        "type": "standard",
        "name": "Projects",
        "icon": "378.png"
    },
    "space_id": 3466816,
    "icon": "378.png"
},
"created_on": "2017-07-10 15:31:16",
"last_event_on": "2017-07-10 15:31:16",
"linked_account_data": null,
"sharefile_vault_folder_id": null,
"app_item_id_formatted": "3988",
"recurrence": null,
"title": "ACSC",
"participants": {},
"created_by": {
    "user_id": 4194774,
    "name": "Anton Mikhailov",
    "url": "https:\/\/podio.com\/users\/4194774",
    "type": "user",
    "image": null,
    "avatar_type": "file",
    "avatar": null,
    "id": 4194774,
    "avatar_id": null,
    "last_seen_on": "2017-07-10 15:31:15"
},
"priority": 641331142.0,
"created_via": {
    "url": null,
    "auth_client_id": 25162,
    "display": true,
    "name": "importer",
    "id": 25162
},
"subscribed_count": 1,
"reminder": null,
"ref": null,
"revision": 0,
"app_item_id": 3988,
"link": "https:\/\/podio.com\/acs-1com\/project-management\/apps\/projects\/items\/3988",
"item_id": 641331142,
"sharefile_vault_url": null,
"rights": ["subscribe", "grant", "add_conversation", "rate", "update", "delete", "add_file", "grant_view", "view", "comment", "add_task"],
"fields": [{
    "status": "active",
    "type": "category",
    "field_id": 93352415,
    "label": "Division",
    "values": [{
        "value": {
            "status": "active",
            "text": "ACSC",
            "id": 3,
            "color": "D2E4EB"
        }
    }],
    "config": {
        "default_value": null,
        "unique": false,
        "description": null,
        "hidden_create_view_edit": false,
        "required": true,
        "mapping": null,
        "label": "Division",
        "visible": true,
        "delta": 5,
        "hidden": false,
        "settings": {
            "multiple": false,
            "options": [{
                "status": "active",
                "text": "ACSE",
                "id": 1,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "ACSB",
                "id": 2,
                "color": "F7F0C5"
            }, {
                "status": "active",
                "text": "ACSC",
                "id": 3,
                "color": "D2E4EB"
            }],
            "display": "dropdown"
        }
    },
    "external_id": "category"
}, {
    "status": "active",
    "type": "category",
    "field_id": 148215928,
    "label": "Contract Type",
    "values": [{
        "value": {
            "status": "active",
            "text": "No Contract",
            "id": 4,
            "color": "DDDDDD"
        }
    }],
    "config": {
        "default_value": null,
        "unique": false,
        "description": null,
        "hidden_create_view_edit": false,
        "required": true,
        "mapping": null,
        "label": "Contract Type",
        "visible": true,
        "delta": 7,
        "hidden": false,
        "settings": {
            "multiple": false,
            "options": [{
                "status": "active",
                "text": "PO \/ Purchase \/ T&M",
                "id": 1,
                "color": "FFD5C2"
            }, {
                "status": "active",
                "text": "Original Contract",
                "id": 2,
                "color": "D2E4EB"
            }, {
                "status": "active",
                "text": "Service Rider",
                "id": 3,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "No Contract",
                "id": 4,
                "color": "DDDDDD"
            }],
            "display": "dropdown"
        }
    },
    "external_id": "contract-type"
}, {
    "status": "active",
    "type": "category",
    "field_id": 93034840,
    "label": "Instal Status",
    "values": [{
        "value": {
            "status": "active",
            "text": "Closed",
            "id": 13,
            "color": "E1D8ED"
        }
    }],
    "config": {
        "default_value": null,
        "unique": false,
        "description": null,
        "hidden_create_view_edit": false,
        "required": true,
        "mapping": null,
        "label": "Instal Status",
        "visible": true,
        "delta": 13,
        "hidden": false,
        "settings": {
            "multiple": false,
            "options": [{
                "status": "deleted",
                "text": "To Be Reviewed",
                "id": 2,
                "color": "F7F0C5"
            }, {
                "status": "deleted",
                "text": "ACS Accounting Review",
                "id": 5,
                "color": "FFD5C2"
            }, {
                "status": "deleted",
                "text": "Ignite Setup",
                "id": 10,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "To Be Scheduled",
                "id": 8,
                "color": "D2E4EB"
            }, {
                "status": "active",
                "text": "In Progress",
                "id": 6,
                "color": "DCEBD8"
            }, {
                "status": "active",
                "text": "Warranty",
                "id": 11,
                "color": "F7F0C5"
            }, {
                "status": "active",
                "text": "Complete",
                "id": 3,
                "color": "D1F3EC"
            }, {
                "status": "deleted",
                "text": "Closed",
                "id": 7,
                "color": "DDDDDD"
            }, {
                "status": "active",
                "text": "Cancelled",
                "id": 9,
                "color": "DDDDDD"
            }, {
                "status": "deleted",
                "text": "VA in Progress",
                "id": 4,
                "color": "E1D8ED"
            }, {
                "status": "deleted",
                "text": "Submitted",
                "id": 1,
                "color": "F7F0C5"
            }, {
                "status": "active",
                "text": "On Hold",
                "id": 12,
                "color": "F7D1D0"
            }, {
                "status": "active",
                "text": "Closed",
                "id": 13,
                "color": "E1D8ED"
            }],
            "display": "inline"
        }
    },
    "external_id": "status"
}],
"initial_revision": {
    "item_revision_id": 1664054437,
    "created_via": {
        "url": null,
        "auth_client_id": 25162,
        "display": true,
        "name": "importer",
        "id": 25162
    },
    "created_by": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "created_on": "2017-07-10 15:31:16",
    "user": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "type": "creation",
    "revision": 0
},
"current_revision": {
    "item_revision_id": 1664054437,
    "created_via": {
        "url": null,
        "auth_client_id": 25162,
        "display": true,
        "name": "importer",
        "id": 25162
    },
    "created_by": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "created_on": "2017-07-10 15:31:16",
    "user": {
        "user_id": 4194774,
        "name": "Anton Mikhailov",
        "url": "https:\/\/podio.com\/users\/4194774",
        "type": "user",
        "image": null,
        "avatar_type": "file",
        "avatar": null,
        "id": 4194774,
        "avatar_id": null,
        "last_seen_on": "2017-07-10 15:31:15"
    },
    "type": "creation",
    "revision": 0
},
"linked_account_id": null,
"push": {
    "timestamp": 1499700676,
    "expires_in": 21600,
    "channel": "\/item\/641331142",
    "signature": "b8a816ff367da6bc730071c875ca3fdca2d2c344"
},
"external_id": null
}
Toxa
  • 63
  • 1
  • 7

1 Answers1

2

Have you tried http://podio.github.io/podio-php/fields/#category-field ?

Setting values
Set a single value by using the option_id. You can also add a value with add_value()

$item = PodioItem::get_basic(123);
$field_id = 'category';

// Set value to a single option
$item->fields[$field_id]->values = 4; // option_id=4

// Add value to existing selection
$item->fields[$field_id]->add_value(4); // option_id=4

Use an array to set multiple values

$item = PodioItem::get_basic(123);
$field_id = 'category';
$item->fields[$field_id]->values = array(4,5,6); // option_ids: 4, 5 and 6

Creating item with value:

$fields = new PodioItemFieldCollection([
    new PodioCategoryItemField(['external_id'=>'status', 'values'=>array(13)]),
]);
$item = new PodioItem([
    'app' => new PodioApp($app_id),
    'fields' => $fields
]);
$item->save();
Pavlo - Podio
  • 2,003
  • 2
  • 10
  • 19
  • it works only after restart the script, when I create an item and immediately set the value (by your method or my), it not works. If I just get existing item and change status it works. I need set status when I create an item, in the same session, it will be the best way. – Bookin Jul 07 '17 at 11:03
  • Can you please create 2 examples and explain on them what is working and what is not? Please also include values that you can see from Podio UI. – Pavlo - Podio Jul 07 '17 at 11:49
  • Updated question – Toxa Jul 07 '17 at 12:12
  • 1
    Updated answer: trick is `'values'=>13` should be `'values'=>array(13)` (btw, your question is still hard to understand, would you rewrite it? and keep only 2 pieces of code to explain what is working and what is not) – Pavlo - Podio Jul 07 '17 at 14:01
  • I see source code and 'values'=>13 and 'values'=>array(13) have the same effects, and send the same data in the request - `"fields":{"status":[13]}`, so, it same not works – Toxa Jul 07 '17 at 14:11
  • Updated question, sorry for my english, now better? – Toxa Jul 07 '17 at 14:20
  • It's better, thanks, where this part came from `['id'=>13]` There should be no `id`s here? I've also updated an answer to use just arrays. – Pavlo - Podio Jul 07 '17 at 15:17
  • Sorry, didn't understand what did you mean. Check now, `$get_item->fields['status']->values = 13` - also works.`add_value()` - not works, but because field don't support multiplay. Anyway, it is for update, but don't work for create item. About just array, it get error `'PodioDataIntegrityError' with message 'Field must have id or external_id set.'` – Toxa Jul 07 '17 at 16:03
  • is it possible that you have another field called 'status' ? – Pavlo - Podio Jul 07 '17 at 16:14
  • Interesting, when I create item, I can change field type 'category', like this - http://prntscr.com/fsvkyf, but can't change value for like this - http://prntscr.com/fsrwc3 – Toxa Jul 07 '17 at 17:00
  • Can you please get full details of https request that is sent to api.podio.com when item is created? This is curl example that works for sure, and you need to find php equivalent to get same request. `curl -H "Content-Type: application/json" -H "Authorization: OAuth2 <--->" -X POST -d '{"fields":{"title":"category set to [3]","category":[3]}}' https://api.podio.com/item/app/` – Pavlo - Podio Jul 07 '17 at 20:01
  • @Pavlo-Podio - perhaps, new any ideas? – Bookin Jul 09 '17 at 18:48
  • @Toxa - mmm, can you share full response that you get when create item? (also include request, so it will be clearly visible that request has status=4 and response status=0, or something like that) – Pavlo - Podio Jul 09 '17 at 23:38
  • @Pavlo-Podio - I added full response, I wrote before that it returns correct response, as if I changed field, but it is wrong, after restart and get information about item I will get default value – Toxa Jul 10 '17 at 15:34
  • I don't see anything wrong with request/response that you've shared. Item is created as needed, each field matches ("status":[8],"category":[3],"contract-type":[4]), so I assume that item is created well. How do you check item after creation? – Pavlo - Podio Jul 10 '17 at 18:23
  • @Pavlo-Podio For check I or open dashboard or use `PodioItem::get_basic(...');` – Bookin Jul 10 '17 at 19:36
  • So, can you include PodioItem::get_basic() request and response? – Pavlo - Podio Jul 10 '17 at 20:25
  • Looks like problem with 'GlobiFlow' service, I will write when I will test it – Toxa Jul 12 '17 at 21:09