AnsweredAssumed Answered

Insert From URL doesn’t return data on error

Question asked by mdenyse on Jul 4, 2018
Latest reply on Jul 20, 2018 by TSGal

When I call the Data API from a FileMaker script, and (on purpose) pass a bad username/password combination, Insert From URL returns no data and Get(LastError) returns 1627. However, the Data API is returning data indicating what went wrong but there’s no way to get at it, except to use the —trace option and then muddle your way through, looking for:

 

<= Recv data, 110 bytes (0x6e)
0000: {"messages":[{"code":"212","message":"Invalid user account and/o
0040: r password; please try again"}],"response":{}}

 

Am I missing a secret curl options switch to have Insert From URL return the data portion when there’s an error?

 

Using PHP I have no problem getting the data so I know if it’s an authentication issue, an invalid token, etc.

 

I haven’t tried this with other services, but I suspect Insert From URL would do the same thing, in that it’s not purposely ignoring data only from the Data API.

 

Has anyone else found a workaround for this bug? I’d rather not have to parse the trace output if I don’t have to. This needs to be native FileMaker so using a plugin like MBS or BE isn’t a choice.

 

To test this yourself, here’s a script to reproduce:

 

# 
Set Error Capture [ On ]
# 
Set Variable [ $url ; Value: "https://" & "YOUR-HOST-NAME" & "/fmi/data/v1/databases/" & "YOUR-DATABASE" & "/sessions" ] 
# 
#  Note:  ‘Authorization: Basic’ digest is properly formatted (but with a un/pw that doesn't exist)
Set Variable [ $options ; Value: "--show-error --dump-header $$curl.HTTPHeader --trace-ascii $$curl.HTTPTrace --no-trace-time --request POST --data \"[]\" --header \"Content-Type: application/json\" --header \"Authorization: Basic QkFELVVTRVJOQU1FOkJBRC1QQVNTV09SRA==\"" ] 
# 
Insert from URL [ Select ; With dialog: Off ; $$curl.Data ; $url ; cURL options: $options ] 
# 
Set Variable [ $$curl.Code ; Value: Let($$curl.Message = Get(LastExternalErrorDetail) ; Get(LastError)) ] 
#

After running the script, look at $$curl.HTTPTrace and you’ll see the data is being returned from the Data API.

Outcomes