HTTP POST request API

80 views (last 30 days)
Orkhan Alikhanov
Orkhan Alikhanov on 6 Aug 2021
Commented: Orkhan Alikhanov on 13 Aug 2021
I am trying to send a POST request to Notion with json body. The request contains a header with three fields.
I get an response HTTP/1.1 400 Bad Request. What am I doing wrong? Everything works through Postman. I also tried to shape the request body as a matlab structure.
My code:
data = '{"parent":{"database_id":"<my_id>"},"properties":{"title":{"title":[{"text":{"content":"hello"}}]}}}';
uri=matlab.net.URI('https://api.notion.com/v1/pages');
method = matlab.net.http.RequestMethod.POST;
header = matlab.net.http.HeaderField('Authorization', 'Bearer <secret_token>',...
'Content-Type', 'application/json',...
'Notion-Version','2021-05-13');
body = matlab.net.http.MessageBody(data);
request = matlab.net.http.RequestMessage(method,header,body);
[response,completedrequest,history] = send(request,uri)
  4 Comments
Reeshabh Ranjan
Reeshabh Ranjan on 13 Aug 2021
@Orkhan Alikhanov its working now, right?

Sign in to comment.

Answers (0)

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!