# REST API tutorial throwing errors

**URL:** <https://community.dremio.com/t/rest-api-tutorial-throwing-errors/2393>\
**Category:** Uncategorized\
**Created:** [December 6, 2018, 6:29pm UTC](https://community.dremio.com/t/rest-api-tutorial-throwing-errors/2393 "2018-12-06T18:29:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![summersmd](https://avatars.discourse-cdn.com/v4/letter/s/f9ae1b/32.png) [@summersmd](https://community.dremio.com/u/summersmd)\
**Post date:** [December 6, 2018, 6:29pm UTC](https://community.dremio.com/t/rest-api-tutorial-throwing-errors/2393/1 "2018-12-06T18:29:27Z")

</div>

I’m using the following code to try to test retrieval of data from a Dremio dataset. I am able to query the dataset via the Dremio interface, and my Python code (shown below) connects to the API and gets a valid job id, however when I try to retrieve data via a SQL query, I get the following error: **{‘errorMessage’: ‘Something went wrong’, ‘moreInfo’: ‘Can not fetch details for a job that is in [RUNNING] state.’}**

```
import json
import requests

username = 'summersmd'
password = 'abc1234'
headers = {'content-type':'application/json'}
dremioServer = 'http://localhost:9047'

def apiGet(endpoint):
  return json.loads(requests.get('{server}/api/v3/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers).text)

def apiPost(endpoint, body=None):
  text = requests.post('{server}/api/v3/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers, data=json.dumps(body)).text

  # a post may return no data
  if (text):
    return json.loads(text)
  else:
    return None

def apiPut(endpoint, body=None):
  return requests.put('{server}/api/v3/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers, data=json.dumps(body)).text

def apiDelete(endpoint):
  return requests.delete('{server}/api/v3/{endpoint}'.format(server=dremioServer, endpoint=endpoint), headers=headers)

def login(username, password):
  # we login using the old api for now
  loginData = {'userName': username, 'password': password}
  response = requests.post('http://localhost:9047/apiv2/login', headers=headers, data=json.dumps(loginData))
  data = json.loads(response.text)

  # retrieve the login token
  token = data['token']
  return {'content-type':'application/json', 'authorization':'_dremio{authToken}'.format(authToken=token)}

headers = login(username, password)
print (headers)

def querySQL(query):
  queryResponse = apiPost('sql', body={'sql': query})
  jobid = queryResponse['id']
  return jobid

path = ['\"OneSource\"', 'CV_CANDIDATE_PORTFOLIO']
path = '.'.join([str(x) for x in path])
query = "SELECT * FROM {source}".format(source=path)
jobid = querySQL(query)
print (jobid)
results = apiGet('job/{id}/results?offset={offset}&limit={limit}'.format(id=jobid, offset=0, limit=100))

print (results)
```

---

<div class="post-metadata">

**Author:** ![doron](https://sea2.discourse-cdn.com/flex020/user_avatar/community.dremio.com/doron/32/294_2.png) [@doron](https://community.dremio.com/u/doron)\
**Post date:** [December 6, 2018, 7:09pm UTC](https://community.dremio.com/t/rest-api-tutorial-throwing-errors/2393/2 "2018-12-06T19:09:44Z")

</div>

Hi,

The jobs API is asynchronous - when you submit a job, the API returns immediately and doesn’t wait for the job to complete. In your case, the job is in the `RUNNING` state and therefore there is no job results available.

You can use [this endpoint](http://docs.dremio.com/rest-api/jobs/endpoints.html#retrieve-a-jobs-status) to monitor the status of the job. All possible states can be found [here](http://docs.dremio.com/rest-api/jobs/models.html).
