I am new to power BI and power query, I am trying to get the JSon data from Post rest api. But i always get a 400 error. Where am I going wrong.
let
authkey ="Bearer xxxx",
url = "https://example.com/xxx",
body = "{""objectId"":""settlement_entity"",""queryString"":""?itemrefs=settlementreference,itemdescription&perpage=12&includekeyitems=true&includeforeignkeyitems=true&includetimestamp=true&includeadditionalmeta=true""}",
Source = Json.Document(Web.Contents(url,
[
Headers = [#"Authorization"= authkey,#"Content-Type"="application/json"], Content = Text.ToBinary(body)
]
))
in
Source
Ok I fixed the issue the body was missing square bracket
let
authkey ="Bearer xxxx",
url = "https://example.com/xxx",
body = "[{""objectId"":""settlement_entity"",""queryString"":""?itemrefs=settlementreference,itemdescription&perpage=12&includekeyitems=true&includeforeignkeyitems=true&includetimestamp=true&includeadditionalmeta=true""]}",
Source = Json.Document(Web.Contents(url,
[
Headers = [#"Authorization"= authkey,#"Content-Type"="application/json"], Content = Text.ToBinary(body)
]
))
in
Source
Related
I'm trying to receive data from an API, but it's POST method, so I'm trying to send the data, but it won't
let
body = [COD_INT= "886000", COD_INT_CSO= "0"],
Parsed_JSON = Json.FromValue(body),
Source = Web.Contents("https://apixxxxxxx.yyyyyyyyy.com.br/api/CursosConcluidos",
[
Headers= [#"User-Token" ="673E9CAF-xxxxxxxxxxx-xxx-xx-968"],
Content = Parsed_JSON
]
),
final = Json.Document(Source)
in
final
In Postman it works perfectly
Print from Postman
I tried the same from here but it's the same result
Changing or not the ParsedJSON in Binary gives the same result, 400
Here is my snippet from Python
def sendTemplateMessage():
url = "http://api.gupshup.io/sm/api/v1/template/msg"
payload = "channel=whatsapp&source=%s&destination=%s&src.name=%s&disablePreview=%s" % (SENDER_NUMBER, "1234567890", APP_NAME, False)
obj = '{"id": "4234234-7b42-4e23423424-956c-234234","params": ["my text", "https://some-link-with-image/"]}'
obj = quote(obj)
payload = "%s&template=%s" % (payload, obj)
response = requests.post(url, headers=HEADERS, data=payload)
print(response.text)
This correctly sends the message. But there is no preview image for the link, it just shows plain link with other contents. Anybody come across this and have solution?
I am looking for a way to use a relative path for external JSON files while defining the example request body.
My current definition is like this:
#Operation(requestBody = #RequestBody(description = "Request", content = #Content(schema = #Schema(implementation = Request.class), examples = {
#ExampleObject(
name = "An example request",
value = "{\n" +
"\"token\":\"token\"\n" +
"}",
summary = "Request"
)}
)),summary = "summ", description = "desc")
I want to keep JSON value on an external JSON file.
I know that "externalValue" field can be used instead of "value" to reference an external json file, but it requires a URL. I want to keep it in the project file and use the relative path. I am using Open API v3.
For those who are just looking for external JSON file usage, you can use external JSON file from a URL like this:
#Operation(requestBody = #RequestBody(description = "Request", content = #Content(schema = #Schema(implementation = Request.class), examples = {
#ExampleObject(
name = "An example request",
externalValue = "http://domain/test/example.json",
summary = "Request"
)}
)),summary = "summ", description = "desc")
I'm iterating over a for loop of a list of ingredients (strings) calling a http post request for each one to obtain their nutritional info.
The following works.
data = '{"query": "black olives"}'
r = requests.post(url, headers = headers, data = data)
body = json.loads(r.text)
But this:
for ingredient in ingredients:
data = '{"query": ' + ingredient + '}'
r = requests.post(url, headers = headers, data = data)
body = json.loads(r.text)
gives the error:
{'message': 'Unexpected token r in JSON at position 10'}
How do I fix it?
Edit: It works now.
It is safer to construct JSON from a dict.
Try this:
import json
for ingredient in ingredients:
data = {"query": ingredient}
# Two options : let requests do the json conversion of the dict
r = requests.post(url, headers = headers, json=data)
# or do it yourself
# r = requests.post(url, headers = headers, data=json.dumps(data))
body = json.loads(r.text)
I am trying to call a REST API through LUA. However, I am not able to capture full raw response returned by the API. Below is the code sample:
local http_socket = require("socket.http")
local pretty_print = require("pl.pretty")
local header = {
["x-device-type"] = "M",
["authorization"] = "ashdjkashd",
["x-app-secret"] = "asdasda",
["x-user-id"] = "asdasdasd"
}
r, c, h = http_socket.request {
method = "GET", -- Validation API Method
url = "http://google.com", -- Validation API URL
headers = header
}
print(r .. c)
pretty_print.dump(h)
I'm using lua 5.3, and luarocks version=2.4.1.
In variable c i am getting code, and in h there are a few headers. I need to capture full response returned by the API.
As you may know, luasocket's http.request supports two forms of usage. I'm assuming you need the second form to customize the resty request for that particular API.
In this case to capture the response body you'll need to use the sink field with ltn12.sink module. For example
local ltn12 = require 'ltn12'
-- ...
local res = {}
r, c, h, s = http_socket.request
{
method = "GET", -- Validation API Method
url = "http://google.com", -- Validation API URL
headers = header,
sink = ltn12.sink.table(res)
}
res = table.concat(res)
print(res)
The table.concat is needed since the response could be comprised of multiple chunk sizes(appended to res as it's received).
You can also write it out to file by replacing above with ltn12.sink.file, eg. using ltn12.sink.file(io.stdout) will dump the response to standard output.