I’m calling an API and I get the following response:
"items": [
{
"packagingType": "PCS",
"description": "[REDACTED]",
"productCode": "MATT",
"freightClass": "300",
"insuranceValue": 428.70999999971326,
"primaryReferenceNumber": null,
"poNumber": "[REDACTED]",
"skuNumber": "[REDACTED]",
"pluNumber": null,
"actualQuantity": 1,
"actualWeight": 125,
"actualWeightUnitOfMeasure": "Pounds",
"actualPallets": 1,
"actualVolume": null,
"actualVolumeUnitOfMeasure": "Cubic Feet",
"actualPackagingLength": null,
"actualPackagingHeight": null,
"actualPackagingWidth": null,
"actualPackagingUnitOfMeasure": "Inches",
"referenceNumbers": [
{
"type": "CustomerItemIdentifier1",
"value": "[REDACTED]"
},
{
"type": "OrderItemId",
"value": "123456789"
},
{
"type": "SHID",
"value": "[REDACTED]"
}
],
"associatedStop": {
"pickSequenceNumber": null,
"dropSequenceNumber": null
}
}
]
But sometimes the API also sends an answer like this:
"items": [
{
"packagingType": "PCS",
"description": "[REDACTED]",
"productCode": "MISC",
"freightClass": "300",
"insuranceValue": 2500,
"primaryReferenceNumber": null,
"poNumber": "[REDACTED]",
"skuNumber": "[REDACTED]",
"pluNumber": null,
"actualQuantity": 1,
"actualWeight": 132,
"actualWeightUnitOfMeasure": "Pounds",
"actualPallets": null,
"actualVolume": null,
"actualVolumeUnitOfMeasure": "Cubic Feet",
"actualPackagingLength": null,
"actualPackagingHeight": null,
"actualPackagingWidth": null,
"actualPackagingUnitOfMeasure": "Inches",
"referenceNumbers": [
{
"type": "OrderItemId",
"value": "987654321"
}
],
"associatedStop": {
"pickSequenceNumber": null,
"dropSequenceNumber": null
}
}
Now, what I’m trying to achieve is to append the "value" under the "referenceNumbers" when the "type" is equal to "OrderItemId".
Can anyone please point me out on the right direction to do it?
UPDATE: This is my current block of code:
for object in parsed['results']:
if object['event']['eventType'] in event_list:
for item in object['event']['items']:
orders_event_name.append(object['event']['eventType'])
orders_customer_order.append(object['billToReferenceNumber'])
orders_reference_number.append(item['referenceNumbers']['value'])
orders_event_id.append(None)
orders_item_id.append(item['skuNumber'])
orders_datetime_started.append(object['eventTime'])
orders_seconds.append(None)
orders_load_number.append(object['event']['loadNumber'])
2
Answers
Output:
An answer with your code: