Problem with POST request to rdf/neo4j/cypher

@jesus.barrasa
On Neo4j v4.2.3
n10s v.4.2.0.1
I am using the following python code to submit GET and POST requests to the rdf endpoint of my database:

import requests
import os
import json

rdf_host = "http://localhost:11006/rdf"
get_pstfx = "/neo4j/describe/13"
post_pstfx = "/neo4j/cypher"
credentials=(os.environ.get("NEO4J_USER"), os.environ.get("NEO4J_PASSWORD"))

get_url = rdf_host + get_pstfx
get_response = requests.get(get_url, auth=credentials).text
print(f"get_response: {get_response}")

post_url = rdf_host + post_pstfx
post_data = {
    "cypher": "MATCH (x) RETURN x",
    "cypherParams": {},
    "format": "Turtle"
}
post_response = requests.post(post_url, auth=credentials, data=post_data)
print(f"post_response: {post_response}")

post_response2 = requests.post(post_url, auth=credentials, json=json.dumps(post_data))
print(f"post_response2: {post_response2}")

I get the following results:

get_response: @prefix n4sch: <neo4j://graph.schema#> .
@prefix n4ind: <neo4j://graph.individuals#> .

<neo4j://graph.schema#Car#toyota#petrol> a n4sch:Car;
  n4sch:fuel "petrol";
  n4sch:model "toyota" .

post_response: <Response [500]>
post_response2: <Response [500]>

so GET requests work fine, however neither of the POST requests worked (I tried with passing python object into data= and passing json serialization into json=)
They fail with 500 Internal Server Error, which makes me think the problem with with the contents of data I submit in the POST request...

Interesting fact that when I submit

:POST /rdf/neo4j/cypher {"cypher": "MATCH (x) RETURN x", "format": "Turtle"}

in MS Edge browser, the query works:


when I submit the query in Neo4j Desktop Browser, it does not:

Could you please help me with that?
What I am trying to achieve is the real Turtle serialization of a custom cypher query result. As far as I understood there is no such n10s.* procedure to do that (n10s.rdf.export.cypher returns a table of triples)

Thank you!

Hi @paltusplintus,

You were nearly there :) Pasing the python dictionary into the json param does the job. No need to do json serialization. This is the fragment I've tested:

post_url = rdf_host + post_pstfx
post_data = {
    "cypher": "MATCH (x) RETURN x limit 3",
    "cypherParams": {},
    "format": "Turtle"
}
post_response = requests.post(post_url, auth=credentials, json=post_data)
print(f"post_response: {post_response.content}")

The n10s.export.* (cypher and spo) procedures are useful when you want to decouple the HTTP endpoint from the DB. In that case the a client will communicate with the DB+n10s using the python driver, and take care of serialising the triples-as-records.

You may find this thread useful.

Finally, on the behavior of the browsers I really cannot explain. For the HTTP requests, I'd suggest (that's what I normally do) to test using curl or some rest client like postman or rested.
I see no issues on chrome at my end but let me know if the problem persists and you think it's worth me trying to reproduce it. I'd need more details like versions of db+n10s+browser... etc.

Hope this helps.

Cheers,

JB.

1 Like

Hi JB,

I am trying to convert Neo4J property graph data model into RDF JSON-LD format. Any suggestions?

Regards,
-Vijay

Hi @vijaykrishna.adigopu , you got your answer right there. If you take the example by @paltusplintus and replace the value of "format" parameter with "JSON-LD" instead of "Turtle" you get your request results serialised as JSON-LD.

Hope that helps. Let us know how it goes :)

JB

Hi JB,

I am attempting to install neosemantics but received the following error.


Can you please help me to install. Thanks in advance

Regards,
-Vijay

I have installed Neosemantics and executed the following query and getting below error


:POST /rdf/neo4j/cypher
{"cypher": "MATCH MATCH (x) RETURN x LIMIT 1", "format": "JSON-LD"}

Hello All

[ 6:06 PM ]

Need a small help on Cypher queries

[ 6:06 PM ]

I am trying to export Neo4J Graph model into RDF-Json-LD

[ 6:07 PM ]

Looking for a Cypher query help

[ 6:07 PM ]

Getting following error when I execute following Cypher query

[ 6:07 PM ]

:POST /rdf/neo4j/cypher {"cypher": "MATCH MATCH (x) RETURN x LIMIT 1", "format": "JSON-LD"}

[ 6:08 PM ]

Could not fetch URL: "404 Not Found". This could be due to the remote server policy. See your web browsers error console for more information.