Skip to content

Sample Code for requests to Smartlists endpoint #23

Description

@evanashbrook

I am attempting to send a request to '/rest/asset/v1/smartLists.json' to get all SmartLists. I am authenticating with Marketo fine and recieving an access token that I include in the headers of each of my subsequent requests . Additionally, the documentation states that if our instance did not have this capability, the response code would be >1000 (It's some number I can't remember off the top of my head). However, I did not get this response code, but rather 403, which is a forbidden request. I am hoping to figure out why I am not getting a valid response, but there is no documentation for troubleshooting this endpoint.

Code:
`

def get_smartlist_ids(config, access_token):

    identity_url = config['identity_url']

    headers = {
        'Authentication': 'Bearer {}'.format(access_token),
    }

    url = '{}/rest/asset/v1/smartLists.json'.format(identity_url)

    response = requests.get(url, headers=headers)

    return response


 mkto_config = {
    'client_id': [redacted],
    'client_secret': [redacted],
    'identity_url': [redacted]
  }
  
  access_token_response = get_mkto_access_token(mkto_config)
  access_token = access_token_response.json()['access_token']
  
  print(access_token_response.status_code)
  print(access_token_response.json())
  
  smartlist_ids = get_smartlist_ids(mkto_config, access_token)
  
  print(smartlist_ids.status_code)
  print(smartlist_ids.headers)
  print(smartlist_ids.request.headers)
  print(smartlist_ids.text)
  print(smartlist_ids.url)

`

And the Output:

`

  200
  {'access_token': '[redacted]', 'token_type': 'bearer', 'expires_in': 337, 'scope': 'marketoapi@bizjournals.com'}
  403
  {'Server': 'nginx', 'Date': 'Thu, 29 Sep 2022 17:54:55 GMT', 'Content-Type': 'text/html', 'Content-Length': '162', 'Connection': 'keep-alive'}
  {'User-Agent': 'python-requests/2.25.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Authentication': 'Bearer [redacted]'}
  <html>
  <head><title>403 Forbidden</title></head>
  <body bgcolor="white">
  <center><h1>403 Forbidden</h1></center>
  <hr><center>nginx</center>
  </body>
  </html>
  
  [redacted]/rest/asset/v1/smartLists.json

`

Let me know if I can clarify or provide more information in order to help. Thanks in advance for the help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions