Data Service
The Data Service allows you to Add, Update, Query and Load Database records.
In the SDK you get access to the data service functions by including the file “DataService.php” in your code. Below is a list of the functions, their return values and the arguments they accept.
| Function | Description | Return Value | Arguments |
|---|---|---|---|
| dsAdd | Adds a record to Infusionsofts database. | Integer | 2 |
| dsDelete | Deletes a record from Infusionsofts database. | Boolean | 2 |
| dsUpdate | Updates a record in Infusionsofts database. | Integer | 3 |
| dsLoad | Loads a record from Infusionsofts database. | Array | 3 |
| dsFind | Searches a table records field for specific data. | Array | 6 |
| dsQuery | Queries a table for specified field criteria. | Array | 5 |
| authenticateUser | Validates user login credentials. | Integer | 2 |
| addCustomField | Allows for the creation of new custom fields. | Integer | 4 |
| updateCustomField | Updates a custom field. | Boolean | 1 |
| dsGetSetting | Returns Application settings. | String | 2 |
dsAdd( [string] Table Name, [array] Field Data ); |
|
| Top Menu
With dsAdd you can add a new record to a table in the Infusionsoft database. This function takes 2 parameters, the table name(you can find the names in api_field_access.xml) and the associative array with the field names and data that you wish to add to them. Like addCon dsAdd will return the ID of the record it creates. Below we have an example of adding a contact record with this function.
|
dsDelete( [string] Table Name, [int] Record ID ); |
|
| Top Menu
With dsDelete you can delete records from the Infusionsoft database if their access rights permit delete actions.
|
dsUpdate( [string] Table Name, [int] Record ID, [array] Field Data ); |
|
| Top Menu
The dsUpdate function is used to update specified records in Infusionsoft. It accespts 3 arguments, Table Name, ID, and Field Data. If the update was successful it will return the ID of the updated record. Below we have an example of updating a group name.
|
dsLoad( [string] Table Name, [int] Record ID, [array] Return Fields ); |
||
| Top Menu
The dsLoad function is used to return the values of fields in a specific database record. To use this function you just pass a the table name, the records ID and an array of the field names you wish to retrieve. Below is an example of loading data from a contact.
If the function runs without any errors the returned data will look like:
|
dsFind( [string] Table Name, [int] Limit, [int] Page, [String] Search Field, [string] Search Data, [array] Return Fields ); |
||
| Top Menu
The dsFind function is used to find records that have a specific value in a specific field. It will return results to you back in a nested array. Note that the maximum results returned back (limit) is 1000 and that paging is 0 based, meaning page 0 is the first page of [limit] results. Below we have an example of using dsFind to locate all contact records in a specific contact group.
The output of the above code with show the breakdown of the nested array returned by dsFind, the output looks like:
|
dsQuery( [string] Table Name, [int] Limit, [int] Page, [array] Query Data, [array] Return Fields ); |
||
| Top Menu
The dsQuery method allows you to query multiple fields in a table for matching criteria. This method returns results back in a nested array. Note that the maximum amount of results able to be returned by a single query is 1000, you specify this with the limit argument. Also paging is 0 based meaning that page 0 is actually the first page of results. When using dsQuery a % in your data array is treated as a wild card. Below is a sample of a query that pulls up all contacts who’se first name contains “est”.
If the function runs without any errors the returned data will look like:
|
authenticateUser( [String] username, [String] password ); |
|
| Top Menu
With the authenticateUser function you can pass a username and password into Infusionsoft and if it matches the credentials of a user it will return the users ID.
|
addCustomField( [String] context, [String] displayName, [String] dataType, [int] groupId ); |
|
| Top Menu
With the addCustomField function you are able to create custom fields via the API. Parameters:
|
updateCustomField( [Int] customFieldId, [Array] values ); |
|
| Top Menu
The updateCustomField function will allow you to change properties of an existing custom field. The values will be an associative array to define fieldname/value. below is a sample of creating a custom text field and then renaming it with the update
The Available fields are as follows: [Int] GroupId – What Header to place the field in [String] Label – The fields display name [String] DefaultValue – What data should start off in the field [String] Values – Newline seperated string to populate list boxes and drop down lists [Int] – ListRows – The amount of rows visible in a listbox [Int] – UserGroup – The user group the field belongs to |
dsGetSetting( [String] Module, [String] Setting ); |
|
| Top Menu
This function allows you to get application settings out of Infusionsoft. They are usually returned to you in a comma delimited string <br />
|
This concludes the Data Service functions. Happy Coding!