Skip to main content
New Contributor
July 17, 2024
Solved

Using Clari API

  • July 17, 2024
  • 0 replies
  • 2168 views

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.
    Best answer by Steve Overton

    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

    Kenna
    Community Manager
    Community Manager
    July 17, 2024

    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
    July 18, 2024

    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
    July 19, 2024

    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
    July 21, 2024

    Thanks Steven! It works!

    New Member
    February 4, 2025

    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
    Community Manager
    Community Manager
    February 4, 2025

    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