I have some JSON data from the HubSpot CRM API which, after doing some pagination using Python Code essentially looks like this:
[
{
"dealId": 18039629,
"portalId": 62515,
"isDeleted": false
},
{
"dealId": 18040854,
"portalId": 62515,
"isDeleted": false
}
]
... and now what I'd like to do is:
1) Read one "set" of JSON at a time (meaning dealId, portalId, isDeleted)
2) If isDeleted==false
then grab the dealId
and portalId
and store in variables
3) Use the variables from #2 above to build a URL string that can be used to go back to the HubSpot API and get information on each individual deal (this API endpoint is https://api.hubapi.com/deals/v1/deal/23487870?hapikey=demo (where 23487870
is the dealId
from the above JSON)
4) Combine that individual deal-level info into another set of JSON. Specifically I want to grab /properties/dealname/value
and properties/dealstage/value
from JSON that looks like this:
{
"portalId": 62515,
"dealId": 23487870,
"isDeleted": false,
"properties": {
"dealname": {
"value": "AutomationTestUser-national",
"timestamp": 1457692022120
},
"dealstage": {
"value": "appointmentscheduled",
"timestamp": 1457692022120
}
},
"imports": []
}
5) And then output the final result in JSON something like this:
{
"deals":
[
{
"portalId": 62515,
"dealId": 23487870,
"isDeleted": false,
"properties": {
"dealname": {
"value": "AutomationTestUser-national",
"timestamp": 1457692022120
},
"dealstage": {
"value": "appointmentscheduled",
"timestamp": 1457692022120
}
},
"imports": []
},
{
"portalId": 62515,
"dealId": 23487871,
"isDeleted": false,
"properties": {
"dealname": {
"value": "AutomationTestUser-regional",
"timestamp": 1457692022120
},
"dealstage": {
"value": "appointmentscheduled",
"timestamp": 1457692022120
}
},
"imports": []
}
]
}
... all in Python.
Any help?