Since I am learning about HTTP packets and chrome extension, I thought of developing an extenison which could extract the GET and POST arguments of a website?
Is it possible using chrome extension?
GET is embedded data in the URL
Example : http://stackoverflow.com?username=user782400
?username=user782400 is a GET request ..
You can fetch the data in URL's username
in POST
where data is posted back to server , using forms ... you need to know to field names which are posted to fetch the data.
Best thing is Use JQuery jQuery.get() to GET
$.ajax({
url: url,
data: data,
success: success,
dataType: dataType
});
POST
$.ajax({
type: 'POST',
url: url,
data: data,
success: success,
dataType: dataType
});
Related
I'm trying to migrate one of my systems from RequestJS to the new (currently experimental) fetch feature of Node 17.5+ but I'm having issues with the uploading of files, I'm hoping someone can assist.
At the receiving end I have Multer which is doing a simple upload.single('document') which always returns an empty object, so I'm fairly sure the way I'm sending the data is wrong.
In order to send the request, I'm doing the below (this is not the exact code, it's just to give an idea):
var requestOptions = {
headers: {'Content-Type': 'multipart/form-data'},
formData: {
document: {
value: _bufferData,
options: {
filename: _fileName,
contentType: _mimeType
}
}
}
};
Then I'm obviously sending the request using:
fetch('http://myurl.com/fileUpload', requestOptions).then(....);
I'm guessing new fetch API doesn't process the formData property the same way requestJS does. Does anyone know how I should be doing this?
Thanks.
Update: I've investigated further and the issue appears to be due to the content-disposition header missing the filename. I'm not sure how Multer creates this header but I assume its from the formdata, where the filename is clearly being passed in.
My request body for an endpoint is so long:
1st question: I read that we can use some request.body.js file for storing our request body and then call it where ever we need it. But unfortunately, I could not find any sample framework/tutorial to learn it.
2nd question: in my project the properties of the request body (especially names of properties) are not exactly matching with the response body that is gaven in the Swagger document. What can be the reason? What would be your approach?
I would appreciate it if you could help me to ridd off the question in the best possible way. Thank you!
It's quite straight forward, take a look at this login example:
cy.fixture('users.json').then((userdata) => {
cy.request({
method: 'POST',
url: <auth_url>,
form: true,
body: userdata
});
});
You can export this as cypress function and then have it available in all your test spec files.
users.json file in fixtures folder looks like this:
{
"username": "...",
"password": "..."
}
Hope that answers the first question at least.
I want to share uploaded files in dropbox with another member.
add_member={
method: "POST",
url:'https://api.dropboxapi.com/2/sharing/add_file_member',
headers:{
"content-Type":"application/json",
"Authorization": "Bearer " + access_token,
"Data":"{\"file\": \"id:3kmLmQFnf1AAAAAAAAAAAw\",\"members\": [{\".tag\": \"email\",\"email\": \"jyotijagtap2209#gmail.com\"}],\"custom_message\": \"This is a custom message about ACME.doc\",\"quiet\": false,\"access_level\": \"viewer\",\"add_message_as_comment\": false}"
},
body:content
}
request(add_member,function(err,res,body){
console.log("link shared", body);
})
This is my code. I have also read documentation for Dropbox API but I can't get what is id given to this file and I didn't get any error. What I am missing?
The file parameter you supply to /2/sharing/add_file_member should be the id for the file for which you want to add a file member.
You can get the id for a file from the Metadata for the file, such as is returned by /2/files/get_metadata or /2/files/list_folder[/continue], for instance.
Also, note that /2/sharing/add_file_member uses the RPC request/response style, so your parameters should be sent as JSON in the request body, not a header.
In any case, make sure you check the resulting response status code and body to see if the call succeeded or failed, and to retrieve any returned result or error information.
Trying to post a file to a subfolder of the Shared Documents folder. I thought I had the correct syntax down, but I keep getting StatusCode 400 Bad Request.
https://graph.microsoft.com/v1.0/sites/xxxxxx.sharepoint.com,495435b4-60c3-49b7-8f6e-1d262a120ae5,0fad9f67-35a8-4c0b-892e-113084058c0a/drives/b!tDVUScNgt0mPbh0mKhIK5WefrQ-oNQtMiS4RMIQFjAqJk9Tt237bQYC9yEkyNOr6/items/01JDP7KXJ7ZSCYHUJC7BFJW2X6BTR4Z4JH:/filename.xlsx:/content
where "filename" is the actual filename.
I know a GET to the following lists the subfolder:
https://graph.microsoft.com/v1.0/sites/xxxxxx.sharepoint.com,495435b4-60c3-49b7-8f6e-1d262a120ae5,0fad9f67-35a8-4c0b-892e-113084058c0a/drives/b!tDVUScNgt0mPbh0mKhIK5WefrQ-oNQtMiS4RMIQFjAqJk9Tt237bQYC9yEkyNOr6/items/01JDP7KXJ7ZSCYHUJC7BFJW2X6BTR4Z4JH
Request is going out as:
{Method: PUT, RequestUri: 'https://graph.microsoft.com/v1.0/sites/xxxxxx.sharepoint.com,495435b4-60c3-49b7-8f6e-1d262a120ae5,0fad9f67-35a8-4c0b-892e-113084058c0a/drives/b!tDVUScNgt0mPbh0mKhIK5WefrQ-oNQtMiS4RMIQFjAqJk9Tt237bQYC9yEkyNOr6/items/01JDP7KXJ7ZSCYHUJC7BFJW2X6BTR4Z4JH:/', Version: 2.0, Content: <null>, Headers:
{
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJub...BXS_cSg1CcZHj5Q
}}
Seems like it is dropping part of the request to me.
First, https://graph.microsoft.com/v1.0/sites/xxx.sharepoint.com,495435b4-60c3-49b7-8f6e-1d262a120ae5,0fad9f67-35a8-4c0b-892e-113084058c0a/drives and https://graph.microsoft.com/v1.0/sites/xxx.sharepoint.com/drives will return the same results, we prefer the second one.
I have never sucessful run the following API:
/drives/{drive-id}/items/{parent-id}:/{filename}:/content
But based on my test, the following API works well:
/v1.0/me/drive/root:/Test/Test1.txt:/content
or
/v1.0/me/drives/driveid/root:/Test/Test1.txt:/content
I have an issue trying to download files attached to Podio items:
podio.request('get', '/file/{file_id}/raw').then(console.log);
The above program displays:
{}
This is a JSON stringified empty object (instead of raw file content).
Details:
The above file can be accessed with its URL when logged in
The above code is run after proper authentication
It actually works when using a file_id from an image field of the item, but not from a file attachment (pdf files in my case).
When using API endpoint /item/app/{app_id}/filter to get a list of items, the property file_count is set, but not files. I have to request /item/{item_id} individually to get the files property included in the response, not sure why.
Question: Do you know what is the issue, and how I can download raw attached files?
EDIT: aditionnal info
If I request a single file metadata using the folowing command:
podio.request('get', '/file/1234').then(console.log);
I get a file JSON object which includes many fields, but not the file content :
{
...
link: 'https://files.podio.com/1234',
file_id: 1234,
...
}
As stated in my comment to #stengaard, if I try to request the API for the above link, here is the response :
{ [PodioNotFoundError: [object Object]]
message:
{ error_parameters: {},
error_detail: null,
error_propagate: false,
request:
{ url: 'http://api.podio.com/1234',
query_string: '',
method: 'GET' },
error_description: 'No matching operation could be found. The path \'/1234\' was not found..',
error: 'not_found' },
status: 404,
url: 'https://api.podio.com:443/1234',
name: 'PodioNotFoundError' }
To use the GET /file/{file_id}/raw endpoint you need an API key with elevated trust levels.
Instead use GET /file/{file_id} endpoint. That contains a link attribute (a URL) you should follow to get the file content.
The link attribute will look like: https://files.podio.com/{file_id}. To fetch the file do https://files.podio.com/{file_id}?oauth_token={oauth_token}. Where the OAuth token is the same as the one used to GET /file/{file_id}. If you know the file ID (e.g. from a GET /item/{item_id} you can skip the GET /file/{file_id} and contact files.podio.com directly. (Note: You can also set the Authorization: OAuth2 {oauth_token} header in your HTTP request if you don't like passing the auth token in a URL paramter.)
For an example on how to use it see https://github.com/podio/podio-js/blob/master/lib/general.js#L11
Typically in the JS client, if you use podio as your Podio API object, the OAuth token would be located there:
podio.authObject.accessToken
So to get the raw content of the file in nodejs:
var url = 'https://files.podio.com/'+file_id+'?oauth_token='+podio.authObject.accessToken;
request(url, function (err, fileContent) {
// use fileContent here, write to a file, etc...
});
It seems your request has an error.
please try the below method and get raw file content from its response.
podio.request('get', '/file/{file_id}').then(console.log);
FYI, we couldn't get the files by filtering the items. we need to request /item/{item_id} individually to get the files property as you said.