# Contacts API

**URL:** <https://forums.fusetools.com/t/contacts-api/4480>\
**Category:** Feature Suggestions\
**Created:** [April 12, 2016, 9:56am UTC](https://forums.fusetools.com/t/contacts-api/4480 "2016-04-12T09:56:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [April 12, 2016, 9:56am UTC](https://forums.fusetools.com/t/contacts-api/4480/1 "2016-04-12T09:56:53Z")

</div>

It’d be really awesome to have a Contacts API, for the app I’m working on I want to do something like SnapChat does with Contacts, where you can add someone by your Contacts list.

So an example API I have in mind **(Naively proposing I’m not sure what’s allowed on each OS when it comes to messing with Contacts, perhaps a read only api is possible)**:

### Reading Contacts

```auto
var contacts = require('FuseJS/Contacts');

contacts.getAll().then(function(contactsArr) {
  // where contactsArr is an Array of contact objects
});

contacts.searchByName('edwin').then(function(contactsArr) {
  // where contactsArr is an Array of contact objects with the either firstName or lastName including the string edwin (fuzzysearched)
});

contacts.searchByFirstName('edwin').then(function(contactsArr) {
  // where contactsArr is an Array of contact objects with only the firstName including the string edwin (fuzzysearched)
});

contacts.searchByLastName('reynoso').then(function(contactsArr) {
  // where contactsArr is an Array of contact objects with only the lastName including the string reynoso (fuzzysearched)
});

contacts.searchByNumber('347').then(function(contactsArr) {
  // where contactsArr is an Array of contact objects with their number including the number 347
});

contacts.search({ field: 'FirstName', query: 'edwin' }).then(function(contactsArr) {
  // returns same thing as searchByFirstName, however search method takes an object which specifies the field and what to query
});

```

### Writing Contacts

```auto
contacts.createNewContact({
  firstName: 'Edwin',
  lastName: 'Reynoso',
  number: '347 ... ....'
  ... // etc
});

contacts.update(contactObject, {
  // values to update
});

contacts.updateAll([...contactObjects], {
  // values to update
});

```

Or just pass an Array of Contact Objects to the `update` method, however I think its a bad idea to even be able to update a bunch of contacts like so

### Contact Object

```auto
var contact = contactsArr[0];

contact.fullName; // 'Edwin Reynoso'
contact.firstName; // 'Edwin'
contact.lastName; // 'Reynoso'
contact.number; // '347 ... ....'

// or use methods?
contact.getFullName(); // 'Edwin Reynoso'
contact.getFirstName(); // 'Edwin'
contact.getLastName(); // 'Reynoso'
contact.getNumber(); // '347 ... ....'

contact.get('FirstName'); // 'Edwin'

```

The only reason for using methods or getters would be for not having to read each contact right away, so it could asynchronously be done

regarding getters it’d synchrounosly read the attribute of the contact I suppose, yet that may be bad so perhaps the methods could return a promise:

```auto
contact.getFullName().then(function(firstName) {
  // firstName === 'Edwin'
});
...// etc

```

**In all honesty one big read should be enough, and make everything else easier**

Contact Objects could have writing methods?:

```auto
contact.update({
  // values to update
});

```

---

<div class="post-metadata">

**Author:** ![Anders\_Bondehagen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_bondehagen/32/98_2.png) [@Anders\_Bondehagen](https://forums.fusetools.com/u/Anders_Bondehagen)\
**Post date:** [April 12, 2016, 2:54pm UTC](https://forums.fusetools.com/t/contacts-api/4480/2 "2016-04-12T14:54:18Z")

</div>

We don’t have contacts on the priority list right now. But hopefully someone in the community can help you make this. It should be very simple with foreign code.

---

<div class="post-metadata">

**Author:** ![Bjorn-Olav\_Strand](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/bjorn-olav_strand/32/583_2.png) [@Bjorn-Olav\_Strand](https://forums.fusetools.com/u/Bjorn-Olav_Strand)\
**Post date:** [April 14, 2016, 8:41am UTC](https://forums.fusetools.com/t/contacts-api/4480/3 "2016-04-14T08:41:57Z")

</div>

Here is a skeleton of an API that you could use to implement the things you are requesting.

[https://github.com/bolav/fuse-contacts](https://github.com/bolav/fuse-contacts)

---

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [April 14, 2016, 7:05pm UTC](https://forums.fusetools.com/t/contacts-api/4480/4 "2016-04-14T19:05:30Z")

</div>

@Bolav thanks, but sadly I don’t understand the majority of that uno code to expand it. I haven’t tested this code yet, so thanks for the `contacts.getAll()` method I’ll have to try it out soon

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [September 22, 2016, 8:53am UTC](https://forums.fusetools.com/t/contacts-api/4480/5 "2016-09-22T08:53:14Z")

</div>

Heads up! The Contacts module has been fixed and improved a little: [https://github.com/bolav/fuse-contacts](https://github.com/bolav/fuse-contacts)

On Android, it now returns only those contacts you’ve entered in Address Book (as opposed to random entries from all connected accounts on device) and calls the Permission request correctly (thanks to Fuse team!).

On both platforms, a new `getPage()` function has been implemented to provide a way to work around memory consumption with big contact lists.

---

<div class="post-metadata">

**Author:** ![Michael](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/michael/32/121_2.png) [@Michael](https://forums.fusetools.com/u/Michael)\
**Post date:** [October 19, 2016, 2:54pm UTC](https://forums.fusetools.com/t/contacts-api/4480/6 "2016-10-19T14:54:02Z")

</div>

Hi guys,

I am having massive issues with this contacts uno code. It is all implemented and it will work the first time I open the app… but the second time I open the app (or the page reloads) - it will fail with an error that “authorise” is not a function…

After a bit of investigation it looks like the permissions code is crashing - I have a feeling that Android might be rejecting multiple requests to the permission, even after its approved.

Thanks  
Michael

---

<div class="post-metadata">

**Author:** ![Tobias\_Gorgs](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@Tobias\_Gorgs](https://forums.fusetools.com/u/Tobias_Gorgs)\
**Post date:** [January 26, 2018, 7:53pm UTC](https://forums.fusetools.com/t/contacts-api/4480/7 "2018-01-26T19:53:07Z")

</div>

Hey guys,

I tried to get the fuse-contacts module to work, but when I try to call the authorize() function after require(“Contacts”) I get the following error …

[Viewport]: Error: TypeError: contacts.authorize is not a function: Name: TypeError: contacts.authorize is not a function  
Error message: Uncaught TypeError: contacts.authorize is not a function  
…  
JS stack trace: TypeError: contacts.authorize is not a function  
at Object.\_tempMethod (MainView.ux:20:23)  
in Fuse.Scripting.DiagnosticSubjectMainView.ux:20

I’m relatively new to Fuse, so maybe I’m missing something. But I followed all the steps in the README. Installed it via fusepm (the unoproj file is adapted automatically), did a whole bunch of restarts of the preview tool, etc.

Who can help?

Thanks,  
Tobi

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [January 29, 2018, 2:06pm UTC](https://forums.fusetools.com/t/contacts-api/4480/8 "2018-01-29T14:06:41Z")

</div>

Debugged a little and solved the issue by removing `<Contacts ux:Global="Contacts" />` from UX code.

Since a good while now, Uno classes can be instantiated directly in JavaScript, and you don’t need to include them in UX the old way. Just do `var contacts = require('Contacts');` in your JS and you should be all set.

---

<div class="post-metadata">

**Author:** ![Tobias\_Gorgs](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@Tobias\_Gorgs](https://forums.fusetools.com/u/Tobias_Gorgs)\
**Post date:** [February 19, 2018, 8:09pm UTC](https://forums.fusetools.com/t/contacts-api/4480/9 "2018-02-19T20:09:11Z")

</div>

Hey Uldis,

thanks for your quick response. Your reply helped me to get the module working. Thanks also to Bolav for providing it.

Cheere, Tobi

---

<div class="post-metadata">

**Author:** ![dolsom](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@dolsom](https://forums.fusetools.com/u/dolsom)\
**Post date:** [November 16, 2018, 3:00pm UTC](https://forums.fusetools.com/t/contacts-api/4480/10 "2018-11-16T15:00:50Z")

</div>

This solution not running anymore.

---

<div class="post-metadata">

**Author:** ![aeq](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/aeq/32/129_2.png) [@aeq](https://forums.fusetools.com/u/aeq)\
**Post date:** [November 16, 2018, 9:27pm UTC](https://forums.fusetools.com/t/contacts-api/4480/11 "2018-11-16T21:27:57Z")

</div>

I fixed the dependencies and permission issue, Android & iOS works! ~ [https://github.com/rbtech/fuse-contacts](https://github.com/rbtech/fuse-contacts)

---

<div class="post-metadata">

**Author:** ![MVONDO\_Yannick](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/mvondo_yannick/32/214_2.png) [@MVONDO\_Yannick](https://forums.fusetools.com/u/MVONDO_Yannick)\
**Post date:** [September 28, 2021, 5:22pm UTC](https://forums.fusetools.com/t/contacts-api/4480/12 "2021-09-28T17:22:15Z")

</div>

Hi,  
this repo can be used with actual version of fuse?

> **[GitHub - rbtech/fuse-contacts: Fuse Contacts](https://github.com/rbtech/fuse-contacts)**
>
> Fuse Contacts. Contribute to rbtech/fuse-contacts development by creating an account on GitHub.

thanks

---

<div class="post-metadata">

**Author:** ![bezjosh99](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@bezjosh99](https://forums.fusetools.com/u/bezjosh99)\
**Post date:** [November 15, 2021, 7:36am UTC](https://forums.fusetools.com/t/contacts-api/4480/13 "2021-11-15T07:36:36Z")

</div>

this post is really helpful for me, thank you for sharing your comments with us

---

<div class="post-metadata">

**Author:** ![bezjosh99](https://avatars.discourse-cdn.com/v4/letter/b/4da419/32.png) [@bezjosh99](https://forums.fusetools.com/u/bezjosh99)\
**Post date:** [December 15, 2021, 10:37am UTC](https://forums.fusetools.com/t/contacts-api/4480/14 "2021-12-15T10:37:53Z")

</div>

thank you for sharing your comments with us[.](https://get-vidmateapp.com)[.](https://get-mobdroapk.com)
