Follow

Custom Tables API examples

We've created a "Demo CT API" custom table with the following fields:
- idItem int (unique, primary key, required)
- ItemName nvarchar (length 50, unique, required)
- ItemPrice decimal
- CreatedOn datetime

The table contains the following dummy data:

idRow

idItem

ItemName

ItemPrice

CreatedOn

1

1001

Item 1001

1001.01

2012-02-05 04:25:00

2

1002

Item 1002

1002.02

2012-08-15 18:31:00

3

1003

Item 1003

1003.03

2012-12-25 08:13:00

4

1004

Item 1004

4.04

2013-01-01 00:00:00

5

1005

Item 1005

5.05

2013-03-21 23:10:00

6

1006

Item 1006

NULL

NULL

7

1007

Item 1007

1007.07

NULL

 

 The CustomTables_List.php file calls the "List" method of the Web service, with a filter that will return all the items with a price above 9.99 and a creation date that is not empty.

List() result:
Success = true
AuthenticationError =
ErrorCode = NoError
ErrorMessage =
NbRowsAffected = 3

idRow = 1
idItem = 1001
ItemName = Item 1001 ItemPrice = 1001,010000
CreatedOn = 2012-02-05 04:25:00

idRow = 2
idItem = 1002
ItemName = Item 1002
ItemPrice = 1002,020000
CreatedOn = 2012-08-15 18:31:00

idRow = 3
idItem = 1003
ItemName = Item 1003
ItemPrice = 1003,030000
CreatedOn = 2012-12-25 08:13:00

 

The CustomTables_Create.php file calls the "Create" method, to add an item with the id 2001.

 

Create() result:

Success = true
AuthenticationError =
ErrorCode = NoError
ErrorMessage =
AffectedRows = 0
ErrorMessage =
idRow = 11

FieldName = idItem
Value = 2001
GotError =

FieldName = ItemName
Value = Item 2001
GotError =

FieldName = ItemPrice
Value = 2001
GotError =

FieldName = CreatedOn
Value = 2013-04-01
GotError =

 

If we refresh CustomTables_List.php, it shows the new item.

 

List() result:
(...)

idRow = 11
idItem = 2001
ItemName = Item 2001
ItemPrice = 2001,010000
CreatedOn = 2013-04-01 00:00:00

 

The CustomTables_Update.php file updates the item with the id 2001 and sets its price to 100.01

 

Update() result:

Success = true
AuthenticationError =
ErrorCode = NoError
ErrorMessage =
NbRowsAffected = 1
ErrorMessage =

 

Confirm the new price by refreshing CustomTables_List.php again.

 

List() result:
(...)
idRow = 11
idItem = 2001
ItemName = Item 2001
ItemPrice = 100,010000
CreatedOn = 2013-04-01 00:00:00

 

The CustomTables_Delete.php file deletes the item with the id 2001, only if it's price is below 999.99.

 

Delete() result:

Success = true
AuthenticationError =
ErrorCode = NoError
ErrorMessage =
NbRowsAffected = 1

 

Confirm that the item is gone by refreshing CustomTables_List.php again.

 

List() result:

Success = true
AuthenticationError =
ErrorCode = NoError
ErrorMessage =
NbRowsAffected = 3

idRow = 1
idItem = 1001
ItemName = Item 1001
ItemPrice = 1001,010000
CreatedOn = 2012-02-05 04:25:00

idRow = 2
idItem = 1002
ItemName = Item 1002
ItemPrice = 1002,020000
CreatedOn = 2012-08-15 18:31:00

idRow = 3
idItem = 1003
ItemName = Item 1003
ItemPrice = 1003,030000
CreatedOn = 2012-12-25 08:13:00

 

A few important things:

- In the samples, prices are declared using a comma (,) as a decimal symbol. 
This is likely due to the configuration of our PHP server.  If you get an "invalid format" error, try using a period (.)
- When declaring field-value pairs, put the value between quotes even if it's a numeric value. (exemple: "FieldName" => "ItemPrice", "Value" => "2001,01")
- Call CustomTables_Create.php when the id 2001 item already exists to see an example of "item already exists" error Success = false AuthenticationError = ErrorCode = SqlError ErrorMessage = Dupe AffectedRows = 0 ErrorMessage = Dupe idRow = 0

 

0 Comments

Please sign in to leave a comment.