Hi,
I'm trying to replicate the whole Marketo instance in a spreadsheet, where I can analyze/audit the all campaigns.
I;m trying to achieve this with REST API and Python
I would like to know the list of,
Right now, I'm looking from programs in a active folder and the programs in the Archived folders. Using the REST api "Browse Folder" method.
Below is the Python code I used,
from marketorestpython.client import MarketoClient
munchkin_id =
client_id =
client_secret =
mc = MarketoClient(munchkin_id, client_id, client_secret)lead = mc.execute(method='browse_folders', root=3, maxDepth=9, maxReturn=200, workSpace='Default')
print(lead)
For some reason, I get the output which is not JSON but something like you see below,
[{'name': 'Marketing Activities', 'description': 'Root node for the Marketing Activities app area', 'createdAt': '2013-06-02T00:21:24Z+0000', 'updatedAt': '2013-06-02T00:21:24Z+0000', 'url': None, 'folderId': {'id': 3, 'type': 'Folder'}, 'folderType': 'Zone', 'parent': None, 'path': '/Marketing Activities', 'isArchive': False, 'isSystem': True, 'accessZoneId': 1, 'workspace': 'Default', 'id': 3}
And with the maxDepth=9, the result is incomplete, not all folders data comes in the output. It's stops randomly.
Anyone knows how to convert the output to JSON and get the complete data with maxDepth=9?
Thanks in advance.
VS
Solved! Go to Solution.
Hi Viki, I have seen that it sometimes skips a particular node, is that what you are seeing also? My workaround is to run it again, specifying the ID of that folder as the root.
The output you are getting is a Python object, since you are using the Python library. Use json.dumps() to get JSON.
Please highlight your code using the Advanced Editor's syntax highlighter so it's readable. (There may not be a highlighter for Python but even choosing None as the language makes it monospace and preserves layout.)
When you say "which is not JSON" are you referring to the lack of double quotes? Are you actually dumping the object from your client app, or dumping the raw HTTP response? The raw response should be JSON, I've never seen any other response type returned in error.
I did the similar thing a few days back and it just worked fine for me. I did it in google app script. Can you share more details on how you are doing it meaning which end point URL you are using?
I used "/rest/asset/v1/folders.json". I used 20 as the max depth to be on safer side and it worked just fine for me. The response which I got was like below instead and it was purely a jSON:
{
"success": true,
"warnings": [],
"errors": [],
"requestId": "9bd8#14e1f49047c",
"result": [
{
"name": "Marketing Activities",
"description": "Root node for the Marketing Activities app area",
"createdAt": "2010-03-27T18:27:45Z+0000",
"updatedAt": "2010-03-27T18:27:45Z+0000",
"url": null,
"folderId": {
"id": 14,
"type": "Folder"
},
"folderType": "Zone",
"parent": null,
"path": "/Marketing Activities",
"isArchive": false,
"isSystem": true,
"accessZoneId": 1,
"workspace": "Default",
"id": 14
}]
And can you highlight that as JSON please?
Sorry to be a downer here, but when visually impaired people try to read code, it's nearly impossible unless monospaced, preformatted, and highlighted.
I'm not sure how Google Apps Script works.
I do get pure JSON when I make the API call from the browser, irrespective of endpoint. And it would take ages from me get all the data I wanted, as it is only maxReturn=200 and I have change the offset every time till it reaches 54000.
Hence, I did it with Python, and the output was not JSON as a result of missing command. Which I figured just after I posted my question here
Thanks
VS
Hi Viki, I have seen that it sometimes skips a particular node, is that what you are seeing also? My workaround is to run it again, specifying the ID of that folder as the root.
The output you are getting is a Python object, since you are using the Python library. Use json.dumps() to get JSON.
Thanks Jep!
Exactly what I figured!
I wasn't using the json.dumps() to get JSON and output was Python Object without the double quotes.
In my case, with the print command, there was only half the data in the output. I figured it is just too much for python to print in the console. I got the complete data in JSON file.
Here is what worked for me, if anyone wants to use it,
from marketorestpython.client import MarketoClient
import json
import array
munchkin_id = ""
client_id = ""
client_secret = ""
mc = MarketoClient(munchkin_id, client_id, client_secret)
lead = mc.execute(method='browse_folders', root=3, maxDepth=9, maxReturn=200, workSpace='Default')
with open('output.json', 'w') as outfile:
json.dump(lead, outfile)