Skip to main content
Solved

Using Clari API


Forum|alt.badge.img

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.

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

View original
Was this topic helpful to you?

6 replies

Kenna
Community Manager
Forum|alt.badge.img+18
  • Community Manager
  • 959 replies
  • 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!


Forum|alt.badge.img
  • Author
  • New Contributor
  • 2 replies
  • 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.  


Forum|alt.badge.img

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


Forum|alt.badge.img
  • Author
  • New Contributor
  • 2 replies
  • July 21, 2024

Thanks Steven! It works!


Forum|alt.badge.img

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
Forum|alt.badge.img+18
  • Community Manager
  • 959 replies
  • 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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings