Uploading a small text file to OneDrive API / MS Graph - postman

What's the right content schema/format or protocol to use to upload a small text file to OneDrive? I'm authenticating correctly, etc., but the docs don't seem to work...
__
I'm following the documentation, exactly - and for sanity check - using Postman.
Specifically, this example from the docs:
PUT /me/drive/root:/FolderA/FileB.txt:/content
Content-Type: text/plain
The contents of the file goes here.
Error: "Entity only allows writes with a JSON Content-Type header.",
--
So I tried putting the body in a json and changing the content-type to json. I'm actually not sure what the right json schema is...
Error: "Property file in payload has a value that does not match schema."
--
I tried fiddling a bit with PUT /me/drive/root:/FolderA/tester.txt:/content
{
"name": "tester.txt",
"file": { }
}
But got Error: The name in the provided oneDrive.item does not match the name in the URL

It turned out that the : needs to be at the end of the file path...
Previously, I had tried using /me/drive/root:/FolderA:/FileB.txt:/content instead of /me/drive/root:/FolderA/FileB.txt:/content

Related

why I am getting this output in djangorestframework-jwt

hello I have implemented JWT in my test project using this package "djangorestframework-jwt"
I have generated the token by giving my "username" and "password"
but the problem is that I am getting this output bypassing my token with the endpoint
I am using postman to test API,Django=2.2.12, python 3.7.6
I am not getting my data from the database
{"eno":["This field is required."],"ename":["This field is required."],"esal":["This field is required."],"eaddr":["This field is required."]}
Your question is not correct, but I try to explain you what happend. So,
You try send POST request to your /api/ route and you got error because you dont send any required data. Go to Body tab and click on 'raw' radio button and than change 'Text' to JSON and insert correct JSON with data that you want to send to your server, it will be looks like:
{
"eno": "your_eno",
"ename": "your_ename"
.....
}
You should read about it if you dont know.

How to post a message with an image using Postman

I am trying send an image from POSTMAN. I am able to send a message but image is not getting posted.
https://slack.com/api/chat.postMessage
Used POST type headers i am passing token, channel and i have an Image URL but not sure how to send that. Can anyone please help me on this.
There are two alternative approaches on how to send your message to the API endpoint chat.postMessage:
Body as form-urlencoded
Here is how to include an image in a message send as x-www-form-urlencoded:
The image has to be send as part of an attachment by setting the property called image_url.
The attachments are set with the attachments key in the API call, which requires you define your attachments as array of attachment object in JSON.
In addition to the image_url your attachment needs to contain a fallback property, which is used to display a text to the user in case the image can not be displayed.
Your attachments object then looks like this in JSON:
{
"fallback": "this did not work",
"image_url": "https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"
}
Now you have to put that into an array (by adding [] around it) and this is what you get as value for your attachments key:
[{"fallback":"did not work","image_url":"https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"}]
In addition you need to add the keys token, channel, text key to your message. Voila.
Body as JSON
An alternative and probably easier approach is to send your data as JSON instead of x-www-form-urlencoded to the API.
This requires you to send the token in the Auth header and switch to JSON for the body.
To do that in Postman put your token as "Bearer Token" under "Authorization".
In "Body" switch to "raw" and select "JSON".
Then you can define the whole message as follows:
{
"channel": "test",
"text": "Hi there!",
"attachments":
[
{
"fallback": "this did not work",
"image_url": "https://secure.gravatar.com/avatar/d6ada88a40de8504c6b6068db88266ad.jpg?s=512&d=https%3A%2F%2Fa.slack-edge.com%2F27b6e%2Fimg%2Favatars%2Fsmiley_blobs%2Fava_0016-512.png"
}
]
}
Of course you can do the same in your code. Since your are working in JavaScript using JSON would be the natural approach.
Note that not all API methods support sending the body in JSON. Check out this documentation for more info.

API endpoint to save multipart-file by POST method through Postman

I am trying to mock the request to upload a zip file through 'POST' method using Wiremock. But I could not find the required property for that. Following is my mocked request which needs to be sent.
How can I save this file to the _file directory through POST request?
"request":
{
"url": "/order/uploadFile",
"method": "POST",
"headers": {
"token": {
"equalTo": "0000000"
},
"Content-Type":{
"equalTo": "multipart/form-data"
}
},
"bodyPatterns": [{
"equalToJson": "{\"sampleFile\":\"Sample_file.zip\"}"}]
} ....```
Here is the postman request. [![request-postman][1]][1]
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/CQaSj.png
In short: you can't save anything to the __files directory using the out-of-the-box standalone WireMock from withing a mapping rule. This functionality requires a custom extension that needs to do the saving for you.
That said, it is possible, according to this Stack Overflow answer to store a file in __files using a PUT on /__admin/files/[your desired filename]. This will then create a new file under the __files. It appears to be undocumented and as such may not feature in future versions. Sub-folders seem to go unsupported when I tried it.

Postman: ordering of fields in form-data request

I have a server set up to which I can successfully send the following request:
curl localhost:8081/graphql \
-F operations='{ "query": "mutation ($file: Upload!) { uploadFile(file: $file) { id } }", "variables": { "file": null } }'
-F map='{ "0": ["variables.file"] }'
-F 0=#a.txt
However, if I paste that into Postman, or try to build the request manually, I get an error on the server-side stating
Custom error: Misordered multipart fields; files should follow “map” (https://github.com/jaydenseric/graphql-multipart-request-spec).
But in Postman, I have defined the fields in that order:
Does Postman do anything on its own to re-order the fields? Is there anything I can do to control the order?
Update: Filed a bug with Postman here: https://github.com/postmanlabs/postman-app-support/issues/4461
This way worked for me,instead of giving file name as "0" I gave "nfile" and order I maintained same operations,map and nfile
Postman seems to order fields alphabetically so 0 would become the first field. I renamed my own file fields as "nfile1" etc.
But I found this question because I was able to read only the first file. And I'm not sure if it caused by the naming I'm using. But that way you can at least test with one file on Postman.
You can also use Altair GraphQL Client to test out your file upload implementation as explained here.

how can I fix conflicting query string params for S3 uploads?

I'm attempting to upload raw image data to S3 in the context of a react-native app.
I have the raw data correct and for the most part I think my code inside react native is working correctly to capture image data.
On my rails server, I'm using the amazon ruby gem to build the details of the url and associated authentication data required to post data to the bucket in question which I'm then rendering into react-native just like a regular react web front end.
# inside the rails server controller
s3_data = S3_BUCKET.presigned_post(key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read', url: 'https://jd-foo.s3-us-west-2.amazonaws.com')
render json: {s3Data: {fields: s3_data.fields, url: s3_data.url}}
At the moment I attempt to post to S3, I'm using ES6 fetch like the below to build my http request.
saveImage(data) {
var url = data.url
var fields = data.fields
var headers = {'Content-Type': 'multipart/form-data'}
var body = `x-amz-algorithm=${encodeURIComponent(fields['x-amz-algorithm'])}&` +
`x-amz-credential=${encodeURIComponent(fields['x-amz-credential'])}&` +
`x-amz-date=${encodeURIComponent(fields['x-amz-date'])}&` +
`x-amz-signature=${encodeURIComponent(fields['x-amz-signature'])}&` +
`acl=${encodeURIComponent(fields['acl'])}&` +
`key=${encodeURIComponent(fields['key'])}&` +
`policy=${encodeURIComponent(fields['policy'])}&` +
`success_action_status=${encodeURIComponent(fields['success_action_status'])}&` +
`file=${encodeURIComponent('12foo')}`
console.log(body);
return fetch(url, {method: 'POST', body: body, headers: headers})
.then((res) => {console.log('s3 inside api res', res['_bodyText']) ; res.json()} );
}
the logging of the body looks like
x-amz-algorithm=AWS4-HMAC-SHA256&x-amz-credential=AKIAJJ22D4PSUNBB5RAQ%2F20151027%2Fus-west-1%2Fs3%2Faws4_request&x-amz-date=20151027T223159Z&x-amz-signature=42b09d7ae134f803b10ef72d220fe74a630a3f826c7f1f625448277d0a6d93c7&acl=public-read&key=uploads%2F46be8ca3-6d3a-4bb7-a658-f2c8e058bc28%2F%24%7Bfilename%7D&policy=eyJleHBpcmF0aW9uIjoiMjAxNS0xMC0yN1QyMzozMTo1OVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJqZC1mb28ifSxbInN0YXJ0cy13aXRoIiwiJGtleSIsInVwbG9hZHMvNDZiZThjYTMtNmQzYS00YmI3LWE2NTgtZjJjOGUwNThiYzI4LyJdLHsic3VjY2Vzc19hY3Rpb25fc3RhdHVzIjoiMjAxIn0seyJhY2wiOiJwdWJsaWMtcmVhZCJ9LHsieC1hbXotY3JlZGVudGlhbCI6IkFLSUFKSjIyRDRQU1VOQkI1UkFRLzIwMTUxMDI3L3VzLXdlc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IngtYW16LWFsZ29yaXRobSI6IkFXUzQtSE1BQy1TSEEyNTYifSx7IngtYW16LWRhdGUiOiIyMDE1MTAyN1QyMjMxNTlaIn1dfQ%3D%3D&success_action_status=201&file=12foo
It seems like my problems could be tied to both
Bad format of the post body including problems with special characters
Not providing S3 with enough data in post body including keys and other information, the documentation feels a bit unclear about what is/is not required.
The error back from S3 servers looks like
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>MalformedPOSTRequest</Code><Message>The body of your POST request is not well-formed multipart/form-data.</Message> <RequestId>DCE88AC349D7B2E8</RequestId><HostId>AKE1xctETuZMAhBFLfyuFlDxikYUlbAC7YufkM7h8Z8eVQdtLA25Z0Od/a4cMUbfW1nWnGjc+vM=</HostId></Error>
I'm pretty unclear on what my actual problems are and where I should be digging in.
Any input would be greatly appreciated.
<Message>The body of your POST request is not well-formed multipart/form-data.</Message>
It may not be that you're missing values from the body. The most significant issue here is that the structure of your body does not resemble multipart/form-data.
See RFC 2388 for how multipart/form-data works. (Or find a library that builds this for you.)
What you are sending looks more like the application/x-www-form-urlencoded format, which is used by some AWS APIs, but not S3.
There is an example in the S3 docs showing what an example POST body might look like. You should see a substantial difference there.
Note also that POST is intended for browser based uploads. If you are uoloading from code, you're doing a lot of extra work. PUT Object is much more straightforward. The request body is the binary file contents. Or, if this will eventually be done by a browser, then test it with a browser, and let the browser build your form.