Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Can not communicate with API due to CORS error

  • kubade1
  • kubade1's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 weeks 1 day ago #267667 by kubade1
LimeSurvey version: LimeSurvey Cloud Version 6.6.7
==================

Hello, I am trying to communicate with LSRC2 API. I started from fetching session key but can't get it due to CORS error each time I try to send request. I send it from locally served angular app. Here is my Interfaces tab configuration from Global settings:

RPC interface enabled: JSON-RPC
Publish API on /admin/remotecontrol: On
Set Access-Control-Allow-Origin header: On

Code snippet:
Code:
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
 
@Injectable({
  providedIn: 'root',
})
export class LimeSurveyService {
  private sessionKey: string | null = null;
  private limeApiUrl =
    'https://xxxxxxxx.limesurvey.net/admin/remotecontrol';
  private username = 'username';
  private password = 'password';
 
  constructor(private http: HttpClient) {}
 
  loginAndGetSessionKey$(): Observable<any> {
    const params = {
      method: 'get_session_key',
      params: [this.username, this.password],
      plugin: 'Authdb',
    };
 
    const headers = new HttpHeaders({
      'Content-Type': 'application/json',
      'connection': 'Keep-Alive',
    });
 
    return this.http.post(this.limeApiUrl, params, {
      headers: headers,
    });
  }
}


Thanks in advance.
 

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose