REST API PUT example


#1

Can I have a simple example on how to use platform.api.put to update a single record in the db (included SQLite database) service using a where clause. I want to only update only 1 field. Something similar to the below SQL query, just to make it more clear

Update tblExample set name='John Doe' where lastname = 'doe'

How do I achieve the same with a REST API. I guess I’d need to use PUT method.

Thanks,
M.M


How to get the original response
#2

Hi @m_menon,

Try this:

payload = {
  "resource": [
    {
      "name": "John Doe"
    }
  ],
  "filter": "lastname=doe"
};

result = platform.api.put("db/_table/tblExample", payload);

#3

I can’t get the PUT to work. I get 500 error:

“message”: “Failed to update records in ‘Products’.\nFirst key in $update argument is not an update operator”

my request is:

{
"resource": [{
	"filename": "Greg-London/JPMC.CSV",
	"products": {
		"data": [{
			"Details": "CREDIT",
			"Posting Date": "6/13/2016",
			"Description": "BTQ DEPOSIT",
			"Amount": "886.07",
			"Type": "MISC_CREDIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "6/8/2016",
			"Description": "DEPOSIT  ID NUMBER 298979",
			"Amount": "1446.28",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "6/6/2016",
			"Description": "DEPOSIT  ID NUMBER 998146",
			"Amount": "1609.51",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "6/6/2016",
			"Description": "DEPOSIT  ID NUMBER 298929",
			"Amount": "1215.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "6/3/2016",
			"Description": "REMOTE ONLINE DEPOSIT #          1",
			"Amount": "250.00",
			"Type": "CHECK_DEPOSIT",
			"Check or Slip #": "1",
			"": ""
		}, {
			"Details": "CREDIT",
			"Posting Date": "6/2/2016",
			"Description": "ODP TRANSFER FROM SAVINGS 000003357125680",
			"Amount": "250.00",
			"Type": "MISC_CREDIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "6/1/2016",
			"Description": "REMOTE ONLINE DEPOSIT #          1",
			"Amount": "600.00",
			"Type": "CHECK_DEPOSIT",
			"Check or Slip #": "1",
			"": ""
		}, {
			"Details": "CREDIT",
			"Posting Date": "5/31/2016",
			"Description": "ODP TRANSFER FROM SAVINGS 000003357125680",
			"Amount": "250.00",
			"Type": "MISC_CREDIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/26/2016",
			"Description": "DEPOSIT  ID NUMBER 298591",
			"Amount": "200.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "CREDIT",
			"Posting Date": "5/25/2016",
			"Description": "ODP TRANSFER FROM SAVINGS 000003357125680",
			"Amount": "200.00",
			"Type": "MISC_CREDIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/23/2016",
			"Description": "DEPOSIT  ID NUMBER 298513",
			"Amount": "250.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/19/2016",
			"Description": "DEPOSIT  ID NUMBER 298162",
			"Amount": "854.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "CREDIT",
			"Posting Date": "5/18/2016",
			"Description": "ODP TRANSFER FROM SAVINGS 000003357125680",
			"Amount": "100.00",
			"Type": "MISC_CREDIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/17/2016",
			"Description": "REMOTE ONLINE DEPOSIT #          1",
			"Amount": "400.00",
			"Type": "CHECK_DEPOSIT",
			"Check or Slip #": "1",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/16/2016",
			"Description": "DEPOSIT  ID NUMBER 998303",
			"Amount": "1913.51",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/16/2016",
			"Description": "DEPOSIT  ID NUMBER 998305",
			"Amount": "290.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/16/2016",
			"Description": "DEPOSIT  ID NUMBER 998304",
			"Amount": "120.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/13/2016",
			"Description": "REMOTE ONLINE DEPOSIT #          1",
			"Amount": "1500.00",
			"Type": "CHECK_DEPOSIT",
			"Check or Slip #": "1",
			"": ""
		}, {
			"Details": "CREDIT",
			"Posting Date": "5/10/2016",
			"Description": "ODP TRANSFER FROM SAVINGS 000003357125680",
			"Amount": "750.00",
			"Type": "MISC_CREDIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/9/2016",
			"Description": "DEPOSIT  ID NUMBER 848056",
			"Amount": "2055.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "CREDIT",
			"Posting Date": "5/6/2016",
			"Description": "ODP TRANSFER FROM SAVINGS 000003357125680",
			"Amount": "100.00",
			"Type": "MISC_CREDIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/5/2016",
			"Description": "DEPOSIT  ID NUMBER 833671",
			"Amount": "100.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/5/2016",
			"Description": "DEPOSIT  ID NUMBER 833670",
			"Amount": "20.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/3/2016",
			"Description": "DEPOSIT  ID NUMBER 833931",
			"Amount": "400.00",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/3/2016",
			"Description": "DEPOSIT  ID NUMBER 833930",
			"Amount": "223.96",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": "DSLIP",
			"Posting Date": "5/2/2016",
			"Description": "DEPOSIT  ID NUMBER 833883",
			"Amount": "1117.14",
			"Type": "DEPOSIT",
			"Check or Slip #": "",
			"": ""
		}, {
			"Details": ""
		}],
		"errors": [{
			"type": "FieldMismatch",
			"code": "TooFewFields",
			"message": "Too few fields: expected 7 fields but parsed 1",
			"row": 26
		}],
		"meta": {
			"delimiter": ",",
			"linebreak": "\r\n",
			"aborted": false,
			"truncated": false,
			"cursor": 1851,
			"fields": ["Details", "Posting Date", "Description", "Amount", "Type", "Check or Slip #", ""]
		}
	},
	"processed": "F",
	"date": "2016-07-24T15:43:24.118Z"
}],
"filter": "filename=Greg-London/JPMC.CSV"

}

Anything obvious?