Important Update: Community URLs redirect issues are partially resolved. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Angular and Archer REST API

SamSalefske1
Contributor III

Has anyone connected successfully to the REST API using angular? I'm more of a C# dev, but do a little bit here and there with angular. Thought I'd take some of my old code and recreate them with angular. So far it's not going well

 

I'm trying to start out with just getting a session, but seem to be getting hung up on the headers. I've confirmed the headers are being set, but the error I'm getting in the Console Tools is something I've never seen.

 

pastedImage_1.png

 

 

archer.services.ts file:

import { Injectable } from '@angular/core';

import { HttpClient } from '@angular/common/http';
import { HttpHeaders } from '@angular/common/http';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Injectable()
export class ArcherService {
constructor(private http: HttpClient) { }

getArcherSessionToken() {
console.log('Attempting to get session token');

const creds = {'InstanceName': 'ArcherInstance', 'Username': 'SysAdmin', 'UserDomain': '', 'Password': 'Password123!'};
let superheader = new HttpHeaders().set('Content-Type', 'application/json');
superheader = superheader.set('Accept', 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');

this.http.post('http://localhost/RSAarcher/api/core/security/login',
JSON.stringify(creds),
{ headers: superheader}).subscribe(
(val) => {
console.log('Post success', val);
},
response => {
console.log('Post call in error', response);
},
() => {
console.log('The Post observable is now completed.');
});
}
}

 

 

Anyone have any ideas?

5 REPLIES 5

Anonymous
Not applicable

Sam,

 

My best guess here is that this is a Cross-Origin Resource Sharing problem. Unfortunately, I don't have any handy tips or tricks for you to try other than to get after the Google Machine and try things out.

I've tried setting the IIS server to allow the OPTIONS verb to "*"; sending the CORS Headers (Access-Control-Allow-Origin/Methods/Headers) and a few other settings in IIS to allow HTTP OPTIONS to be handled. 

 

Unfortunately nothing has worked. the way the message is phrased ("the resource doesn't support OPTIONS") makes me think that the API doesn't handle the HTTP Method OPTIONS, which makes sense since the API docs only call out GET, POST, PUT, and DELETE which are the normal four verbs to handle.

 

I'm going to keep trying to nail this down, just for my own sanity!

Hello Sam,
Do you have any updates on this issue?

Thanks in advance.

I haven't made any progress on this, been fairly busy so had to set it down. This thread seems like it might be helpful, but haven't yet sifted through it. https://community.rsa.com/thread/194869 

MohammadAnasSid
Contributor II

Hi Sam,

I am also facing the same issue. My code is also on angular. Full description of the issue - CORS issue in API integration in Angular. Do you have any update on the issue?