0

I'm trying to get data from the SimilarWeb API, using python requests, like this:

import requests
MY_API_KEY = 'XXXXXXXXXXXXXXXXXX'

API_URL = "https://api.similarweb.com/v1/website/{site}/" \
          "total-traffic-and-engagement/visits?api_key={api_key}" \
          "&start_date={start_date}" \
          "&end_date={end_date}" \
          "&main_domain_only=false" \
          "&granularity={granularity}".format(
    site='cnn.com',
    api_key=MY_API_KEY,
    start_date="2017-09",
    end_date="2017-10",
    granularity="monthly"
)

response = requests.get(API_URL)
print response.json()

As far as possible, this follows the similarweb example on their own site here. Only the dates are different.

However, I get a json error stating that my 'Dates not in range' within the json:

{
    u'meta': {
        u'status': u'Error', 
        u'error_code': 101, 
        u'error_message': u'Dates not in range', <--- error msg
        u'request': {
            u'domain': u'cnn.com', 
            u'end_date': u'2017-10-31', 
            u'format': None, 
            u'country': u'world', 
            u'main_domain_only': False, 
            u'limit': None, 
            u'granularity': u'Monthly', 
            u'start_date': u'2017-09-01'
        }
    }
}

I have tried many different dates (including the ones in the example - start_date=2016-01&end_date=2016-03), and I have tried different date formats, but I always get this error. I have tried dates further in the past, and I have tried dates further apart.

If I leave the dates out, I am returned valid data, so I believe the rest of the request must be well formed? I will continue to try different options, but would be really grateful if anyone has had experience with this, as it is driving me a little crazy now!

I am using python 2.7 due to project constraints, with requests version 2.18.4, which I believe to be the most recent available to pip.

gdoron
  • 147,333
  • 58
  • 291
  • 367
srowland
  • 1,625
  • 1
  • 12
  • 19

1 Answers1

5

You're requesting 2017-09 to 2017-10, Today's Nov 1st so the 2017-10 snapshot is not up yet. contact SimilarWeb support for updates.

SimilarWeb
  • 66
  • 1
  • Thank you, that's really good to know - is there a formula to when the snapshots are available, or do I just need to keep retrying periodically until they are available? – srowland Nov 01 '17 at 14:04
  • You can always GET the 'describe' endpoint for that endpoint, i.e. https://api.similarweb.com/v1/website/ask.com/total-traffic-and-engagement/describe – SimilarWeb Nov 01 '17 at 14:15
  • Awesome - I didn't realise that, that is really helpful, thank you, this has been really helpful! – srowland Nov 01 '17 at 14:18
  • btw - is there a documentation link I have missed? I only see the pages linked above, and they don't detail the describe stuff. – srowland Nov 01 '17 at 14:31
  • Thank you for your input. The error message has been enhanced to reflect the supported date range and acknowledge the 'describe' endpoint. – SimilarWeb Nov 05 '17 at 15:35