Formatting JSON Data for Postman [closed] - postman

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to send JSON data as POST through POSTMAN but I keep getting the following error:

We could format/prettify the JSON request body within Postman.
Paste the JSON request body(raw)
Select JSON(application/json)
Press Ctrl + B

When your JSON is validated with JSONLint this is the result:
Error: Parse error on line 1:
{ taco: { name: "",
--^
Expecting 'STRING', '}', got 'undefined'
The object keys should be strings. This is valid JSON:
{
"taco": {
"name": "",
"price": "",
"photo_url": ""
}
}

paste in your json and hit the beautify button.

You can use simple quote (' or " works) :
in headers put Content-Type:application/json

Related

How to capture trackers like cookies, pixels, etc., used on a remote website? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We are working on a project similar to CookieBot as part of a larger project to protect personal data and information of web users. The aim is to obtain comprehensive information about tracking and profiling techniques so that the user can decide for themselves whether to allow their use. But prior owner of website has to know it.
How can we access a website in such a way that we can intercept requests and cookies?
You could try with puppeteer which allows you to script Chrome (or Chromium) via JavaScript.
In this example:
I go to this page
I print all requests going out from this page
I print all cookies set page this page
// pptr.js
const puppeteer = require('puppeteer-core');
module.exports = async () => {
const browser = await puppeteer.connect({ browserWSEndpoint: 'ws://localhost:3001' });
const page = await browser.newPage();
page.on('request', req => {
console.log(`request: ${req.url()}`);
});
await page.goto('https://stackoverflow.com/q/64901406/1244884');
const cookies = await page.cookies();
console.log('Cookies:');
cookies.forEach(cookie => {
console.log(`${cookie.name}\t${cookie.value}`);
});
await browser.close();
};
Which you can run as follow:
node -p -e 'require("./pptr.js")()'
Output:
request: https://stackoverflow.com/q/64901406/1244884
request: https://stackoverflow.com/questions/64901406/how-to-capture-trackers-like-cookies-pixels-etc-used-on-a-remote-website
request: https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js
request: https://cdn.sstatic.net/Js/stub.en.js?v=e10313546043
request: https://cdn.sstatic.net/Shared/stacks.css?v=3b16a418cc4c
request: https://cdn.sstatic.net/Sites/stackoverflow/primary.css?v=8cf2d7217e38
request: https://www.gravatar.com/avatar/79435cc2571ffa23dfcef703f8d762e0?s=32&d=identicon&r=PG
request: https://www.gravatar.com/avatar/f7c922ac3a9edef38d31baf959088f77?s=32&d=identicon&r=PG&f=1
request: https://cdn.sstatic.net/Img/unified/sprites.svg?v=fcc0ea44ba27
request: https://cdn.sstatic.net/Img/favicons-sprite16.png?v=f4676f10d215
request: https://cdn.sstatic.net/clc/clc.min.js?v=d7c7e62bd2f5
request: https://www.googletagservices.com/tag/js/gpt.js
request: https://www.google-analytics.com/analytics.js
request: https://secure.quantserve.com/quant.js
request: https://sb.scorecardresearch.com/beacon.js
request: https://cdn.sstatic.net/Js/full-anon.en.js?v=2d9c6897045f
request: https://cdn.sstatic.net/clc/styles/clc.min.css?v=83419f27e8fa
request: https://cdn.sstatic.net/Js/post-validation.en.js?v=2589ce0a8248
request: https://stackoverflow.com/posts/64901406/ivc/6697?_=1605741791032
request: https://cdn.sstatic.net/Img/unified/wmd-buttons.svg?v=c26278fc22d9
request: https://rules.quantcount.com/rules-p-c1rF4kxgLUzNc.js
request: https://pixel.quantserve.com/pixel;r=1818481277;rf=0;uht=2;a=p-c1rF4kxgLUzNc;url=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F64901406%2Fhow-to-capture-trackers-like-cookies-pixels-etc-used-on-a-remote-website;fpan=1;fpa=P0-221458664-1605741791402;ns=0;ce=1;qjs=1;qv=3364aec3-20201006003021;cm=;gdpr=0;ref=;d=stackoverflow.com;je=0;sr=800x600x24;dst=0;et=1605741791401;tzo=0;ogl=type.website%2Curl.https%3A%2F%2Fstackoverflow%252Ecom%2Fquestions%2F64901406%2Fhow-to-capture-trackers-like-cookie%2Csite_name.Stack%20Overflow%2Cimage.https%3A%2F%2Fcdn%252Esstatic%252Enet%2FSites%2Fstackoverflow%2FImg%2Fapple-touch-icon%402%252Epng%3Fv%3D73d79a8%2Ctitle.How%20to%20capture%20trackers%20like%20cookies%252C%20pixels%252C%20etc%252E%252C%20used%20on%20a%20remote%20website%3F%2Cdescription.We%20are%20working%20on%20a%20project%20similar%20to%20CookieBot%20as%20part%20of%20a%20larger%20project%20to%20
Cookies:
__qca P0-221458664-1605741791402
prov d91ccb9e-35d8-78ff-61b2-2c157d6d65c7

How to fix - Update plannertaskdetails - If-Match header contains an invalid value

I am trying to update (PATCH) an existing Microsoft Planner task, to add one (1) checklist item to it. I am using Microsoft doc https://learn.microsoft.com/en-us/graph/api/plannertaskdetails-update?view=graph-rest-1.0&tabs=javascript as a reference, and I am using Postman to send the request.
{
"error": {
"code": "",
"message": "The If-Match header contains an invalid value.",
"innerError": {
"request-id": "7b50a25b-7c5a-443b-9a41-1b6314be4014",
"date": "2019-05-16T23:59:03"
}
}
}
As far as I can see, the If-Match key is built up exactly the same as how Microsoft's article used it.
I have found a somewhat similar article (https://powerusers.microsoft.com/t5/Connecting-To-Data/Custom-Connector-Graph-The-If-Match-header-must-be-specified-for/td-p/144092), but this person is filling in the If-Match value differently, and it doesn't work for me at all...
I reused the eTAG value from the response received after creating the task in the first place:
"#odata.etag": "W/\"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc=\""
Does anyone have a clue what I am doing wrong here?
This is my PATCH:
https://graph.microsoft.com/v1.0/planner/tasks/n...................pYAM-DX/details
These are my headers:
Content-Type: application/json
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub..........
If-Match: W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBARCc="
This is my body:
{
"previewType": "checklist",
"checklist": {
"{{$guid}}":{
"#odata.type": "microsoft.graph.plannerChecklistItem",
"title": "Update task details",
"isChecked": false
}
}
}
I was expecting the If-Match key to be correct, as I have used the Microsoft article, but somehow it results in the error message:
"The If-Match header contains an invalid value."
I had similar problem. I used etag from task when updates Task details.
The Task and Task Details are different objects.
Check on - MS Graph doc
Get etag value from Task details of created task using:
GET https://graph.microsoft.com/v1.0/planner/tasks/{task-id}/details

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.

Amazon S3 - Method Not Allowed [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 days ago.
Improve this question
I'm trying to configure for the 1st time the S3 service from Amazon, but I can't upload a file, because I get the following exception (I already gave the user full access to S3, but i keep getting this):
Method Not Allowed (Service: Amazon S3; Status Code: 405; Error Code: 405 Method Not Allowed; ... )
The class below is my configuration class (the keys were changed to "xxx" for security):
public class AmazonConfiguration {
private final String ACCESS_KEY = "xxxxxxxxx";
private final String SECRET_KEY = "xxxxxxxxx";
#Bean
private AmazonS3 amazonS3client() {
//Credenciais de acesso
AWSCredentials credentials = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonS3 s3Client = new AmazonS3Client(credentials, new ClientConfiguration());
s3Client.setS3ClientOptions(new S3ClientOptions().withPathStyleAccess(true));
s3Client.setEndpoint("http://springmvccasadocodigo.s3-website-us-west-2.amazonaws.com/"); //springmvccasadocodigo.s3-website-sa-east-1.amazonaws.com
return s3Client;
}
}
Next class is where I try to upload the file:
#Component
public class FileServer {
#Autowired
private HttpServletRequest request;
#Autowired
private AmazonS3 s3;
public String writeAmazonS3(String baseFolder, MultipartFile multpartFile) {
try {
s3.putObject("springmvccasadocodigo",
multpartFile.getOriginalFilename(),
multpartFile.getInputStream(), new ObjectMetadata());
return "http://springmvccasadocodigo.s3-website-us-west-2.amazonaws.com/"
+ multpartFile.getOriginalFilename() + "?noAuth=true";
} catch (AmazonClientException | IOException e) {
e.printStackTrace();
throw new RuntimeException();
}
}
}
s3Client.setEndpoint("http://springmvccasadocodigo.s3-website-us-west-2.amazonaws.com/"); //springmvccasadocodigo.s3-website-sa-east-1.amazonaws.com
That's not a proper endpoint. And combining it with "path style access" is making it more difficult to debug. ("The path-style syntax... requires that you use the region-specific endpoint when attempting to access a bucket.")
Here's the list of endpoints; if your bucket is in us-west-2, the proper endpoint is s3-us-west-2.amazonaws.com. However, that's mostly useful for "off label" uses of the API, like connecting to OpenStack resources.
I believe you can simply remove those two lines ("setEndpoint" and "setS3ClientOptions").

Grape POST request receiving JSON

I am having problem with grape.
I have tried to look into their docs and google around.
I could not find any solution or sample regarding this.
Let say I am sending this kind of format to the POST request of grape:
{
"preferences": {
"play": {
"weekdays": "5",
"weekend": "8"
},
"grow": {
"weekdays": "4",
"weekend": "8"
}
}
}
Questions:
How do I setup the Grape params to receive this post?
I have tried something like this:
params do
optional :preferences, type: Hash do
optional :play do
optional :weekdays
optional :weekend
end
optional :grow, type: Hash do
optional :weekdays
optional :weekend
end
end
end
I am using postman to do the POST on my chrome. My question is, How do I set the Hash kind of params ? There are 3 options on postman which are form-data, form-urlencoded, and raw. I have tried with form-data and raw (json) it does not work for the raw json, it gave me an error saying that
The requested content-type 'text/plain' is not supported
Any idea how do I fix these problems?
Thank you very much
Answering question 1: If all parameters are optional then you don't even need the params block. Get rid of it and, for example, use params[:preferences][:play][:weekdays] to access the weekdays attribute. Just use the same idea to access other values.
Answering question 2: On Postman, use RAW but don't forget to set the header Content-Type to application/json. I've written the code below to play around with this example.
require 'grape'
class API < Grape::API
version 'v1', :using => :header, :vendor => 'alienlabz', :format => :json
format :json
resource :preferences do
post do
puts params[:preferences][:play][:weekdays]
end
end
end
run API