POST New Record using Temper

Hi,

I’m trying to POST a new record to one FileMaker Database using Temper. I successfully follow the webinar and I can get records from database and insert them into one ListBox.

Now I need to post a new record from the information of some text field and I really don’t know the steps to do it correctly.

I’m looking for an example of this kind of http request or the indications to do it.

Thank you.

This is the request I need:

curl -X "POST" "http://127.0.0.1:8080" \
     -H 'Content-Type: application/json' \
     -d $'{
  "Layout": "Store Details",
  "Action": "InsertRecord",
  "Fields": {
    "Store Name": "Test",
    "Street 1": "100 Test Avenue",
    "City": "Columbus",
    "State": "OH"
  },
  "Host": "localhost",
  "Account": "xfm",
  "Protocol": "http",
  "Password": "latte",
  "Database": "starbucks-us"
}'

what does Temper do?

Temper is a Web API for hosted FileMaker databases. With Temper, you can make API calls to create, read, update, and delete records, run scripts, work with containers, and more.

@Tim_Dietrich wrote Temper so maybe he’ll be able to help you.

Something like this:

Dim sock As New URLConnection
sock.SetRequestContent(theJsonString, "application/json")
sock.Send("POST", "http://127.0.0.1:8080")
1 Like

Thank you.

I will try it.

Trying to replicate the request

curl -X "POST" "http://127.0.0.1:8080" \
     -H 'Content-Type: application/json' \
     -d $'{
  "Layout": "Store Details",
  "Action": "InsertRecord",
  "Fields": {
    "Store Name": "Test",
    "Street 1": "100 Test Avenue",
    "City": "Columbus",
    "State": "OH"
  },
  "Host": "localhost",
  "Account": "xfm",
  "Protocol": "http",
  "Password": "latte",
  "Database": "starbucks-us"
}'

I’m using the following code:

    Var sock As New URLConnection

    // Set up the POST values to send to the Temper API using a Dictionary
    Var postInfo As New Xojo.Core.Dictionary
    postInfo.Value("Host") = "host"
    postInfo.Value("Protocol") = "https"
    postInfo.Value("Database") = "database"
    postInfo.Value("Account") = "username"
    postInfo.Value("Password") = "password"
    postInfo.Value("Layout") = "layout"
    postInfo.Value("Action") = "InsertRecord"

    // Set the sort for the data so we can request it in chunks if necessary
    Dim sortField1 As New Xojo.Core.Dictionary
    sortField1.Value("Store Name") = "Test"
    sortField1.Value("Stree 1") = "100 Test Avenue"

    Dim Fields() As Xojo.Core.Dictionary
    Fields.Append(sortField1)

    postInfo.Value("Fields") = Fields

    // Convert the Dictionary to JSON text
    Dim json As Text
    json = Xojo.Data.GenerateJSON(postInfo)

    // Add the POST data to the RequestContent and send the POST request
    sock.SetRequestContent(json, "application/x-www-form-urlencoded")
    sock.Send("POST", "http://127.0.0.1:8080")

The json is a little different than request I need to post. I need to remove the “[” from the second dictionary (Fields) in order get the post working fine.

I think that the second dictionary is not the correct way to code . Any idea how can I remove it? This is the JSON

{
   "Account":"username",
   "Action":"InsertRecord",
   "Database":"database",
   "Fields":[
      {
         "Store Name":"Test"
         ....
      }
   ],
   "Host":"host",
   "Layout":"layout",
   "Password":"password",
   "Protocol":"https"
}

Removing this fix the issue:

Dim Fields() As Xojo.Core.Dictionary
    Fields.Append(sortField1)