OneNote REST API - The multi-part payload was malformed - rest

I am working on an integration with OneNote using the REST API.
I'm trying to create a note but I'm always receiving 400 response code, with the following message: "The multi-part payload was malformed."
URL:
https://www.onenote.com/api/v1.0/pages
Headers:
Content-Type: multipart/form-data; boundary=NewPart
Authorization: Bearer myToken
--NewPart
Content-Type: text/html
Content-Disposition: form-data; name="Presentation"
<!DOCTYPE html>
<html>
<head>
<title>One Note test</title>
<meta name="created" content="2014-04-13T10:36:28+01:00"/>
</head>
<body>
<p>Hello OneNote World</p>
</body>
</html>
--NewPart--
If I try the same request in the apigee tool (https://apigee.com/onenote/embed/console/onenote), it's working perfectly.
I have initially tried to not use multi-part, but all the notes sent without multi-part were missing the note body on the OneNote site. Here is my post on this other issue:
OneNote body is not sent when using non-multipart REST

Make sure the presentation part lines end in CRLF. We've noticed that when using some tools like Fiddler, when you try to reissue and edit a previous request, it removes the CRLF endings from the lines.

Related

Facebook Instant Articles HTML POST Error

I've hit a blocker with POST'ing of HTML content to the https://graph.facebook.com api. I'm able to successfully POST to the endpoint and I receive a status ID as a response. When I then use a GET on the endpoint to check the status, the error messages tell me my content is malformed. I'm able to manually publish the exact same HTML content on my channel in Instant Articles and I get no warnings about the formatting of the HTML. I've also tried using the sample article HTML provided by Facebook and that returns error messages as well. Any advice is appreciated. Here are samples of my requests:
POST /{my_page_id}/instant_articles?access_token={my_access_token}& html_source=<!DOCTYPE html><html lang="en" prefix="op: http://media.facebook.com/op HTTP/1.1
Host: graph.facebook.com
cache-control: no-cache
Postman-Token: {postman_token}
<!---Facebook Sample Article Content--->
<!doctype html>
<html lang="en" prefix="op: http://media.facebook.com/op#">
<head>
<meta charset="utf-8">
<!--Canonical URL of the article from site -->
<link rel="canonical" href="{my_Facebook_approved_domain/canonical_url}">
<link rel="stylesheet" title="{my_stylesheet}" href="#">
<!--Article Title-->
<title>{my_article_title}</title>
<meta property="fb:article_style" content="{my_stylesheet}">
</head>
<body>
<article>
<header>
<!-- The header image shown inside your article -->
<figure>
<!-- First Figure from the article -->
<img src="{my_image_url}">
</figure>
<!-- Article Title -->
<h1>{my_article_title}</h1>
<!--Article Teaser-->
<h2>{my_article_subtitle}</h2>
<!-- The authors of the article -->
<address>{list_of_authors}</address>
<!--The published and last modified time stamps-->
<time class="op-published" dateTime="2019-01-10T16:00">January 10 2019, 04:00 PM</time>
</header>
<p>{my_content}</p>
<p> Read the Full Story at {my_site}</p><br>
<footer>
<!-- Copyright details for your article -->
<small>© 2019 {my_site}. All Rights Reserved.</small>
</footer>
</article>
</body>
</html>
After submitting the POST request, I get a response that looks like this:
{
"id": "2005563182874064"
}
I then GET the article status endpoint by calling:
GET /{page_id}?access_token={my_access_token}& fields=errors,html_source,instant_article,status HTTP/1.1
Host: graph.facebook.com
cache-control: no-cache
Postman-Token: {postman_token}
...and the response I get from that endpoint is as follows:
{
"errors": [
{
"level": "ERROR",
"message": "AttValue: \" expected"
},
{
"level": "ERROR",
"message": "Couldn't find end of Start Tag html"
},
{
"level": "ERROR",
"message": "Missing Article's Canonical URL: There is no URL specified for this article. A canonical URL needs to be claimed and placed within the HTML to generate an Instant Article. Refer to URLs under Publishing Articles in the Instant Articles documentation for more information on claiming and inserting a canonical URL."
}
],
"html_source": "<!DOCTYPE html><html lang=\"en\" prefix=\"op: http://media.facebook.com/op",
"status": "FAILED",
"id": "2005563182874064"
}
The canonical URL is certainly present in my HTML and I've tripled checked that it's listed in the Configuration/Tools/Connect your site area of my Facebook page. Again, I'm able to manually upload the same HTML and preview it using the Pages App on a mobile device. It's only failing when I try to push the content via the API.
I'm testing all of my calls with POSTMAN and will then convert this code to Python3. Again, thanks for your help.
You always want to place payload data in the body of the request for POSTs and as a query string for GET. Anytime an API calls for data that looks extreme for a URL (can't be longer than 2083 characters), that's a key indicator that this is probably not a GET.

401 Unauthrorized response while creating a Rest API instance?

I'm trying to send a POST request on http://xyz:8002/LATEST/rest-apis using Firefox's rest client. I have added two headers Content-Type: application/xml and Authorization:Basic which I selected using the dropdown UI. The body of the request is -
<rest-api xmlns="http://marklogic.com/rest-api">
<name>Status Dashboard</name>
<database>r75-xyz-v11</database>
<port>8020</port>
</rest-api>
In response I'm getting a 401 Unauthoried.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>401 Unauthorized</title>
<meta name="robots" content="noindex,nofollow"/>
</head>
<body>
<h1>401 Unauthorized</h1>
</body>
</html>
I have Admin rights and I gave the same credential in the UI box that came after selecting authentication basic.
Is port 8002 configured for BASIC or DIGEST (the default) authentication?
By the way, I don't think the name of the appserver can contain a space.

Multipart email working everywhere besides on Hotmail

I have a multipart/alternative email that works perfectly on Gmail, Yahoo, and any others I've tried... besides Hotmail (and anything Microsoft I presume.)
The email just appears as raw text on Hotmail.
No matter the amount of times I slam my head against the wall and shout swearwords towards Microsoft which has become a daily activity, I cannot figure out why it doesn't work. Can you?
Here is the email if you want to try it yourself:
Headers:
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_18243133_1346573420.1408991447668"
Body:
------=_Part_18243133_1346573420.1408991447668
Content-Type: text/plain; charset=UTF-8
Hello world.
------=_Part_18243133_1346573420.1408991447668
Content-Type: text/html; charset=UTF-8
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p style="margin-top:50px;font-size:9px;">Hello world</p>
</body></html>
------=_Part_18243133_1346573420.1408991447668--
Here is the full code if you want to test it on your server, either use phpmail or wp_mail() that I'm using.
Update: Here is a source of received message to hotmail.
Probably it is copy-paste to pastbin bug, but your eml contains a space in delimiter line. See here:
--====f230673f9d7c359a81ffebccb88e5d61==
Content-Type: multipart=...<CR><LN>
<SPACE><CR><LN>
^^^^^^^
--====1fdbf23c3658d752511a8dbe74788e30==
If it is not a copy-paste bug than hotmail just can not recognize end of mime entity header.
What you have looks look to be compliant with RFC2046, so it should work with all MUA's (including Hotmail). But having said that, the way this message is structured is somewhat unusual, and it could be that Hotmail just isn't capable of handing such a message properly, even though it is within spec as far as RFC is concerned.
The more common way of structuring a message containing both a plain text body and an HTML body is to specify multipart/mixed in the headers, then create a multipart/alternative section which encompasses both the plain text body part and the HTML body part, using 'subboundaries' (for lack of a better term) to separate the two body parts. See below:
Message Headers
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="====f230673f9d7c359a81ffebccb88e5d61=="
Message Body
--====f230673f9d7c359a81ffebccb88e5d61==
Content-Type: multipart/alternative;
boundary="====1fdbf23c3658d752511a8dbe74788e30=="
--====1fdbf23c3658d752511a8dbe74788e30==
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hello world.
--====1fdbf23c3658d752511a8dbe74788e30==
Content-Type: text/html; charset="us-ascii"
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p style="margin-top:50px;font-size:9px;">Hello world</p>
</body></html>
--====1fdbf23c3658d752511a8dbe74788e30==--
--====f230673f9d7c359a81ffebccb88e5d61==--

OneNote body is not sent when using non-multipart REST

I'm having some issues when I try to create a note using OneNote REST API.
This happens in my application and also when I try to use for testing purpose the apigee tool: https://apigee.com/onenote/embed/console/onenote
After some tests, i've tested the example available on OneNote documentation:
http://msdn.microsoft.com/en-us/library/office/dn575438(v=office.15).aspx#sectionSection3
On apigee, I have the following parameters:
Method: POST
Header: Content-Type: text/html and the corresponding authorization token.
Request Body:
<!DOCTYPE html>
<html>
<head>
<title>One Simple Note</title>
<meta name="created" content="2013-06-11T12:45:00.000-8:00"/>
</head>
<body>
<p>This is a simple non-multi-part HTML page.</p>
</body>
</html>
The note is sent successfully and I receive 201.
When I check my OneNote page, the note is created, but the body of the note is empty.
What am I doing wrong?
Turns out we had a bug in our system that caused messages under 16kb to be ignored. We just fixed it, so you shouldn't have any problems now!

Drupal 6 incorrect mail messages when using mimemail

I have a problem with the mimemail module on drupal 6.
I'm developing a site on a virtual Unix server and the SMTP server is Micorsoft Exchange (on another server of course) and I'm using mimemail and SMTP modules to send emails.
When I configure the SMTP module by itself, everything is correct and I receive the test message in the correct format.
If I enable mimemail, set the "Use mime mail for all messages" and then I configure the SMTP, the message arrives but it is not correctly encoded.
I hope that someone can give me an help.
I spent a lot of time searching the web for a solution but I was not able to find an answer.
Here is the test message I receive:
This is a multi-part message in MIME format.
--ca2a0ce37a649a90e1efc6d650f2387c
Content-Type: multipart/mixed; boundary="44b02f56426ca5bf19322ab80ca53d99"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
--44b02f56426ca5bf19322ab80ca53d99
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
If you receive this message it means your site is capable of sending e-mail.
--44b02f56426ca5bf19322ab80ca53d99
Content-Type: text/html; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
#charset "UTF-8";
body{background:#FFF;}
*{font-family:Arial,Helvetica,sans-serif;font-size:12px;color:#006;}
-->
</style>
</head>
<body id="mimemail-body" class="mail-smtp-smtp-test">
<div id="center">
<div id="main">
<p>If you receive this message it means your site is capable of sending e-mail.</p>
</div>
</div>
</body>
</html>
--44b02f56426ca5bf19322ab80ca53d99--
--ca2a0ce37a649a90e1efc6d650f2387c--