Unable to debug Content-Type request header of incoming webrequest - json

I'm testing my application with Postman and while testing I've added multiple headers:
These headers I recieve in my API and I'm able to only debug my custom headers "loggedInUser" and "AuthorisationKey". I'm doing this with the following code:
loggedInUser = int.Parse(this.ActionContext.Request.Headers.GetValues("loggedInUser").First());
providedAuthKey = this.ActionContext.Request.Headers.GetValues("AuthorisationKey").First();
However I cant find the header "Content-Type" in my ActionContext, I've tried the following:
var requestedDatatype = this.ActionContext.Request.Headers.GetValues("Content-Type").First();
var requestedDatatype = this.Request.Content.Headers.ContentType;
Does anyone know how to do this?
Thanks in advance!

Authorization can handle it, check this out man https://learning.getpostman.com/docs/postman/sending_api_requests/authorization/

Related

Get Thumbnail from FORGE API but received status code 202

I'm trying to get thumbnail from Forge API here
https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/thumbnails/urn-thumbnail-GET/
`
I got it with Postman and axios successfully, and I tried it with RestSharp, HttpClient and GetThumbnail from DerivativesApi (Autodesk.Forge) in C# but only got status code 202 with message:
{"Result":"The thumbnail generating for this graph node is pending"}
I realized that RestSharp and HttpClient only receive code 202 and return results. I don't know how I can wait for code 200 and thumbnail.
Can anyone help me?
This is my code:
var request = new RestRequest($"https://developer.api.autodesk.com/modelderivative/v2/designdata/{nameHash}/thumbnail", Method.GET);
request.AddHeader("Authorization", $"Bearer {oauth.access_token}");
var client = new RestClient();
var restRes = client.Execute(request);
The 202 code typically indicates that the request has been accepted but the response is not available yet. Is it possible that you're asking for a thumbnail of a file that is still being processed by the Model Derivative service? Try inspecting the response headers, and see if there's one called x-ads-job-status which (according to the documentation) should tell you the status of the processing.

Why am I getting an empty response back from UrlFetchApp in Google Apps Script?

I am trying to make a GET request to an external API from a Google Apps Script using UrlFetchApp. When I make this request with Postman or curl, I get back the expected response. However, when I try it with UrlFetchApp, I get back an empty response, {}.
I have tried using Basic Auth and OAuth 2, as well as explicitly setting the oauthScopes property in the manifest as described here.
I have confirmed with the API team that they are indeed sending back a full response when I hit the endpoint, but all I receive is {}. My problem seems similar to this StackOverflow question which went unanswered.
var headers = {
"X-Client-Key": "KEY",
"Authorization": "Bearer TOKEN"
};
var options = {
method: "get",
headers: headers,
}
var response = UrlFetchApp.fetch(ENDPOINT, options);
console.log(JSON.stringify(response)); // returns {}
Do not take what you see in logs at face value. fetch method of the UrlFetchApp service always returns an instance of HTTPResponse which is an object first and foremost. This is what the logs show you (I am assuming you are logging the response because this is the only context I am aware of where {} is displayed).
To extract useful information from the response, use the appropriate methods exposed on HTTPResponse instances, like getResponseCode or getContentText.

Ruby pass header with API

So I've been trying to set up my chat bot for Twitch. I want the user to be able to type !stats and then they'll see my Fortnite stats.
They can use the command and stuff, that's not what I'm having a problem with. I'm having some trouble sending a header to Fortnite Tracker API.
They want to recieve this: TRN-Api-Key: somelong-api-key-right-here in the header.
I've tried these methods:
require("httparty")
url = "https://api.fortnitetracker.com/v1/profile/pc/bentearzz"
header = {
key: "TRN-Api-Key: Somelong-api-key-here"
}
response = HTTParty.get(url, header: header)
puts(response.body)
and this
require("net/http")
require("json")
url = "https://api.fortnitetracker.com/v1/profile/pc/bentearzz"
uri = URI(url)
response = Net::HTTP::Get.new(uri)
response.basic_auth("TRN-Api-Key: 7af072f0-d195-4c44-b1b4-a8838080e4c4")
JSON.parse(response)
print(response)
Please help.
Your first one is on the right track. I think there are just a few syntax errors.
url = "https://api.fortnitetracker.com/v1/profile/pc/bentearzz"
headers = {
"TRN-Api-Key": "Somelong-api-key-here"
}
response = HTTParty.get(url, headers: headers)
puts(response.body)

POST request not able to find url

I am new to nodejs as well as developing.
I am trying to get a set of data bat from a nutrition site in JSON format. If I formulate the url with my app and api keys along with criteria to paste into the browser I get a JSON data ok. When I try to send a POST request as the site asks for when the request comes back it says it cannot find the url. What it is doing is attaching ':443' to the end of the host url and like I said coming back as an error:
Error: getaddrinfo ENOTFOUND https://api.nutritionix.com/v1_1/search https://api.nutritionix.com/v1_1/search:443
What I would like to do is after the end of the url is append the 'postData'.
Here is my code:
var https = require('https');
var querystring = require('querystring');
var postData = { // Nutrionix required JSON formt
"appId":"MY_APP_KEY",
"appKey":"MY_API_KEY",
"query": "Lentils",
"fields": ["item_name", "nf_calories", "nf_serving_size_qty", "nf_serving_size_unit"],
"sort":{
"field":"score",
"order":"desc"
},
"filters":{
"item_type":"2"
}
};
console.log("This is header dta" + postData);
postBody = querystring.stringify(postData);
var post_options = {
host:"https://api.nutritionix.com/v1_1/search",
"port":"443",
method:"post",
"path":"/",
headers:{"Content-Type":"application/json",
'Content-Length': postBody.length
}
}
console.log(post_options);
var request = https.request(post_options,function(response){
return response;
});
I also am passing this data into the dev HTTP add-on in Chrome and getting back the proper response.
Any help would be appreciated.
Can you please take a look at this documentation?
It seems that you don't need to mention HTTPS
Take the port off, 443 is the default for HTTPS.

BackgroundTransferRequest DownloadLocation to get the Response content

I am uploading a file to the server using BackgroundTransferRequest object. I need to access the response header sent from the server. Based on the research, I understand that there is no direct access to the Response of the request and one possible work around is to provide a download location to which the response content will be written.
However, when I try to do that, there is no data written to that file and its 0 bytes. My request server is actually sending a response having ONLY the headers (without any content).
So my question is, does the response have to have body in order to get the response written to the DownloadLocation?
My code sample:
var request = new BackgroundTransferRequest(targetUri)
{
DownloadLocation = new Uri(downloadTo, UriKind.Relative),
UploadLocation = new Uri(uploadFrom, UriKind.Relative),
Method = "POST"
};