0

I'm trying to use the Hasura API to get the contents of my database. The appropriate endpoint is v1alpha1/pg_dump.

I've tried doing the following in Python:

import requests
api_url = 'http://localhost:9695/v1alpha1/pg_dump'
header = {'Content-Type': 'application/json',
          'x-hasura-admin-secret': 'MY_SECRET',
          'X-Hasura-Role': 'admin'}
r = requests.post(url=api_url, headers=header)

If I do requests.get, I get information back (html code, although nothing particularly useful). However, if I do requests.post (which is required by Hasura: https://hasura.io/docs/1.0/graphql/core/api-reference/pgdump.html), I get a 404 error. I don't understand why. It's not an authentication error, but a page not found error.

Have I built my url incorrectly? Is there something I'm missing? The port is correct (and if I change it in the code, it gives me a different error telling me the port is invalid/closed). I'm not sure what else to change.

Elliptica
  • 3,928
  • 3
  • 37
  • 68
  • 1
    You aren't posting any data, are you? – Abraham Labkovsky Dec 09 '20 at 01:02
  • I tried adding a `data` and/or a `body` field but it didn't make a difference. When I've dealt with REST apis in the past, when something like data is missing, it gives a different error. I've never gotten a "page not found" error for POST due to a missing body. – Elliptica Dec 15 '20 at 08:23

1 Answers1

0

So, I have tried in my own Digital Ocean 1 click deployment environment. I have not secured it so I am not providing any headers. It works fine as follows:

import requests
import json

r = requests.post('http://address_of_hasura/v1alpha1/pg_dump',
  data = json.dumps({
  'opts' : ['-O', '-x', '--schema-only', '--schema', 'public'],
  'clean_output': True
}) )
print r.text

If you have used the HASURA_GRAPHQL_ENABLED_APIS env variable and not included pgdump, that could be a reason it would be disabled.

Abraham Labkovsky
  • 1,771
  • 6
  • 12
  • Hm I tried your code replacing your url with mine and adding my headers, but it still prints `404 page not found` – Elliptica Jan 13 '21 at 22:54