GET request for Detailed Report — 'HTTP 405 Method Not Allowed' Error

Hi all,

I’m new to coding and using APIs. I’m trying to make a GET request for a Detailed Report.

I’m getting {'code': 405, 'message': 'HTTP 405 Method Not Allowed'} as a response but I’m not sure why or how to fix it. I’d be grateful for any help; below is my code and a screenshot of the responses:

code

from django.shortcuts import render
import requests


api_key = "myapikeyisherekaldjfl;kdfjijfae"
workspaceId = "myworkspaceIDishere"

headers = {
    "x-api-key": api_key,
    "content-type": "application/json",
}

payload = {
    "dateRangeStart": "2023-11-15T23:59:59.999Z",
    "dateRangeEnd": "2023-12-07T23:59:59.999Z",
}


full_url = (
    "https://reports.api.clockify.me/v1/workspaces/" + workspaceId + "/reports/detailed"
)


def home(request):
    response2 = requests.get(
        "https://api.clockify.me/api/v1/user", headers=headers
    ).json()

    response3 = requests.get(
        full_url,
        headers=headers,
        params=payload,
    ).json()

    return render(
        request,
        "home.html",
        {"response2": response2, "response3": response3},
    )

screenshot of response for code

Thank you in advance!

Hey Stephanie,

Thank you for getting in touch with us.

For using reports, you need the POST method
Could you please try this and let us know how it goes?

POST method https://reports.api.clockify.me/v1/workspaces/{workspaceId}/reports/detailed

If you continue to encounter issues while doing so, please reach out to support@clockify.me so we can properly address this one.

Cheers,

Thank you, Nikola. Oops :sweat_smile:
I’ve graduated to a new error code of {'code': 501, 'message': 'Please provide detailed filter.'}

Probably another newbie problem: I’m trying to add the detailedFilter (based on the docs), but I’m struggling to understand how to find the options for what can be put into the payload (not what type which is clear, but what actual content should replace the type in the templates. And also what a lot of these terms actually mean - for example, “auditFilter”).

Here’s what I have so far based on guesses and searching the forum, but I’m still getting the {'code': 501, 'message': 'Please provide detailed filter.'}

payload = {
    "dateRangeStart": "2023-01-22T00:00:00.000",
    "dateRangeEnd": "2022-01-22T23:59:59.000",
    "detailedFilter": {
        "auditFilter": {
            "duration": 30,
            "durationShorter": True,
            "withoutProject": True,
            "withoutTask": True,
        },
        "options": {"totals": "CALCULATE"},
        "page": 2,
        "pageSize": 30,
        "sortColumn": "DATE",
    },
}

Is there better explanations or some detailed examples of the API anywhere?

Thank you in advance.

Stephanie

Hey Stephanie,

Thanks for getting back.

Nothing to worry about! :smile: You will receive a message to populate a field that you included in the body, but haven’t specified its value. In this case that would be:

    "auditFilter": {

As you can see, we have an open bracket, but nothing after the comma to specify their values.

You can fully disregard the fields you don’t want to include in the body, and simply delete them. The system will return only the values you left in the body. So, for example, here’s how my sample call for the Detailed reports looks like >>

{
“dateRangeStart”: “2023-10-01T00:00:00.000”,
“dateRangeEnd”: “2023-10-31T23:59:59.000”,
“detailedFilter”: {
“page”: 1,
“pageSize”: 50
},
“rounding”: true,
“clients”: {
“ids”: [“01010101010101”],
“billable”: true }
}

Feel free to play around and try something like this basic call. In case you face any further concerns with our API, please don’t hesitate to reach out to our Support with some screenshots of the body and responses, we’ll gladly look into that further!

Thanks again. I’m still struggling. Trying to use your example this is what I have so far along with a screenshot of the response:

Code

from django.shortcuts import render
import requests


api_key = "myapikeyishere"
workspaceId = "myworkspaceIDishere"

headers = {
    "x-api-key": api_key,
    "content-type": "application/json",
}

payload = {
    "dateRangeStart": "2023-10-01T00:00:00.000",
    "dateRangeEnd": "2023-10-31T23:59:59.000",
    "detailedFilter": {
        "page": 1,
        "pageSize": 50,
    },
    "rounding": True,
    "clients": {
        "ids": ["62cd3953642ffa2999767f70"],
    },
}


def home(request):
    response2 = requests.get(
        "https://api.clockify.me/api/v1/user", headers=headers
    ).json()

    response3 = requests.post(
        "https://reports.api.clockify.me/v1/workspaces/"
        + workspaceId
        + "/reports/detailed",
        headers=headers,
        params=payload,
    ).json()

    response4 = requests.get(
        "https://api.clockify.me/api/v1/workspaces/" + workspaceId + "/clients",
        headers=headers,
    ).json()

    return render(
        request,
        "home.html",
        {"response2": response2, "response3": response3, "response4": response4},
    )

Screenshot

Help appreciated! Am I putting the detailed filter in the wrong place? Is it something else?