Onenote API (REST) - PATCH append - "must include a 'commands'" error when Commands is already supplied (?!) - api

Note: I'm pretty sure nothing's wrong with the PATCH query, I had it working before with 'Content-type':'application/json' and a constructed json file:
[
{
'target':'|TARGET_ID|',
'action':'append',
'content':'|HTML|'
}
]
For the purposes of this, the header supplied (authentication bearer is correct and will be omitted)
'Content-type':'multipart/form-data; Boundary=sectionboundary'
(note: Boundary=sectionboundary is in the same line)
Attempting to pass the following body as a PATCH to
https://www.onenote.com/api/v1.0/pages/|GUID|/content
returns a
"code":"20124","message":"A multi-part PATCH request must include a 'commands' part containing the PATCH action JSON structure." :
--sectionboundary
Content-Disposition: form-data; name="Commands"
Content-Type: application/json
[
{
'target':'|TARGET_ID|',
'action':'append',
'content':'|HTML|'
}
]
--sectionboundary
Content-Disposition: form-data; name="image-part-name"
Content-Type: image/png
|BINARY_IMAGE_DATA|
--sectionboundary--
As you can see, there's a Commands section already. Using smallcaps 'commands' doesn't help, and the correct syntax should be "Commands" as per the OneNote Dev Center documentation.
PS: |TARGET_ID| |HTML| |GUID| and |BINARY_DATA| are replaced with the correct content at runtime. Due to privacy constraints, the fact that you may use a different schema than I do, and how long |BINARY_IMAGE_DATA| actually is, I will not show the actual input unless required to solve the problem.
Would like to know if I missed anything - thanks in advance.
PPS: Yes, I realize i've omitted the img tag inside |HTML| somewhere. It shouldn't have anything to do with code 20124, and if I got it wrong should return another thing entirely.

Based on investigating the request information you shared, I can confirm that the PATCH request referenced as part of the correlation you provided does not match your posted header information.
The correlated PATCH request shows up as a multi-part request with only a single part that has Media Type "TEXT/HTML" and not "Application/JSON". Can you please check and confirm your request content ?
Let us continue to discuss this on email. If you still face issues calling the API, please write to me at machandw#microsoft.com
Regards,
Manoj

Related

postman giving 400 bad request when i use global varibales how to solve this

when i use normal json body postman gives me 201 created response but when i am using global variable postman giving me 400 bad request
Variables still need to be used in proper JSON format therefore you should be putting your strings in quotes:
{
"email": "{{email}}",
"password" : "{{password}}",
"confirmpassword" : "{{confirmpassword}}"
}
See https://learning.postman.com/docs/sending-requests/variables/
Side note: please provide actual "happy path" (when it worked) as well as your errors. Text instead of images is good too to help people try to reproduce your errors without a lot of typing

Mulesoft_ passing client id and Client_secret under HTTP header

I have a requirement where I need to add both client id and client_secret under HTTP headers(under attribute,headers)
I tried to use the below code and unfortunately, it is not working, so please check and guide us to get the expected code.
Transform message create an attribute and applied the below DataWeave code:
output application/java
---
{
headers: {
client_id: '68eee04d10774836b6e5c40189ed3efb',
client_secret: '149541B02E23487EBE517708496a2920'
}
And in the consume connector header part, I have added the below line code.
Attributes.headers
It is difficult to say without seeing exactly what the application is doing but I suspect you are mixing SOAP headers with HTTP headers. HTTP Headers go into the transport headers element.
Example assuming both kind of headers in different variables. Note that you can set each header individually or pass an object which contains them all:
<wsc:consume doc:name="Consume" config-ref="Web_Service_Consumer_Config" operation="GetContent">
<wsc:message>
<wsc:headers><![CDATA[#[vars.soapHeaders]]]></wsc:headers>
</wsc:message>
<wsc:transport-headers>
<wsc:transport-header key="client_id" value="#[vars.httpHeaders.client_id]" />
<wsc:transport-header key="client_secret" value="#[vars.httpHeaders.client_secret]" />
</wsc:transport-headers>
</wsc:consume>

Karate - header name "Content-Length: 70" is automatically added for POST request while calling commonHeader in karate frameworkjs

i m performing one POST request where i dont need "Content-Length" in headers as it is automatically assigned. And i have used "configure charset = null" in the code, still it is passing " Content-Length: 70" in the header.
please let me know how to remove "Content-Length" from header ?
thanks
You can't. I know, you probably want to do a negative-test or something - but there is probably very little value in such a test. If you really want to do this, use a Java library for this particular scenario.
EDIT - or use cURL from Karate: Is possible to execute curl in Karate tests?

Fiddler add binary file data to POST

I'm try to add binary file data directly to the request body of a POST call so I can simulate a file upload. However, I tried setting a 'before request' breakpoint and using 'insert file' but I couldn't seem to get that to work. I also tried to modify CustomRules.js to inject the file but couldn't figure out how to load binary data via JScript. Is there an easy solution here?
I'm sure this is a new feature in the year since this question was answered, but thought I'd add it anyhow:
There's a blue "[Upload file]" link in Composer now on the right side under the URL textbox. This will create a full multipart/form-data request. If you use this, you'll notice in the body you now have something that looks like this:
<#INCLUDE C:\Some\Path\my-image.jpg#>
In my case, I just wanted to POST the binary file directly with no multipart junk, so I just put the <#INCLUDE ... #> magic in the request body, and that sends the binary file as the body.
In order to send multipart/form-data, this receipe will be helped.
In upper panel (Http header), set Content-Type as below. Other values are automatically resolved.
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
And, input Response Body at the below panel as follows.
---------------------------acebdf13572468
Content-Disposition: form-data; name="description"
the_text_is_here
---------------------------acebdf13572468
Content-Disposition: form-data; name="file"; filename="123.jpg"
Content-Type: image/jpg
<#INCLUDE *C:\Users\Me\Pictures\95111c18-e969-440c-81bf-2579f29b3564.jpg*#>
---------------------------acebdf13572468--
The import rules are,
Content-Type should have two more - signs than boundary words in body.
The last of the body should be ended with two - signs.
In Fiddler script: (in Fiddler: Rules... Customize Rules), find the OnBeforeRequest function, and add a line similar to:
if (oSession.uriContains("yourdomain"))
{
oSession.LoadRequestBodyFromFile("c:\\temp\\binarycontent.dat");
}
since version 2.0, the Request Body has an "Upload File..." link that allows you to post/upload binary data.

Why am I not getting the soap header?

Why is this so hard in WCF 4.0
I add a custom header in my client
Authorization: 18732818 gfdsgShoyh3sfayql6jWCRc=
so that my header looks like the following
GET http://HOSTNAME/Public/Xml/SyncReply/TestClearUsername?Id=1 HTTP/1.1
Authorization: 18732818 gfdsgShoyh3sfayql6jWCRc=
Host: HOSTNAME
Connection: Keep-Alive
in my wired up service responder I can access the property Id and get the value 1. I would also like to access the value Authorization, but it always shows as null.
What am I doing wrong?
After much googling I finally found the answer to this so I will post it here so it might be of use to someone else. I am assuming this is an undocumented feature, since it is so well hidden, but someone else might know different.
I found this enumeration System.Web.HttpWorkerRequest.HeaderAuthorization (value=24)
and this method System.Web.HttpWorkerRequest.GetKnownRequestHeader(24)
Just to summarize the reason Authorization was hiding from me was that its a reserved header value. if you add a random word and want to retrieve you can use.
.GetUnknownRequestHeader("YOUR_WORD_HERE").
so in full you need
HttpRequestContext hrc = (HttpRequestContext)this.RequestContext;
RequestAttributes ra = (RequestAttributes)hrc.RequestAttributes;
System.Web.HttpWorkerRequest hwr = ra.HttpWorkerRequest;
string Auth = hwr.GetKnownRequestHeader(System.Web.HttpWorkerRequest.HeaderAuthorization);