# How to run Data Explorer queries with Python

**URL:** https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-python/145803
**Category:** Data & reporting
**Tags:** rest-api
**Created:** [March 27, 2020, 12:19pm UTC](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-python/145803 "2020-03-27T12:19:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Konrad\_Sopala](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/konrad_sopala/32/167014_2.png) [@Konrad\_Sopala](https://meta.discourse.org/u/Konrad_Sopala)
#### Post date: [March 27, 2020, 12:19pm UTC](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-python/145803/1 "2020-03-27T12:19:27Z")

</div>

Hey there!

Regarding this topic: [Run Data Explorer queries with the Discourse API - #27](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-the-discourse-api/120063/27)

I tried to ported the CURL command to Python and from the syntax perspective everything seems ok but I’m getting 404 all the times but when I run. the CURL command I receive 200. Can any of you guys spot what I’m doing wrong? Here’s my Python code:

```plaintext
# Imports

import requests
import json

# Constants

ENDPOINT = 'https://community.myCompanyName.com/admin/plugins/explorer/queries/73/run'
API_KEY = '<the_api_key>'
API_USERNAME = '<my_discourse_username>'

# Core Functions

def send_request(endpoint):

    api_keys = {'Api-Key': API_KEY, 'Api-Username': API_USERNAME}
    headers = {'Content-Type': 'multipart/form-data'}
    request = requests.post(endpoint, api_keys, headers)
    print("STATUS CODE: %s" % request.status_code)

send_request(ENDPOINT)

```

Thanks for help!

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [March 27, 2020, 5:58pm UTC](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-python/145803/2 "2020-03-27T17:58:40Z")

</div>

You will need to put the api credentials in with the headers.

```plaintext
headers = {'Content-Type': 'multipart/form-data', 'Api-Key': API_KEY, 'Api-Username': API_USERNAME}

```

And for the actual request you might need to specify it like this:

```plaintext
requests.post(endpoint, headers=headers)

```

---

<div class="post-metadata">

### Author: ![Konrad\_Sopala](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/konrad_sopala/32/167014_2.png) [@Konrad\_Sopala](https://meta.discourse.org/u/Konrad_Sopala)
#### Post date: [March 30, 2020, 6:40am UTC](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-python/145803/3 "2020-03-30T06:40:08Z")

</div>

Perfectly thanks that worked! Thanks a lot @blake for help!

---

<div class="post-metadata">

### Author: ![blake](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/blake/32/157322_2.png) [@blake](https://meta.discourse.org/u/blake)
#### Post date: [March 30, 2020, 12:39pm UTC](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-python/145803/4 "2020-03-30T12:39:53Z")

</div>

A post was merged into an existing topic: [Creating a topic via the API using Node.js](https://meta.discourse.org/t/creating-a-topic-via-the-api-using-node-js/117160/20)

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 29, 2020, 12:39pm UTC](https://meta.discourse.org/t/how-to-run-data-explorer-queries-with-python/145803/5 "2020-04-29T12:39:56Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
