Skip to content

Cant get data via JS or PHP from Parse Server #352

Description

@gateway

So, im a bit frustrated right now due to the fact that I'm trying to get data out of the parse server via either PHP or JS and I wanted to make sure I wasn't doing something wrong or missing something.

First Im running parse server on Heroku with MongoLab and I have confirmed that its working via CURL command to pull the same data I'm trying to with JS or PHP.

Here is my CURL command that returns results I'm looking for.

curl -X GET \
  -H "X-Parse-Application-Id: xxxxxxxxx" \
  -H "X-Parse-REST-API-Key: xxxxxxxxx" \
  -H "X-Parse-Master-Key: xxxxxxxxx" \
  -G \
  --data-urlencode 'where={"gamelID":"afcd60f2-f9b2-4c5f-9148-1de46713552b"}' \
  https://xxxxxx.herokuapp.com/parse/classes/UserTag

Yesterday I tried to get the same data returned from CURL via PHP w/o any luck see #124

Today I wanted to see if I could get it working with a simple JS query see code below.

<!doctype html>
<head>
  <meta charset="utf-8">
  <title>My Parse App</title>
  <meta name="description" content="My Parse App">
  <meta name="viewport" content="width=device-width">
  <link rel="stylesheet" href="css/reset.css">
  <link rel="stylesheet" href="css/styles.css">
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script type="text/javascript" src="http://www.parsecdn.com/js/parse-latest.js"></script>
</head>
<body>
  <div id="main"></div>
  <script type="text/javascript">

    Parse.initialize("xxxxxx", "xxxxxx");
    Parse.serverURL = 'https://xxxx.herokuapp.com/parse'

    var UserTag = Parse.Object.extend("UserTag");
    var query = new Parse.Query(UserTag);
    query.equalTo("gameID", "afcd60f2-f9b2-4c5f-9148-1de46713552b");
    query.find({
      success: function(results) {
        console.log("Successfully retrieved " + results.length + " scores.");
        // Do something with the returned Parse.Object values
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          console.log(object.id + ' - ' + object.get('placeName'));
        }
      },
      error: function(error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    })

  </script>
</body>
</html>

In the console log im getting a 403

image

I have verbose enabled but the Heroku logs really dont tell me much

2016-02-11T00:07:36.599825+00:00 heroku[router]: at=info method=POST path="/parse/classes/UserTag" host=xxxx.herokuapp.com request_id=b6c443c9-0a33-4e08-b309-4add49b9be18 fwd="12.215.39.106" dyno=web.1 connect=1ms service=17ms status=403 bytes=273

Anyone have any ideas..

I have double checked my keys, and again as stated above the CURL request works.

In the migration docs it states for using the JS SKD use this code

Parse.initialize("YOUR_APP_ID", "YOUR_APP_CLIENT_KEY");
Parse.serverURL = 'http://localhost:1337/parse'

Any thoughts? If its a silly mistake on my part I'm sure im not the only one running into it so any debugging would be appreciated.

Activity

  1. rogerhu commented on Feb 11, 2016

    @rogerhu
    Contributor

    The JavaScript SDK uses javascriptKey. The parse-server-example doesn't set it on init. You have to modify your index.js file:

    https://github.com/ParsePlatform/parse-server-example/blob/master/index.js#L13-L17

    var api = new ParseServer({
      databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
      cloud: process.env.CLOUD_COD
      javascriptKey: process.env.CLIENT_KEY || 'javascriptKey',

    Shouldn't parse-server-example simply init it for backwards compatibility?

    Also, I was able to get stuff to work with master Key but it becomes something like the following (for some reason I have to set useMasterKey on the actual save as well):

        Parse.initialize("myAppId", "javascriptKey");
        Parse.masterKey = "abc";
        Parse._useMasterKey = true;
    
       var testObject = new TestObject();
          testObject.save({
            foo: "bar",
            success: function (object) {
              $(".success").show();
            },
            error: function (model, error) {
              $(".error").show();
            }
          }); {useMasterKey: true});
  2. gfosco commented on Feb 11, 2016

    @gfosco
    Contributor

    This could be a keys issue. The best troubleshooting step here is not to set any client keys. No rest/js/client/dotnet... Only master key should be defined. Unauthorized means either you've hit the wrong server, or you're using the wrong appid/keys, or you've set at least 1 client key but not the one you're calling with (i.e. you set the rest key, and now get fails on JS).

  3. rogerhu commented on Feb 11, 2016

    @rogerhu
    Contributor

    @gfosco - it is definitely a keys issue, has the Parse JavaScript SDK been updated though to make things more streamlined to work with the master key? See comment above.

  4. gateway commented on Feb 11, 2016

    @gateway
    Author

    as @rogerhu pointed out the JS key works now.. thanks btw.. I think using a master key in JS web code would be a super bad thing personally so I try to avoid using the master key in 99% of the cases.

    Now to try to figure out the issue #124 on the PHP side of things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:questionSupport or code-level question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions