Start a new topic
Answered

Trouble fetching a collection

I'm trying to fetch a few items from my collection but I receive an error, "The credentials used to authenticate this request are not authorized to run this operation. Please retry your request with appropriate credentials" 


The request: 

let dataStore = DataStore<Item>.collection(.network)
        
        dataStore.find { (item, error) in
            if let item = item {
                //succeed
                print("Items: \(item.count)")
                
            } else {
                print("ERROR: \(error?.localizedDescription)")
                //fail
            }
        }

 

Model:

import Kinvey

class Item: Entity {

    dynamic var name: String?
    
    override class func collectionName() -> String {
        //return the name of the backend collection corresponding to this entity
        return "items"
    }
    
    override func propertyMapping(_ map: Map) {
        super.propertyMapping(map)
        
        name <- ("item_name", map["item_name"])
        
    }
}

 

The items collection's permission is set to Read Only.


Best Answer
Shae,

  1. So "Item" is the name of your collection. Let me know the username of your 'test' user.
  2. Can you please change collection's permission to different options and try to fetch records again? Let me know if it works.
  3. Are you fetching the same records which were created by your 'test' user (results will depend on what permission is set for the collection)?
  4. Also can you try fetching records from "Item" collection by logging in 'test' user on Kinvey API console. Please check http://devcenter.kinvey.com/rest/guides/datastore#Fetching. Make sure you login using 'test' user, not mastersecret.


Thanks,

Pranav

 


Answer
Shae,

  1. So "Item" is the name of your collection. Let me know the username of your 'test' user.
  2. Can you please change collection's permission to different options and try to fetch records again? Let me know if it works.
  3. Are you fetching the same records which were created by your 'test' user (results will depend on what permission is set for the collection)?
  4. Also can you try fetching records from "Item" collection by logging in 'test' user on Kinvey API console. Please check http://devcenter.kinvey.com/rest/guides/datastore#Fetching. Make sure you login using 'test' user, not mastersecret.


Thanks,

Pranav

 

Hey Pranav,

I am currently logging in a test user before I make the call to get the collections so there's a user. Seems like it's something I'm missing, even when I take the .network option out of the collection's call it succeeds but return 0 items.

Shae,

At first glance, I think login session has not been established before accessing/ fetching data from the backend. Please login and then try fetching few items from your collection. Please check http://devcenter.kinvey.com/ios/guides/users#login.

Good luck, and let me know how it goes.

Thanks,
Pranav
Kinvey

 

Login or Signup to post a comment