7:16 pm

November 27, 2018

hi,
I'm trying to send some data to powerbi dataset via RESTful API. Server expects it in this format (JSON starts with square brackets)
[
{
"field1" :"AAAAA555555",
"field2" :"AAAAA555555",
"field3" :"AAAAA555555"
}
]
I've tested it with postman and it's working fine,
here is my code in MATLAB
options = weboptions('MediaType','application/json','RequestMethod','post');
data = '[{"field1":"AAAAA555555","field2":"AAAAA555555","field3":"AAAAA555555"}]';
powerbiURL = 'https://api.powerbi.com/beta/%%%/datasets/%%%/rows?key=%%%%';
response = webwrite(powerbiURL, data, options)
Here is the error:
Error using readContentFromWebService (line 46)
The error "Error copying data." occurred while communicating with URL
Error in webwrite (line 139)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
if I use response = webwrite(powerbiURL, jsondecode(data), options), I get this error which means that it's missing wrapping [ ] brackets
Error using readContentFromWebService (line 46)
The server returned the status 400 with message "Bad Request" in response to the request to URL
What's the workaround? How can I debug it and see what's the request header that is being sent?
Thanks.
9:48 am


Moderators
March 7, 2017

I wasn't able to find the error for you, but POSTMAN has an echo service that you might be able to use to see your post data.
https://docs.postman-echo.com/
My reading of the MediaType doc says that it will automatically use json encode for data, so the second thing you tried is possibly redundant.
Perhaps escaping the quotes might help? (just guessing here)
Most Users Ever Online: 166
Currently Online:
25 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 272
Vinod: 240
piajola: 95
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 8665
Moderators: 1
Admins: 2
Forum Stats:
Groups: 3
Forums: 14
Topics: 1600
Posts: 5760
Newest Members:
estebanmateo93, mikewrite, onlinebusiness, winzy99, Zark_zeugan, StefanWiModerators: cstapels: 460
Administrators: Hans: 405, lee: 457