webwrite sending POST JSON isn't working | MATLAB IoT Analytics | Forum

The ThingSpeak community site has been upgraded to a new site. This site is currently in read-only mode. You can ask questions or post and read discussions on the new site.

Please consider registering

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —

— Match —

— Forum Options —

Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
webwrite sending POST JSON isn't working
No permission to create posts
November 27, 2018
7:16 pm
New Member
Forum Posts: 1
Member Since:
November 27, 2018
sp_UserOfflineSmall Offline


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?


March 12, 2019
9:48 am

Forum Posts: 885
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

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.
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)

Forum Timezone: America/New_York

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, StefanWi

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457