# node-sugarcrm-client

> SugarCRM REST API Client in node.js

Latest version **0.9.3** (published 2013-06-06) · BSD license · 0 weekly downloads

## Install

```sh
npm install node-sugarcrm-client
pnpm add node-sugarcrm-client
yarn add node-sugarcrm-client
bun add node-sugarcrm-client
```

Provides the command `sugar`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.3 |
| Published | 2013-06-06 |
| First published | 2013-06-06 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jean-Charles Nadé |
| Maintainers | jcnade |
| Keywords | sugarcrm,  |

## Links

- npm: https://www.npmjs.com/package/node-sugarcrm-client
- Repository: https://github.com/jcnade/node-sugarcrm-client
- npm.io page: https://npm.io/package/node-sugarcrm-client

## Dependencies (1)

- [request](https://npm.io/package/request.md) *

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 0.9.3 (latest) — 2013-06-06
- 0.9.2 — 2013-06-06
- 0.9.1 — 2013-06-06
- 0.9.0 — 2013-06-06

## README

node-sugarcrm-client
====================

SugarCRM REST API Client in node.js 

[![Build Status](https://travis-ci.org/jcnade/node-sugarcrm-client.png)](https://travis-ci.org/jcnade/node-sugarcrm-client)


* Tested on SugarCRM Community Edition 6.5.* on RESP API v4.1


Provide URL, login and password:

     var sugar = require('node-sugarcrm-client');
     sugar.init(
        {
            apiURL:  "http://*********/sugarcrm/service/v4_1/rest.php"
           ,login:   "*******"
           ,passwd:  "*******"
        }
      );


Config Check:

     console.log(sugar.configInfo());


### Login and get a session ID


    sugar.login(function(sessionID){

        if (sessionID != 'undefined') {

            // If you are here, you got a session ID
            // and you can add all your query here

            console.log('Your session ID is', sessionID);


        } else {
            console.log("can't login, check your credentials");
        }
    });



### Create a new Account


        params = {
                     session:  sessionID
                    ,module_name : "Accounts"
                    ,name_value_list : [
                                        { "name":  "name",  "value": "Account from Node-SugarCRM-Client" }
                                        ]
                 };
        sugar.call("set_entry", params, function(res,err){
            console.log(res,err)
        });


### Create a new Contact

		params = {
					 session:  sessionID
					,module_name : "Contacts"
					,name_value_list : [
						{ name:'first_name'  , value: 'Daneel'   },
						{ name:'last_name'   , value: 'Olivaw' },

						{ name:'title'  , 		value: 'R.'   },
						{ name:'phone_work'   , value: '555-2368' },
					]

				 };
		sugar.call("set_entry", params, function(res,err){
			console.log(res, err);
		})



###  Create a relationship link from an Account to a contact

You need to know before the account ID and the contacts ID.
Yes, the name 'module_id' is very confusing.

		params = {
					 session:  sessionID
					,module_name : 'Accounts'
					,module_id : "d41ad995-7f68-5238-a054-51af62906e81" // the account ID
					,link_field_name : 'contacts'
					,related_ids : ["b1378306-2d84-6e01-6c4a-51af41058b94"]  // some contacts ID

				 };
		sugar.call("set_relationship", params, function(res,err){
			console.log(res, err);
		})



### Query the Acounts table

This query will give you a dump

        params = {
                     session:  sessionID
                    ,module_name : "Accounts"
                    ,query : ""
                    ,order_by : ''
                    ,offset : '0'
                    ,select_fields : [ 'id' ,'name']
                    ,link_name_to_fields_array : []
                    ,max_results : -1
                    ,deleted : '0'
                    ,Favorites : false

                 };
        sugar.call("get_entry_list", params, function(res,err){

            if (err) {
                console.log(err)
            }
            else {
                console.log(res);
            }

        });



### Create and Update a Documents


        params = {
                    session:  sessionID
                   ,module_name : "Documents"
                   ,name_value_list : [
                                       { "name":  "document_name",	"value": "Document from Node-sugarCRM-Client REST API" },
                                       { "name":  "revision",		"value": "1" },
                                      ]
                 };

        sugar.call("set_entry", params, function(document){

                console.log('Document is',document.id);

                // Note
                params = {
                           session:  sessionID
                           ,note : {
                                      id: document.id
                                     ,file : new Buffer("This text come from the REST API").toString('base64')
                                     ,filename : 'note.txt'
                                     ,revision : '1'
                            }
                         };
                sugar.call("set_document_revision", params, function(res){
                    console.log(res);
                });
        });


### Create a relationship link from an Documents to an account

		params = {
					 session:  sessionID
					,module_name : 'Documents'
					,module_id : "286832e1-e3a7-1384-a884-51af487d6b16" // document ID
					,link_field_name : 'accounts'
					,related_ids : ["d41ad995-7f68-5238-a054-51af62906e81"] // Some account IDs
				 };

		sugar.call("set_relationship", params, function(res,err){
			console.log(res, err);
		})

---
_Source: https://npm.io/package/node-sugarcrm-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
