How to get Folder Archival status of the default workspace using python? | Community
Skip to main content
New Participant
June 17, 2019
Solved

How to get Folder Archival status of the default workspace using python?

  • June 17, 2019
  • 4 replies
  • 3740 views

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, 

  • Active/Inactive Programs
  • Active/Inactive Smart Campaigns
  • Active/Archived Folders
  • Program/Folder Token Values

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jep_Castelein2

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.  

4 replies

New Participant
June 26, 2019

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)

‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Viki Sparks
Jep_Castelein2
Jep_Castelein2Accepted solution
New Participant
June 19, 2019

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.  

Amit_Jain
Community Manager
June 17, 2019

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
}]
SanfordWhiteman
New Participant
June 17, 2019

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.

SanfordWhiteman
New Participant
June 17, 2019

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.