Search code examples
angulartypescriptparse-platformangular-servicesparse-server

How to use Parse SDK with Angular 7


I'm trying to do a GET request on a Parse backend but i have a 403 response from the server. I tried to follow these instructions but i still have the issue.

Here's the configuration of my service :

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { environment } from 'src/environments/environment';
import * as Parse from 'parse';


Parse.initialize('MY APP ID', 'MY MASTER KEY ID'); // use your appID & your js key
(Parse as any).serverURL = 'https://MYURL/parse'; // use your server url


@Injectable({
  providedIn: 'root'
})
export class BackofficeService {

  constructor(private http: HttpClient) {}

  public getStores(): Observable<any> {
    return this.http.get(Parse.serverURL + '/classes/Stores');
  }

I tried to add an empty paramater for the jskey (because i used master key instead of JS key) but it didn't work.

Parse.initialize('MY APP ID', '', 'MY MASTER KEY ID'); // use your appID & your js key

Solution

  • You are trying to use the Rest API of the Parse server, but you configure it with the SDK.

    As you configure the SDK and you have it, I really recommend you to use it. Here is how to get all object of stores.

    var Stores = Parse.Object.extend("Stores");
    var query = new Parse.Query(Stores);
    query.find().then(function(results) {
      console.log(results);
    });