Resource Managment API - Reports

When connecting to the report rows endpoint, I am receiving an error when using the timeframe as shown in the API documentation.

"time_frame":{  "from": "2022-01-01",

  "to":"2022-12-31"}


Error message received:

{'message': 'to is not a valid time_frame'}



The API works without error when using one of the canned strings such as:

  • this_week
  • this_month
  • this_quarter
  • this_year
  • last_week
  • last_month
  • last_quarter
  • last_year
  • next_30
  • next_60
  • next_90
  • last_30
  • last_60
  • last_90
  • last_and_next_90


I'm using Python and the request package here is the basic code:


response = requests.post('https://api.rm.smartsheet.com/api/v1/reports/rows',

                            headers={

                               

                                "Content-Type": "application/json",

                                "auth":token,

                               

                            }, params={

                                "view":'time_fees_hours',  

                                "time_frame":{

                                "from": "2022-01-01",

                                "to":"2022-12-31"}


                            })


print(response.json())


Any help is greatly appreciated.


Cheers!

Answers

  • Hi @Dataman

    Can you test removing "time_frame": from this request (but keeping the dates in)?

    In my testing, "time_frame" was only needed if I was specifying one of the canned strings you have mentioned above, but when identifying specific dates it was not needed.

    If this works for you, I'll put in a request to have the API Documentation updated as I can see that it puts "time_frame": before the From and To when identifying specific dates.

    Cheers,

    Genevieve

    Join us at Smartsheet ENGAGE 2024 🎉
    October 8 - 10, Seattle, WA | Register now

  • Dataman
    Dataman ✭✭

    Hi @Genevieve P.

    Thanks for your response. I've removed the time_frame tag as you suggested. So the request just looks like:


    The API response has the set the default option to "time_frame": "this_week" regardless if I put this tag in or not. Additionally, the actual range in the dates section does not update to my custom range.


    Thanks,


    Dataman

  • Hi @Dataman

    I have to admit I'm not sure if what you're seeing is expected or not; please submit your findings to our RM Support team through this form, here. They'll be able to work with you directly in a private channel and identify if this is a bug and needs to be fixed, or expected and the documentation should be updated.

    Thank you!

    Genevieve

    Join us at Smartsheet ENGAGE 2024 🎉
    October 8 - 10, Seattle, WA | Register now

  • NNPPC
    NNPPC ✭✭

    @Genevieve P.

    I also seem to be running into a similar issue where the parameters provided in the body of the request are ignored and it is defaulting them. Could you please advise if there were any updates on this?


  • Tamer Moustafa
    Tamer Moustafa ✭✭✭✭

    Hi @NNPPC , You need to pass the group_by Parameter as a string' - (Put quotes for the array)

    {'view': 'time_fees_hours',

    'group_by': '["project_id", "user_id"]' }

  • Tamer Moustafa
    Tamer Moustafa ✭✭✭✭

    Hello, @Dataman , @NNPPC , @Genevieve P.

    Did you manage to solve the time frame tag ? I have the same issue, whatever I pass it returns the default value "this week", I need to pass date range.

    any advise ?

  • Coin Graham
    edited 04/23/24

    I didn't see an answer here so I'll post working python code:

    custom_timeframe = {
      "from": "2024-04-24",
      "to": "2024-04-30"
    }
    
    report_parameters = {
        "view": "time_fees_hours",
        "time_frame": custom_timeframe,
        "group_by": ["project_id"],
        "today": "{}".format(datetime.today().strftime('%Y-%m-%d')),
    }
    
    [snip]
    

    You can troubleshoot these payloads by inspecting the page on the website, running the report you want, then looking at the network tab. Here's the payload from the browser.

    {
     "view": "time_fees_hours",
     "time_frame": {
      "from": "2024-04-24",
      "to": "2024-04-30"
     },
     "group_by": [
      "project_id"
     ],
     "today": "2024-04-23"
    }