Laravel / Mongodb - How to delete a single / multiple keys from the documents - php

In the mongodb database I have multiple documetns and each document contain this type of data:
{
"_id": {
"$oid": "636b7f0f889929ce62194c28"
},
"id": "SK7732.1825+1",
"aff_link": "https://go.linkwi.se/z/11593-0/CD24352/?lnkurl=https%3A%2F%2Fwww.celestino.gr%2Fel-GR%2Fpanteloni-me-pietes-lefko%2Fprd%2FSK7732.1825%2F7%3Faffiliate%3Dlinkwise%26utm_source%3Dlinkwise%26utm_medium%3Dlw%26utm_campaign%3Dlw",
"availability": "Y",
"brand": "Celestino",
"color": [],
"date_add": 1667989263,
"date_upd": 1674697681,
"description": "Παντελόνι με πιέτες, κλείσιμο με φερμουάρ και κουμπί, θηλιές στη μέση, με τσέπες, λευκο",
"image_link": "https://2ccdn.celestino.gr/small/SK7732.1825-7#1F.JPG",
"link": "https://www.celestino.gr/el-GR/panteloni-me-pietes-lefko/prd/SK7732.1825/7?affiliate=linkwise&utm_source=linkwise&utm_medium=lw&utm_campaign=lw",
"part_number": "SK7732.1825.1",
"price": "13,99",
"product_type": "Παντελόνια/Παντελόνια",
"sizes_in_stock_feed": "S",
"title": "Παντελόνι με πιέτες SK7732.1825+1",
"update_history": [
{
"id_feed": 169,
"feed_name": "from linkwise",
"date_upd": 1674689686,
"field_history": []
},
{
"id_feed": 170,
"feed_name": "scrape info",
"date_upd": 1674697681,
"field_history": [
{
"field_name": "all_sizes",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "sizes_in_stock",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "breadcrumbs",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "breadcrumbs_url",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
},
{
"field_name": "color",
"removable": 1,
"updatable": 1,
"date_upd": 1674697681
}
]
}
],
}
From this data I can get the data based on id .for example:
$get_product = DB::connection('mongodb')->collection( $collection )->where( 'id', $id )->first();
Now, Is there anyway I can delete single or multiple keys from the document based on id?
For example, I want to delete the aff_link and availability key.

Related

Skipping an object if one of the attributes is null in laravel

Task: you need to get a students object, with the conditions "group_id*" and "specialty_*id", where all these 3 tables are connected. It is also necessary to paginate only those objects of students for whom a group and specialty was found.
My problem: if the group or specialty data is not found, then the object is still added with the "group: null" attribute to pagination, thereby failing to display the requested number of elements on the page. How can this problem be solved?
The code:
$students = Student::with([
"group" =>
function($query) {
$query->where("id", \request("group_id"));
},
"group.speciality" =>
function($query) {
$query->where("id", \request("speciality_id"));
},
])->paginate(\request("page_size") ? : 10)->toArray();
return response()->json($students);
Preview: when I make a request with parameters
group_id = 2
speciality_id = 2
page_size = 2
The following object is returned:
{
"current_page": 1,
"data": [
{
"id": 1,
"receipt_date": "2010-11-02",
"user": {
"id": 1,
"login": "ykirillova#gmail.com",
"phone": "+7 (922) 472-9240",
"role": "user",
"passport": {
"series": 1762,
"number": 384282,
"date_of_issue": "1991-11-27",
"issued": "magni",
"division_code": 3,
"scan": "*photo link*",
"secondname": "Kilikova",
"firstname": "Olga",
"thirdname": "Anisimova",
"birthday": "1973-05-13",
"sex": "W"
}
},
"group": {
"id": 2,
"group_code": "4433",
"speciality": {
"id": 2,
"specialty_title": "Programming in computer systems",
"faculty": "SPO IKTZI"
}
}
},
{
"id": 2,
"receipt_date": "1973-11-07",
"user": {
"id": 2,
"login": "marta.fedorov#dackov.net",
"phone": "+7 (922) 903-0339",
"role": "user",
"passport": {
"series": 8241,
"number": 419233,
"date_of_issue": "1980-06-05",
"issued": "quos",
"division_code": 33,
"scan": "*photo link*",
"secondname": "Efremov",
"firstname": "Boleslav",
"thirdname": "Kostin",
"birthday": "2009-04-03",
"sex": "W"
}
},
"group": null
}
],
"per_page": "2",
"total": 75
}
Whereas with group == null, only 2 objects with groups should be returned
{
"current_page": 1,
"data": [
{
"id": 1,
"receipt_date": "2010-11-02",
"user": {
"id": 1,
"login": "ykirillova#gmail.com",
"phone": "+7 (922) 472-9240",
"role": "user",
"passport": {
"series": 1762,
"number": 384282,
"date_of_issue": "1991-11-27",
"issued": "magni",
"division_code": 3,
"scan": "*photo link*",
"secondname": "Kilikova",
"firstname": "Olga",
"thirdname": "Anisimova",
"birthday": "1973-05-13",
"sex": "W"
}
},
"group": {
"id": 2,
"group_code": "4433",
"speciality": {
"id": 2,
"specialty_title": "Programming in computer systems",
"faculty": "SPO IKTZI"
}
}
},
{
"id": 5,
"receipt_date": "2002-07-05",
"user": {
"id": 5,
"login": "tester#mail.ru",
"phone": "+7 (800) 555-3535",
"role": "user",
"passport": {
"series": 5521,
"number": 866521,
"date_of_issue": "1980-06-05",
"issued": "quos",
"division_code": 33,
"scan": "*photo link*",
"secondname": "Pavlov",
"firstname": "Denis",
"thirdname": "Artemev",
"birthday": "2009-04-03",
"sex": "W"
}
},
"group": {
"id": 2,
"group_code": "4433",
"speciality": {
"id": 2,
"specialty_title": "Programming in computer systems",
"faculty": "SPO IKTZI"
}
}
}
],
"per_page": "2",
"total": 75
}
The data presented is irrelevant as it is randomly generated.
Removing data elements in a loop with group equal to null does not solve the problem, since pagination gets lost.

Doctrine Issue - Entities not joining correctly

So I'm having a strange problem with Doctrine that I don't understand and need help with. Essentially, I am running quite a complex query due to the nature of my database and its various joins and for some reason the response when I grab try to grab all records from my database is returning my entities incorrectly.
See my doctrine query below:
$subQuery = $this->_em->createQueryBuilder()
->from(Product::class, 'ex')
->select('ppsi.id')
->join('ex.productSpecificationItems', 'ppsi')
->where('ex.id = p.id');
$subQuery = $subQuery->getDQL();
$subQuery2 = $this->_em->createQueryBuilder()
->from(Product::class, 'ex2')
->select('ppoiv.id')
->join('ex2.productOptionItemValues', 'ppoiv')
->where('ex2.id = p.id');
$subQuery2 = $subQuery2->getDQL();
$subQuery3 = $this->_em->createQueryBuilder()
->from(Product::class, 'ex3')
->select('poie.id')
->join('ex3.productOptionItems', 'poie')
->where('ex3.id = p.id');
$subQuery3 = $subQuery3->getDQL();
$qb = $this->createQueryBuilder('p')
->select('p, pc, psc, i, po, poi, poiv, ps, psi')
->join('p.productCategory', 'pc')
->leftJoin('p.productSubCategory', 'psc')
->leftJoin('p.images', 'i')
->leftJoin('p.productOptions', 'po')
->leftJoin('p.productSpecifications', 'ps')
->leftJoin('ps.productSpecificationItems', 'psi', Join::WITH, 'psi.id IN (' . $subQuery. ')')
->leftJoin('po.productOptionItems', 'poi', Join::WITH, 'poi.id IN (' . $subQuery3. ')')
->leftJoin('poi.productOptionItemValue', 'poiv', Join::WITH, 'poiv.id IN (' . $subQuery2. ')')
->addOrderBy('p.id', 'ASC');
The response of this causes some entities to have the productOptionItemValues either listed under the wrong productOptionItem, just causes blank records to return, or doesn't return them at all. See an example below (as a JSON for clarity):
{
"id": 373,
"name": "test",
"code": "test",
"url": "373-test",
"price": "1.00",
"stock": 1,
"description": "<p>fghfgh mnsdbfksdhfjk sd</p>\n",
"live": false,
"createdAt": "2022-03-17T14:45:35+00:00",
"updatedAt": "2022-03-17T15:12:44+00:00",
"featured": false,
"aggregateReviewScore": null,
"productCategory": {
"id": 2,
"name": "Hex Set Screws",
"url": "hex-set-screws"
},
"productSubCategory": {
"id": 12,
"name": "Nylon",
"url": "nylon"
},
"images": [],
"productOptions": [
{
"id": 1,
"name": "Colour",
"productOptionItems": {
"0": {
"id": 2,
"name": "Black",
"productOptionItemValue": [
{
"id": 1196,
"stock": 1,
"price": "1.00",
"useOwn": false
},
{
"id": 1201,
"stock": 1,
"price": "1.00",
"useOwn": false
},
{
"id": 1198,
"stock": 1,
"price": "1.00",
"useOwn": false
}
]
},
"1": {
"id": 8,
"name": "Yellow",
"productOptionItemValue": [
{
"id": 1197,
"stock": 1,
"price": "1.00",
"useOwn": false
}
]
},
"2": {
"id": 14,
"name": "Light Grey"
},
"3": null,
"4": {
"id": 15,
"name": "Mid Grey"
},
"7": null,
"8": {
"id": 20,
"name": "Light Blue"
},
"11": null,
"12": {
"id": 22,
"name": "Purple"
},
"13": null
}
},
{
"id": 2,
"name": "Pack Size",
"productOptionItems": [
{
"id": 3,
"name": "10",
"productOptionItemValue": [
{
"id": 1180,
"stock": 100,
"price": "10.00",
"useOwn": true
}
]
},
{
"id": 4,
"name": "100",
"productOptionItemValue": [
{
"id": 1181,
"stock": 10,
"price": "1000.00",
"useOwn": true
}
]
}
]
}
],
"productSpecifications": []
}
If I run the same query on a SINGLE product (so the same Doctrine Query as a above just with a p.id = :id WHERE added) it returns absolutely fine. See the response for that below (and the CORRECT response I am looking for):
{
"id": 373,
"name": "test",
"code": "test",
"url": "373-test",
"price": 1,
"stock": 1,
"description": "<p>fghfgh mnsdbfksdhfjk sd</p>\n",
"live": false,
"createdAt": "2022-03-17T14:45:35+00:00",
"updatedAt": "2022-03-17T15:12:44+00:00",
"featured": false,
"aggregateReviewScore": null,
"productCategory": {
"id": 2,
"name": "Hex Set Screws",
"url": "hex-set-screws"
},
"productSubCategory": {
"id": 12,
"name": "Nylon",
"url": "nylon"
},
"images": [],
"productOptions": [
{
"id": 1,
"name": "Colour",
"productOptionItems": [
{
"id": 2,
"name": "Black",
"productOptionItemValue": {
"id": 1196,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 7,
"name": "Red",
"productOptionItemValue": {
"id": 1201,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 8,
"name": "Yellow",
"productOptionItemValue": {
"id": 1197,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 14,
"name": "Light Grey",
"productOptionItemValue": {
"id": 1202,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 15,
"name": "Mid Grey",
"productOptionItemValue": {
"id": 1205,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 20,
"name": "Light Blue",
"productOptionItemValue": {
"id": 1203,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 22,
"name": "Purple",
"productOptionItemValue": {
"id": 1204,
"stock": 1,
"price": 1,
"useOwn": false
}
},
{
"id": 23,
"name": "Natural",
"productOptionItemValue": {
"id": 1198,
"stock": 1,
"price": 1,
"useOwn": false
}
}
]
},
{
"id": 2,
"name": "Pack Size",
"productOptionItems": [
{
"id": 3,
"name": "10",
"productOptionItemValue": {
"id": 1180,
"stock": 100,
"price": 10,
"useOwn": true
}
},
{
"id": 4,
"name": "100",
"productOptionItemValue": {
"id": 1181,
"stock": 10,
"price": 1000,
"useOwn": true
}
}
]
}
],
"productSpecifications": []
}
Any help or ideas would be greatly appreciated!

filtering json data in php laravel

I've a sample json data
"regions": [
{
"id": 1,
"name": "Region 1",
"state_id": 1,
"areas" :[ {
"id": 1,
"name": "area 1",
"region_id": 1},
{
"id": 2,
"name": "area 2",
"region_id": 1}
]
},
{
"id": 2,
"name": "Region 2",
"state_id": 1,
"areas" :[ {
"id": 3,
"name": "area 3",
"region_id": 2},
{
"id": 4,
"name": "area 4",
"region_id": 2}
]
}
]
How can I filter out the data the based on id in the regions? For example, if id is 2, then the response should be like
"regions": [
{
"id": 2,
"name": "Region 2",
"state_id": 1,
"areas" :[ {
"id": 3,
"name": "area 3",
"region_id": 2},
{
"id": 4,
"name": "area 4",
"region_id": 2}
]
}
]
You can json_decode that json string and then use array_filter method to filter regions
$regions = json_decode('{"regions":
[
{
"id": 1,
"name": "Region 1",
"state_id": 1,
"areas" :[ {
"id": 1,
"name": "area 1",
"region_id": 1
},{
"id": 2,
"name": "area 2",
"region_id": 1
}]
},{
"id": 2,
"name": "Region 2",
"state_id": 1,
"areas" :[{
"id": 3,
"name": "area 3",
"region_id": 2
},{
"id": 4,
"name": "area 4",
"region_id": 2
}]
}
]
}', true);
// Filter Region
$region_id = 2;
$filtered_regions = array_filter($regions['regions'], function($r) use ($region_id) {
return $r['id'] == $region_id;
});
// Filter By Area Id
$area_id = 2;
$filtered_areas = array_filter($regions['regions'], function($r) use ($area_id) {
$areas = array_filter($r['areas'], function($area) use ($area_id) {
return $area['id'] == $area_id;
});
return count($areas) > 0;
});
return ['regions' => $filtered_regions];
First apply json_decode on your json data then apply filter . If you want to get an whole object from this response array , then write a function which will accept the id and return that object after filtering.

How to sort based on an array inside of an array in PHP?

Let's consider the following JSON response. It is a list of station objects.
[
{
"id": 43,
"trucks": [
{
"id": 24,
"vehicleType": {
"id": 2,
"vehicleType": "VT",
"createdAt": 1622645476000,
"updatedAt": 1622645476000
},
"sensor": {
"id": 16,
"devId": "tutorial",
"readings": [
{
"id": 36296,
"interiorTemperature": 528.36,
"batteryTemperature": 528.36,
"batteryVoltage": 0,
"createdAt": 1623065279000,
"updatedAt": 1623065279000
}
],
"resolved": false,
"createdAt": 1622645598000,
"updatedAt": 1622650553000
},
"vehicleNumber": 123456,
"truckStatus": true,
"defaultBatteryVoltage": "12",
"batteryTempThreshold": 25,
"interiorTempThresholdMax": 30,
"interiorTempThresholdMin": 5,
"batteryVoltageThreshold": 11.5,
"createdAt": 1622645517000,
"updatedAt": 1622645663000
},
{
"id": 29,
"vehicleType": {
"id": 2,
"vehicleType": "VT",
"createdAt": 1622645476000,
"updatedAt": 1622645476000
},
"sensor": {
"id": 23,
"devId": "value",
"readings": [
{
"id": 36298,
"interiorTemperature": 10,
"batteryTemperature": 10,
"batteryVoltage": 10,
"createdAt": 1623074142000,
"updatedAt": 1623074142000
}
],
"resolved": false,
"createdAt": 1623074089000,
"updatedAt": 1623074089000
},
"vehicleNumber": 313215,
"truckStatus": true,
"defaultBatteryVoltage": "12",
"batteryTempThreshold": 50,
"interiorTempThresholdMax": 50,
"interiorTempThresholdMin": 50,
"batteryVoltageThreshold": 50,
"createdAt": 1623073365000,
"updatedAt": 1623073365000
}
],
"name": "value",
"city": "value",
"address": "value",
"zipCode": "value",
"createdAt": 1622645352000,
"updatedAt": 1622645352000
},
{
"id": 44,
"trucks": [
{
"id": 25,
"vehicleType": {
"id": 3,
"vehicleType": "AG",
"createdAt": 1622647436000,
"updatedAt": 1622647436000
},
"sensor": {
"id": 18,
"devId": "test",
"readings": [
null
],
"resolved": false,
"createdAt": 1622795394000,
"updatedAt": 1622795394000
},
"vehicleNumber": 123457,
"truckStatus": true,
"defaultBatteryVoltage": "24",
"batteryTempThreshold": 80,
"interiorTempThresholdMax": 50,
"interiorTempThresholdMin": -20,
"batteryVoltageThreshold": 11.5,
"createdAt": 1622645584000,
"updatedAt": 1623074846000
}
],
"name": "value",
"city": "value",
"address": "value",
"zipCode": "11112",
"createdAt": 1622645431000,
"updatedAt": 1622645431000
},
{
"id": 46,
"trucks": [
{
"id": 26,
"vehicleType": {
"id": 2,
"vehicleType": "VT",
"createdAt": 1622645476000,
"updatedAt": 1622645476000
},
"sensor": null,
"vehicleNumber": 979787,
"truckStatus": true,
"defaultBatteryVoltage": "12",
"batteryTempThreshold": 123,
"interiorTempThresholdMax": 123,
"interiorTempThresholdMin": 123,
"batteryVoltageThreshold": 123,
"createdAt": 1623064671000,
"updatedAt": 1623064671000
}
],
"name": "value",
"city": "value",
"address": "value",
"zipCode": "11111",
"createdAt": 1622918304000,
"updatedAt": 1622918304000
}
]
All stations have an id, a list of trucks, and some basic info (name, location etc). With PHP, I convert this to an array object. What I would like to achieve is to sort the array. Now I have managed to sort based on name or location. I used the following snipped:
usort($stations, function($a, $b) {
$retval = $a['name'] <=> $b['name'];
return $retval;
});
Now it's all nice but we would like to sort it based on the highest interior temperature read in a station. To make the station with the highest interior temperature be the 0th element in the list and the one with the lowest (or no reading at all) is the nth. I have tried playing around with usort but I had no results. Is it even possible to sort it like that?

Podio api - how to set category field when create item

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
}
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();

Categories