# iOS API calls do not expose Particle Cloud variables or functions

**URL:** <https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759>\
**Category:** Developer Tools\
**Tags:** photon\
**Created:** [October 16, 2019, 5:06pm UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759 "2019-10-16T17:06:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![as51p](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@as51p](https://community.particle.io/u/as51p)\
**Post date:** [October 16, 2019, 5:06pm UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/1 "2019-10-16T17:06:35Z")

</div>

Following the code in the reference documentation for the iOS SDK, I am unable to read variables or functions from the Particle Cloud. Running the code below does not list any of the variables or functions on the Photon which are exposed to Particle Cloud.

```auto
    func loginWithCredentials(userName:String, userPassword:String) {
        ParticleCloud.sharedInstance().login(withUser: userName, password: userPassword) { (error:Error?) -> Void in
            if let _ = error {
                // catch login failure
                print("Wrong credentials or no internet connectivity, please try again")
            } else {
                print("Logged in")
                var myPhoton : ParticleDevice?
                ParticleCloud.sharedInstance().getDevices {(devices:[ParticleDevice]?, error:Error?) -> Void in
                    if let _ = error {
                        print("Check your internet connectivity")
                    } else {
                        if let d = devices {
                            for device in d {
                                if device.name == "photon" {
                                 myPhoton = device
                                
                                }
                            }
                        }
                        //print the contents of myPhoton
                        print(myPhoton!)
                    }
                }
            }
        }
    }

```

Here is the printed output:

```auto
Logged in
<ParticleDevice 0x282f10410, type: Photon, id: 2c001f000a47363339343638, name: photon, connected: true, flashing: false, variables: {
}, functions: (
), version: 1.4.0, requires update: false, last app: (null), last heard: 2019-10-15 09:06:15 +0000, notes: (null), networkId: (null), networkRole: 0, networkRoleState: 0>

```

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [October 17, 2019, 3:26am UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/3 "2019-10-17T03:26:19Z")

</div>

What do you get when running `particle list photon`?

---

<div class="post-metadata">

**Author:** ![as51p](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@as51p](https://community.particle.io/u/as51p)\
**Post date:** [October 17, 2019, 4:36am UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/5 "2019-10-17T04:36:00Z")

</div>

```auto
particle list photon
photon [2c001f000a47363339343638] (Photon) is online 
 variables:
    analogvalue (int32)
    temp (double)
    mess (string)
    mess2 (string)
  Functions:
    int toggle(String args) 

```

CLI seems to display the variables and functions correctly. I attempted to call the functions and check the variables anyway in the iOS app. For some reason, the API calls requesting the values of the particular variables work, but you cannot print the variables and functions associated with the device when you print the contents of the object.

---

<div class="post-metadata">

**Author:** ![marekparticle](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/marekparticle/32/22793_2.png) [@marekparticle](https://community.particle.io/u/marekparticle)\
**Post date:** [October 17, 2019, 1:12pm UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/6 "2019-10-17T13:12:20Z")

</div>

@Raimis, would you mind taking a look into this? Thank you for your experienced eye! 🙂

---

<div class="post-metadata">

**Author:** ![Raimis](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/raimis/32/17562_2.png) [@Raimis](https://community.particle.io/u/Raimis)\
**Post date:** [October 17, 2019, 1:16pm UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/7 "2019-10-17T13:16:04Z")

</div>

This is odd. Can you please see if our Tinker app sees variables and functions for this device?

---

<div class="post-metadata">

**Author:** ![as51p](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@as51p](https://community.particle.io/u/as51p)\
**Post date:** [October 17, 2019, 5:18pm UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/8 "2019-10-17T17:18:09Z")

</div>

The Tinker app works just fine. It is indeed strange that I cannot get the API to list the variables and functions. If you’re interested, I can try making a sample project so you can have a closer look.

---

<div class="post-metadata">

**Author:** ![Raimis](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/raimis/32/17562_2.png) [@Raimis](https://community.particle.io/u/Raimis)\
**Post date:** [October 17, 2019, 5:37pm UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/9 "2019-10-17T17:37:14Z")

</div>

Ah my bad!.. `getDevices()` only loads cached device info - if I remember correctly it contains everything but variables and functions. Call `refresh()` on device instance you want to inspect. Pseudo-code for that would be:

```auto
ParticleCloud.sharedInstance().login {
    ParticleCloud.sharedInstance().getDevices {
        for device in devices {
            if (device.name == "photon") {
                device.refresh {
                    //here you will have variables and functions
                }
            }
        }
    }
}

```

We do not cache (at least for now) variables and functions, so to use them we need to reach out to device. If that would happen as part of `getDevices()`, we would waste too much data for cellular devices. Hope this helps!

---

<div class="post-metadata">

**Author:** ![as51p](https://avatars.discourse-cdn.com/v4/letter/a/9d8465/32.png) [@as51p](https://community.particle.io/u/as51p)\
**Post date:** [October 17, 2019, 7:50pm UTC](https://community.particle.io/t/ios-api-calls-do-not-expose-particle-cloud-variables-or-functions/52759/10 "2019-10-17T19:50:30Z")

</div>

Great catch! It makes a lot of sense now. Thank you very much.
