POST request using Power Query - rest

I'm trying to collect data from the major electronic components distributors using their API with Power Query.
I was able to do it easily with ARROW and FARNELL as they use a GET request but now I'm trying to do the same thing with MOUSER but it's a POST request.
Here's the code I've written so far but it's not working :
edit
Can someone please help me and tell me what's wrong ?
The API documentation is here:
https://api.mouser.com/api/docs/ui/index#/SearchApi/SearchApi_SearchByPartNumber
Thanks for your help !
edit
My first attempt was really awful, I've made a few changes but it's still not working:
let
url = "https://api.mouser.com/api/v1.0/search/partnumber?apiKey=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
body = Json.FromValue({[SearchByPartRequest = ""], [mouserPartNumber = "LL4148"], [partSearchOptions = "3"]}),
Source = Json.Document(Web.Contents(url, [Headers=[#"Content-
Type"="application/json"], Content = body]))
in
Source
edit
I get the following error:
error message (from Power Query or the API ?)

The answer you're looking for is in the Web.Contents() function.
You can read more information here, here, and here.

Related

PowerQuery missing supports for windows authentification and REST API POST body

I've discovered the hard way that PowerQuery (Powerbi & excel) Web.Contents function doesn't support a body payload when using Windows authentification.
with similar query
let
body = "{""json"" : ""payload""}",
Data= Web.Contents("http://xxxx/api/Query",[Content=Text.ToBinary(body),Headers=[#"Content-Type"="application/json"]]),
DataRecord = Json.Document(Data)
...
pretty stocked this lonely support and I suspect I'm missing an important aspect. Is there a recommanded way ? My google search were pretty un-successful.
Should I generate some kind of token with a first GET and then make a POST with body + token in anonymous ?
Do you have to use Windows authentication? How about using something like this with Anonymous authentication:
let
AuthKey = "mytoken",
url="http://xxxx/api/Query",
body = "{""json"" : ""payload""}",
Source = Json.Document(Web.Contents(url,[
Headers = [#"Authorization"=AuthKey ,
#"Content-Type"="application/json"],
Content = Text.ToBinary(body)
]
))
in
Source
Will this solve your problem?

uber_rides.errors.UberIllegalState: Bad Request. Missing state parameter

I'm trying to just retrieve all my receipts amount from my Uber account and dump into excel.
I installed uber_riders and trying to do that. I have no intention of creating a website or any other business purpose. My mere purpose is just fetch trips bills and dump to excel sheet.
So in my code.
from uber_rides.auth import AuthorizationCodeGrant
auth_flow = AuthorizationCodeGrant(
"xxx",
"partner.trips",
"xxx",
"http://localhost/redirect_uri"
)
print auth_flow
auth_url = auth_flow.get_authorization_url()
session = auth_flow.get_session("http://localhost/redirect_uri")
So what should i fill in the redirect_uri ? I believe i don't need it. Can someone help me on what to do with this. I currently get uber_rides.errors.UberIllegalState: Bad Request. Missing state parameter.
I was also facing the same problem, after spending some time thinking, I found this solution:
Execute till this statement as it is:
auth_url = auth_flow.get_authorization_url()
After executing this instruction copy the auth_url and paste it into a browser.
If everything is fine, you would get to your redirected link with two parameters, 'code' and 'state', now copy this complete url along with the parameters, and use it for the get_session()
session = auth_flow.get_session(<new_url_here>)

Facebook InsightsAPI calls limited to 25 entries

I'm pretty new to programming and I'm currently trying to use the InsightsAPI of Facebook in order to extract our performance data. The problem is that the response of the API call is limited to 25 entries.
I use the following code for the call:
String access_token = "xxx";
String ad_account_id = "yyy";
setApp_secret("zzz");
APIContext context = new APIContext(access_token).enableDebug(false);
APINodeList<AdsInsights> response = new AdAccount(ad_account_id, context).getInsights()
.setLevel(AdsInsights.EnumLevel.VALUE_CAMPAIGN)
.setBreakdowns(Arrays.asList(AdsInsights.EnumBreakdowns.VALUE_COUNTRY))
.setTimeRange("{\"since\":\"2017-09-01\",\"until\":\"2017-09-30\"}")
.requestField("account_id")
.requestField("campaign_id")
.requestField("impressions")
.requestField("clicks")
.execute();
How can I extend the limit of the response? I found some information about how to do this via curl but there were no hints on how to do this with java. Would be great if anyone of you could help me!
All the best,
Paul
All the responses of Graph API are paginated which means you will get at most 'x' number of results where 'x' is 25 by default at the moment.
You can specify a higher value using limit param but it is not recommended as it is likely to cause a timeout.
You should look into using pagination instead: https://developers.facebook.com/docs/graph-api/using-graph-api/#paging

unable to run rest api service in loadrunner?

i'm facing issue while running rest api service in loadrunner(VUGEN),in soap ui it is working fine.
My Data contains around 10 fields but while request it is breaking one parameter into two then i'm facing internal server error.
Please help and unable to continue in new line in case i want to write it in another line
Code is :
Action()
{
web_custom_request("Calculate",
"URL=http://sdfsdfsdfgsdfgsdfgsdfgsdfgsd/sdfgsdf/sdfgsd",
"Method=POST",
"Resource=0",
"EncType=application/json",
"Mode=HTTP",
"Body={\"program\":\"L002\",\"Number\":null,\"serviceNumber\":\"09000\",\"customerStateName\":\"{state}\",\"storeCode\":\"{store}\",\"Amount\":\"{amount}\",\"paymentDetails\":[{\"type\":\"{types}\",\"amount\":{amount}\"}]}",LAST);
return 0;
}
Unable to write it in two lines of code ,in case i'm trying to write then it is giving syntax error like , is missing or " is missing.Unable to write please any one help.
Response coming as:
{"program":"L002","Number":null,"serviceNumber":"09000","customer
StateName":"MAHARASHTRA","storeCode":"1111","invoiceAmount":"50","paymentDetails":[{"type"
:"CASH","amount":50"}]}
Line is breaking i.e customerStateName into customer,StateName because of this i'm getting Bad Request in Response,Please help.
Since LoadRunner 12.53, you have a new and easier way for making REST API calls, using the web_rest() API. See blog post about it.

Got an error in the IBM Bluemix Weather Insights API used. Kindly help me out

I am referencing the documentation page here:
https://developer.ibm.com/bluemix/2015/10/23/ibm-insights-weather-available-in-bluemix/
But I'm getting the following error :
{"metadata":{"version":"1","transaction_id":"1:677162605","status_code":404},"success":
false,"errors":[{"error":{"code":"AGW-0114","message":"Failed to parse apiname"}}]}
My Constructed URL is :
https://****:*****#twcservice.mybluemix.net/api/weather/v2/forecast/&format=JSON&geocode=11.9310,%2079.7852&language=en-US&units=e
Kindly help me with this issue .
The constructed url needs to be like this:
https://twcservice.mybluemix.net/api/weather/v2/forecast/hourly/24hour?format=JSON&geocode=11.9310%2C79.7852&language=en-US&units=e
The differences are:
call the REST API /forecast/hourly/24hour rather than just /forecast
Add the ? at the end of the API so you pass the parameters
Add the %2C in the geocode to represent the ,
See swagger doc here