Skip to main content
New Contributor
Jul 17, 2024 8:38 AM UTC
Solved

Using Clari API

I am trying to use Clari API, but I am getting errors from the client side.  

I have already generated a token. 

Can you please provide a short example of using the API? just a simple request.

Thanks,

Shahar.

    This topic has been closed for replies.
    Salesloft Employee
    Jul 19, 2024 4:22 PM UTC

    Hi @ShaharP ,

     

    Here is a simple Python code block, you will note that this includes all of the types to export and that the forecast ID is not set, as this will be unique to your environment, as will the be the API Key:

    import requests

    url = "https://api.clari.com/v4/export/forecast/<forecast_name>"

    payload = "{\n \"timePeriod\": \"2020_Q3\",\n \"typesToExport\": [\n \"forecast\",\n \"quota\",\n \"forecast_updated\",\n \"adjustment\",\n \"crm_total\",\n \"crm_closed,\n ],\n \"currency\": \"USD\",\n \"schedule\": \"NONE\",\n \"includeHistorical\": false,\n \"exportFormat\": \"CSV\"\n}"
    headers = {
    'Content-Type': 'text/plain',
    'apikey': '<api_key>'
    }

    exportresponse = requests.request("POST", url, headers=headers, data=payload)

    print(exportresponse.text)

    This code generates the request, you can pull a list of jobs running or completed with the following code block:

    import requests

    url = "https://api.clari.com/v4/export/jobs"

    payload = {}
    headers = {
    'apikey': '<api_Key>'
    }

    jobresponse = requests.request("GET", url, headers=headers, data=payload)

    print(jobresponse.text)

    Finally, to pull the results for your export job, you can take the ID from the list, or from the ID returned by the initial code block:

    import requests

    url = "https://api.clari.com/v4/export/jobs/<job_id>/results"

    payload = {}
    headers = {
    'apikey': '<api_key>'
    }

    response = requests.request("GET", url, headers=headers, data=payload)

    print(response.text)

    Steve Overton - Sr Technical Support Engineer - Clari

    6 replies

    Kenna
    Salesloft Employee
    Salesloft Employee
    Jul 17, 2024 9:50 PM UTC

    Hi, @ShaharP. This’ll likely depend on which data warehouse/BI tool/analytics tool you are using. I would recommend opening a case with our support team with the specific error messages you’re experiencing to get some help!

    Kenna Valdez, Manager, Customer Community, Clari
    ShaharPAuthor
    New Contributor
    Jul 18, 2024 5:33 AM UTC

    I'm just looking for short code examples in any language (preferably Python). Due to the fact that I could not find any examples in the documentation or on the internet, I believe that other people will find it useful as well.  

    Salesloft Employee
    Jul 19, 2024 4:22 PM UTC

    Hi @ShaharP ,

     

    Here is a simple Python code block, you will note that this includes all of the types to export and that the forecast ID is not set, as this will be unique to your environment, as will the be the API Key:

    import requests

    url = "https://api.clari.com/v4/export/forecast/<forecast_name>"

    payload = "{\n \"timePeriod\": \"2020_Q3\",\n \"typesToExport\": [\n \"forecast\",\n \"quota\",\n \"forecast_updated\",\n \"adjustment\",\n \"crm_total\",\n \"crm_closed,\n ],\n \"currency\": \"USD\",\n \"schedule\": \"NONE\",\n \"includeHistorical\": false,\n \"exportFormat\": \"CSV\"\n}"
    headers = {
    'Content-Type': 'text/plain',
    'apikey': '<api_key>'
    }

    exportresponse = requests.request("POST", url, headers=headers, data=payload)

    print(exportresponse.text)

    This code generates the request, you can pull a list of jobs running or completed with the following code block:

    import requests

    url = "https://api.clari.com/v4/export/jobs"

    payload = {}
    headers = {
    'apikey': '<api_Key>'
    }

    jobresponse = requests.request("GET", url, headers=headers, data=payload)

    print(jobresponse.text)

    Finally, to pull the results for your export job, you can take the ID from the list, or from the ID returned by the initial code block:

    import requests

    url = "https://api.clari.com/v4/export/jobs/<job_id>/results"

    payload = {}
    headers = {
    'apikey': '<api_key>'
    }

    response = requests.request("GET", url, headers=headers, data=payload)

    print(response.text)

    Steve Overton - Sr Technical Support Engineer - Clari

    ShaharPAuthor
    New Contributor
    Jul 21, 2024 8:15 AM UTC

    Thanks Steven! It works!

    New Member
    Feb 4, 2025 3:26 PM UTC

    Can anyone advise why this payload causes a malformed API response? I am following the docs and receive errors every time, but don’t receive any errors when I remove the payload. Thanks 

    payload = {
    'timePeriod' : '2026_Q1',
    'typesToExport' : ['forecast'],
    'currency' : 'USD'
    }

    headers = {
    'apikey': key,
    'Content-Type': 'application/json'
    }

    response = requests.post(url, headers=headers, data=payload)

     

    Kenna
    Salesloft Employee
    Salesloft Employee
    Feb 4, 2025 11:05 PM UTC

    Hi, ​@Michael Duffner — It could be that the apikey section doesn't pull the variable you have set. However, to be certain, my best suggestion would be to open a case with our Support team. With your org details, the support team can test to confirm.

    Kenna Valdez, Manager, Customer Community, Clari