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

Avatar

Please consider registering
Guest

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
Avatar
studioab
New Member
Members
Forum Posts: 1
Member Since:
November 27, 2018
sp_UserOfflineSmall Offline

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.

March 12, 2019
9:48 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 610
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.
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)

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
31 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:

adeeeban, theweddingties, Vasant Gosai, pavithra, shivaniprakash, Akeyan

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457