I am trying to fetch the conversations from my messagebird api, I tried in postman and all is good but when I'm trying to get from my angular project, that gives me an error, this is my code:
export class AppComponent {
constructor(private service: WaServiceService) { }
fetchCharacters() {
this.service.getConversations().subscribe(
(data) => {
console.log(data);
},
(error) => {
console.error(error);
}
);
}
}
my service:
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class WaServiceService {
private apiUrl = 'https://conversations.messagebird.com/v1/conversations?status=all&offset=0&limit=20';
private apiKey = 'AccessKey abc123';
constructor(private http: HttpClient) { }
getConversations(): Observable<any> {
const url = `${this.apiUrl}`;
const headers = new HttpHeaders().set('Authorization', `${this.apiKey}`);
return this.http.get(url, { headers });
}
}
What am I doing wrong?