hey guys im having some wierd issue,
i get the error i stated in the title when i try to fetch something from an api,
when i check with postman with the same url i get a valid jason,
the request comes back with a status of 200 so its fine on that end.
howerver when i execute the following command the error occurs:
fetch('/api/bug',{mode:'no-cors'}).then(response => response.json())
.then(data => console.log(data));
the Json:
{
"_id" : "abc123",
"title" : "Cannot save ",
"description" : "problem ",
"severity" : 1,
"createdAt" : 154210735954,
"creator" : {"nickname" : "Nick"}
}
Edit:
After changing from Json To Text,
The fetch request returns the html of the page, and the postman request return a json, any reason for this?
Related
I'm trying to understand why when I transform the observable it comes up undefined in the console log even though I know it has values assigned to it.
Http Request
getLibraryCardPeople(bookName: String): Observable<people[]> {
return this.http.get<LibraryCard>(url).pipe(map(results => results.people));
}
JSON response
book : "LOTR"
people : [
{"name" : "joe", "age" : 20 , "Location": [...]},
{"name" : "sarah", "age" : 16 , "Location": [...]}
]
When I execute the function and try and observe the people array is always undefined in the console log. However, If I don't map, I can see the entire JSON Response is defined.
You need to subscribe to the httpClient. First subscribe will activate the http call so to say.
getLibraryCardPeople(bookName: String): Observable<people[]> {
return this.http.get<LibraryCard>(url);
}
Then in your component:
this.myService.getLibraryCardPeople.subscribe(data => {
data.pipe(map(results => results.people));
})
This is the normal way to use HttpClient. What you can do, too, is to use toPromise from RxJS. Read all about here. A example:
this.http.get<LibraryCard>(url).toPromise()
.then(res => console.log(res))
.catch(err => { console.log ('error');
I'm trying to get to grips with the Places API and I am getting an invalid request when I enter the address_component as a field. The formatted_address works though I understand that should not be used if we want to parse it programatically.
Sample request:
https://maps.googleapis.com/maps/api/place/findplacefromtext/json?fields=address_components%2Cname%2Ctype&input=George%20Street&inputtype=textquery&key=MY_API_KEY
Response:
{
"candidates": [],
"error_message": "Error while parsing 'fields' parameter: Unsupported field name 'address_components'. ",
"status": "INVALID_REQUEST"
}
I want to post this JSON code and send it to https://localhost:44324/api/ocorrenciasapi:
{
"dispositivo":"dewdkij",
"latitude" : "39",
"longitude" : "-9",
"azimute": "43",
"fotografia": "lifhwee",
"estado":"ldhel"
}
I doing this on the Body-raw with JSON. However, everytime I send this request, it returns "There was an error in evaluating the Pre-request Script: SyntaxError: Unexpected token :". What should I do?
The same happens when I do the GET request.
NOTE: I'm using a API Controller with action, using Entity Framework.
I'm using Vimeo's official NodeJS API module to build an app, and I can successfully upload a video without issue. I can also set the video's privacy property successfully. Now, I would like to move that uploaded video to an album, and if the album does not exist, I want to create one automatically. I have an access token stored in a file that my application reads from, and the scopes granted to the token are the following
"scope": "interact create edit upload delete video_files private public"
So, I've got the create scope which is needed to create a new album for a user. However, when I make the request to the Vimeo API, I am getting an error of which I cannot resolve or fix.
{
"invalid_parameters":[{
"field":"name",
"error_code":2204,
"error":"You have provided an invalid parameter. Please contact developer of this application.",
"developer_message":"The parameters passed to this API endpoint did not pass Vimeo's validation. Please check the invalid_parameters list for more information."
}]
}
Here is my code that is making the request:
if (!album_uri) {
console.log("Attempting to create a new album named `" + config.params.video.group + "`");
var req_make_album = {
"method" : "POST"
, "path" : "/me/albums"
, "name" : config.params.video.group
, "description" : config.params.video.group
};
api.request(req_make_album, function(error, body, status_code, headers) {
if (error)
throw new Error(error);
step();
})
}
To be sure, the config.params.video.group variable is a string and to be certain that it was in fact a string, I replaced the request options with literal ones as such:
var req_make_album = {
"method" : "POST"
, "path" : "/me/albums"
, "name" : "My First New Album"
, "description" : "My First New Album"
};
Still, I received the above error about the "name" field being invalid. What am I missing here? When I go to the Vimeo API "playground" for this particular endpoint, it does work (even when I authenticate via my app) but I don't understand why it won't work when I make the request via the NodeJS module. Why am I getting this error?
My mistake. The issue is that the Vimeo API requires that the items "name" and "description" to be passed as an object.
So, instead of
var req_make_album = {
"method" : "POST"
, "path" : "/me/albums"
, "name" : "My First New Album"
, "description" : "My First New Album"
};
It should actually be:
var req_make_album = {
"method" : "POST"
, "path" : "/me/albums"
, "query" : {"name" : "My First New Album", "description" : "My First Album's Description"
};
The more you know :)
I have tried deleting instances using https://cloud.google.com/compute/docs/reference/beta/instanceGroupManagers/deleteInstances but it's not working.
In the request body, I am entering
{
"instances": [
"scaler-group-instance-1"
]
}
For project, I used project-name-1
For zone, I used us-west1-a
For instanceGroupManager I am using scaling-group-manager
In response, I am receiving
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid value for field 'instances[0]': 'scaler-group-instance-1'. The URL is malformed.",
"reason" : "invalid"
} ],
"message" : "Invalid value for field 'instances[0]': 'scaler-group-instance-1'. The URL is malformed."
}
I have also tried this in Java as well using this code snippet and have also received a 400 Bad Request
String projectId = "project-name-1";
String zoneName = "us-west1-a";
String instanceGroupName = "scaling-group-manager";
List<String> instancesToDelete = new ArrayList<>();
instancesToDelete.add("scaler-group-instance-1");
InstanceGroupManagersDeleteInstancesRequest deleteInstancesRequest = new InstanceGroupManagersDeleteInstancesRequest().setInstances(instancesToDelete);
Compute.InstanceGroupManagers.DeleteInstances deleteInstances = compute.instanceGroupManagers().deleteInstances(projectId, zoneName, instanceGroupName, deleteInstancesRequest).execute();
Is there something wrong with my request that I'm not seeing?
I found the issue. This request expects the instance string to be a URL and not an instance name.
The instance can be found in the selfLink value in the listInstances requests.
Entering the selfLink URL into the request caused the server to reply correctly.