Forum Discussion
how to pass json object in URL via a GET parameter ?
Hello,
I have the following code that works fine :
= Json.Document(Web.Contents("https://myurl/documents", [Headers=[Authorization="Bearer "&GetToken(),#"profile"="full-access", #"enduser"="enduser"]]))
But when I add the parameter "search" that takes some json like this :
= Json.Document(Web.Contents("https://myutl/documents?search={"_type":{"$eq":"Document"}}", [Headers=[Authorization="Bearer "&GetToken(),#"profile"="full-access", #"enduser"="enduser"]]))
It works fine with Postman but Power Query tells me there is a syntax error under "_type".
I have the same issue when I add this :
= Json.Document(Web.Contents("https://myurl/documents?search={
"$and": [
{"_type": {"$eq":"TOTO"}},
{"$or": [
{"g_service":{"$eq":"FR_Moto"}},
{"g_service":{"$eq":"FR_Moto2"}},
{"g_service":{"$eq":"FR_Moto3"}}
]}
]
}", [Headers=[Authorization="Bearer "&GetToken(),#"profile"="full-access", #"enduser"="enduser"]]))
The syntax error is under the first dollar sign before the and
Is the issue that we must concatenate strings in json differently in PowerQuery ?
- Anonymous4 years ago
Actually I found out that I need to escape the double quotes by adding another double quote before each ones within the json part
2 Replies
- AlexisOlson
Super User
You need to use "&" to concatenate strings.
For example, if _type = "TypeA", then you could write
"https://myutl/documents?search={TypeA}"as
"https://myutl/documents?search={" & _type & "}"If you remove the ampersands, then you'll get an error.
- AnonymousNot applicable
Actually I found out that I need to escape the double quotes by adding another double quote before each ones within the json part