Apoc.text.urlencode seems to be adding extra % characters to URL for Wikidata

I am trying to follow the tutorial here: Neo4j: Enriching an existing graph by querying the Wikidata SPARQL API · Mark Needham (markhneedham.com)

When I get to the apoc.load.jsonParams section (right after Table 2), I get the following error:

Failed to invoke procedure apoc.load.jsonParams: Caused by: java.lang.RuntimeException: Can't read url or key https://query.wikidata.org/sparql?query=SELECT+*%250AWHERE+%257B+%253Fperson+wdt%253AP106+wd%253AQ10833314+%253B%250A++++++++++++++++rdfs%253Alabel+%2522Nick+Kyrgios%2522%2540en+%253B%250A++++++++++++++++wdt%253AP569+%253FdateOfBirth+%253B%250A++++++++++++++++wdt%253AP27+%255B+rdfs%253Alabel+%253FcountryName+%255D+.%250A+++++++filter%2528lang%2528%253FcountryName%2529+%253D+%2522en%2522%2529%250A%257D as json: Server returned HTTP response code: 400 for URL: https://query.wikidata.org/sparql?query=SELECT+*%250AWHERE+%257B+%253Fperson+wdt%253AP106+wd%253AQ10833314+%253B%250A++++++++++++++++rdfs%253Alabel+%2522Nick+Kyrgios%2522%2540en+%253B%250A++++++++++++++++wdt%253AP569+%253FdateOfBirth+%253B%250A++++++++++++++++wdt%253AP27+%255B+rdfs%253Alabel+%253FcountryName+%255D+.%250A+++++++filter%2528lang%2528%253FcountryName%2529+%253D+%2522en%2522%2529%250A%257D

It seems like extra "25"s (% sign used in the HTML encoding) are getting inserted into the URL when it gets sent to Wikidata. I have tried cleaning the string using the replace() function but that doesn't work.

When I manually remove the "25"s and paste the URL in my browser, it is able to communicate with Wikidata just fine. Does anyone know how I can encode the URL without the extra "25"s

  • Neo4j 4.2.7, Windows 10, Chrome

Can you please create a GH issue for APOC for this, thank you!

Hmm works for me

WITH "SELECT *
WHERE { ?person wdt:P106 wd:Q10833314 ;
                rdfs:label \"" + "Nick Kyrgios" + "\"@en ;
                wdt:P569 ?dateOfBirth ;
                wdt:P27 [ rdfs:label ?countryName ] .
       filter(lang(?countryName) = \"en\")
}" AS sparql
CALL apoc.load.jsonParams(
  "https://query.wikidata.org/sparql?query=" + apoc.text.urlencode(sparql),
  { Accept: "application/sparql-results+json"},
  null
)
YIELD value
RETURN value