function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
forceDeveloperforceDeveloper 

Retrieve Rest API value

Hi All,

I am using this code .
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
                    System.debug('results::'+results);
                    System.debug('results.get()::'+results.get('items'));


 I want to get the "customer_id" in apex
{items=({addresses=({city=ewing, country_id=US, customer_id=18,  firstname=nini, id=19, lastname=nini, postcode=08628, region={region=New Jersey, region_code=NJ, region_id=41}, ...}),
 , custom_attributes=({attribute_code=phone_number, value=1231231234}, {attribute_code=account_number, value=147439}), default_billing=19,  email=ninin@example.com, firstname=nini, group_id=0, ...}), 
search_criteria={filter_groups=({filters=({condition_type=eq, field=email, value=ninin@example.com})})}, 
total_count=1}

When I using   System.debug('results.get()::'+results.get('items'));  . I am getting the below value 

({addresses=({city=ewing, country_id=US, customer_id=18, default_billing=true, default_shipping=true, firstname=nini, id=19, lastname=nini, postcode=08628, region={region=New Jersey, region_code=NJ, region_id=41}, ...}), created_at=2019-01-02 15:58:29, created_in=Default Store View, custom_attributes=({attribute_code=phone_number, value=1231231234}, {attribute_code=account_number, value=147439}), default_billing=19, default_shipping=19, disable_auto_group_change=0, email=ninin@example.com, firstname=nini, group_id=0, ...})

results.get('items').get("addresses") -- is not working

Please help me to get the "customer_id" value.
Thanks,
 
Shaik Naga janiShaik Naga jani
Hi forceDeveloper,
Please try below code, I wrote this code based on your JSON response
Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(res.getBody());
                    System.debug('results::'+results);
                    System.debug('results.get()::'+results.get('items'));
map<String, Object> addressData = (Map<String, Object>)results.get('items');
map<String, Object> addressInfo = (Map<String, Object>)addressData.get('addresses');
Integer customerId = (Integer)addressInfo.get('customer_id');
System.debug('Customer Id ====> '+customerId);
if it helps for you please mark the best answer.
Thanks
Shaik