iosapigeeusergridmbaas

Can't connect user to entity in Apigee Usergrid


When using the IOS API, I'm making a call to connect via the ApigeeDataClient connectEntities method. I pass in the type "users", then the user's uuid, then connectionType "likes", with the connectee type of "songs" and the song's uuid.

Example:

ApigeeClientResponse *response = [_dataClient connectEntities:@"users" connectorID:_apigeeUser.uuid connectionType:@"likes" connecteeType:@"songs" connecteeID:song.uuid];

When I make the connection, it says successful, but when I look at the data on the server, it seems to save the connection incorrectly. For example, for the song, I see:

connecting :likes :/songs/b523a6aa-bb39-11e4-a2bb-35673af856e9/connecting/likes

It looks like the song's uuid isn't in the connecting path.

The same is true for the connection related to the user. It's the user's uuid that seems to be connected to the same user. The uuid is that of the song's uuid, not the user's. When I make the call to getEntityConnections, like so:

ApigeeClientResponse *response = [_dataClient getEntityConnections:@"songs" connectorID:_apigeeUser.uuid connectionType:@"likes" query:nil];

It returns an error, saying "expected song, but got user's uuid.

Entity c831e1c4-2e6e-11e4-94ce-299efa8c6fd5 is not the expected type, expected song, found user"

In looking in Apigee itself, in the data section, I see the following snippet:

"connections": {
  "likes": "/users/c831e1c4-2e6e-11e4-94ce-299efa8c6fd5/likes"
}

The song's uuid is missing. Even when I try to update the JSON directly on the server, basically adding the song's uuid to the end, it says it's saved, but it removes the song's uuid.

Even just using the curl method to make a connection doesn't work. For example:

curl -X POST http://api.usergrid.com/peterdj/sandbox/users/bc2fc82a-bfa3-11e4-a994-b19963f177‌​9d/likes/c37f1eaa-bfa3-11e4-9141-97b3510c98e6

When I make that call, I get this

{"action":"post",
  "application":"0baaf590-2c1b-11e4-9bb5-11cb139f1620",
  "params":{
  },
  "path":"/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/likes",
  "uri":"https://api.usergrid.com/peterdj/sandbox/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/likes",
  "entities":[
  {
    "uuid":"c37f1eaa-bfa3-11e4-9141-97b3510c98e6",
    "type":"song",
    "name":"WingSpan",
    "created":1425167080842,
    "modified":1425167080842,
    "bpm":"124",
    "code":"WingSpan",
    "genre":"Progressive House",
    "metadata":{
      "connecting":{
        "likes":"/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/likes/c37f1eaa-bfa3-11e4-9141-97b3510c98e6/connecting/likes"
      },
      "path":"/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/likes/c37f1eaa-bfa3-11e4-9141-97b3510c98e6"
    },
    "title":"Wing Span"
  }
],
  "timestamp":1425246006718,
  "duration":78,
  "organization":"peterdj",
  "applicationName":"sandbox"
}

Notice that the resulting connecting path seems correct when it's returned, but when do another GET curl, as so:

curl http://api.usergrid.com/peterdj/sandbox/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d

The song's uuid isn't there:

{
"action" : "get",
"application" : "0baaf590-2c1b-11e4-9bb5-11cb139f1620",
"params" : { },
"path" : "/users",
"uri" : "https://api.usergrid.com/peterdj/sandbox/users",
"entities" : [ {
   "uuid" : "bc2fc82a-bfa3-11e4-a994-b19963f1779d",
   "type" : "user",
   "name" : "peter",
   "created" : 1425167068578,
   "modified" : 1425167495412,
   "username" : "peterdj",
   "email" : "asdf@adf.com",
   "activated" : true,
   "picture" :"",
     "metadata" : {
     "path" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d",
     "sets" : {
       "rolenames" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/roles",
       "permissions" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/permissions"
     },
     "connections" : {
       "likes" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/likes"
     },
     "collections" : {
       "activities" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/activities",
       "devices" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/devices",
      "feed" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/feed",
      "groups" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/groups",
      "roles" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/roles",
      "following" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/following",
     "followers" : "/users/bc2fc82a-bfa3-11e4-a994-b19963f1779d/followers"
    }
  }
} ],
"timestamp" : 1425311662762,
"duration" : 12,
"organization" : "peterdj",
"applicationName" : "sandbox"
}

Is this a bug with the entity connections with Apigee/Usergrid or am I doing something wrong?

Thanks


Solution

  • Well, turns out, thanks to the comments by @remus, I've figured it out.

    In this call: ApigeeClientResponse *response = [_dataClient getEntityConnections:@"songs" connectorID:_apigeeUser.uuid connectionType:@"likes" query:nil];

    The connection needs to be "users", not "songs". Works now. Thanks @remus