Getting INSERT FROM URL To parse JSON Data?

As I find is often the case, getting a complex request to work is often very simple in POSTMAN and even a programming language found in .NET, but getting it to work in FileMaker can be quite time consuming.

Below is some JSON I want to pass to a POST Request using "--data $jsonData" The JSON is below, but regardless of what I try (hour after hour ... in FileMaker), I keep getting parse errors.

{"detail":"Failed to parse request body as JSON: unexpected EOF","status":400}

FileMaker set variable statement value below:

json parse

(I had to upload an image above so I didn't need to further refine my JSON so FMSOUP would show all the data.)

Can anyone see what I need to do to make FileMaker happy? I tried copying the working CURL from POSTMAN also and quoting that, but FileMaker won't work with that either.

Thanks in advance,

Is there a reason not to use JSONSetElements? is the order of the keys important?
If not, try:

JSONSetElement ( ""
; [ "version" ; "<version_info_here>" ; jsonstring ]
; [ "input" ; jsonsetelement ( "" ; "text" ; "TEST" ; jsonstring ) ; jsonobject ]
; [ "webhook" ; "<webhook_url_here>" ; jsonstring ]
; [ "webhook_events_filter[0]" ; "start" ; jsonstring ]
; [ "webhook_events_filter[1]" ; "output" ; jsonstring ]
; [ "webhook_events_filter[2]" ; "logs" ; jsonstring ]
; [ "webhook_events_filter[3]" ; "completed" ; jsonstring ]
)
5 Likes

Brilliant, thank you! It works!!! :slight_smile:

1 Like

Hey @FabriceN,

I noticed if I add a second word to the "text" entry using your JSONSetElement example, I again get the could not parse error: {"detail":"Failed to parse request body as JSON: unexpected EOF","status":400}

image

If I just used a single word like "write", it works.

I tried different JSONSetElement options like "{}" and JSONString, etc., but none worked. Do you see what's missing now?

(Adding words works as before in POSTMAN CURL and Python.)

Thanks again.

Sorry, no idea.

Hi @OliverBarrett ,

A couple of thoughts:

  1. If you happened to be including a Content-Length header in the specified "cURL options" of the Insert From URL script step, then modifying the content size without updating the value specified by such a header could play out as you are seeing, especially if the actual content size exceeds what the header is indicating.

  2. Please feel free to post a screenshot of the FileMaker script steps and the supporting calculations. Having more eyes on it could help.

Hope this might help.

2 Likes

I am curious, is there a reason not to use this calculation?

JSONSetElement ( ""
; [ "version" ; "<version_info_here>" ; jsonstring ]
; [ "input.text" ;  "TEST" ; jsonstring ]
; [ "webhook" ; "<webhook_url_here>" ; jsonstring ]
; [ "webhook_events_filter[0]" ; "start" ; jsonstring ]
; [ "webhook_events_filter[1]" ; "output" ; jsonstring ]
; [ "webhook_events_filter[2]" ; "logs" ; jsonstring ]
; [ "webhook_events_filter[3]" ; "completed" ; jsonstring ]
)

which seems simpler

3 Likes

Both produce seemingly valid JSON, but neither works in FileMaker.

{"detail":"Failed to parse request body as JSON: unexpected EOF","status":400}

The IFURL has:

"--data " & $jsonData

The header top lines of CURL Options are:

"--X POST " &
"--header "Authorization: <auth_here>"&
"--header "Content-Type: application/json""

In Python where I can easily add raw JSON, this works fine.

In POSTMAN, this works fine.

???

Thanks

Absolutely no reason indeed. But it makes me look more knowledgeable :wink:
Of course you're right.

2 Likes

That's a relief. I had a moment of self doubt where I thought I might have missed something important/significant...

1 Like

Since this could be a bug of some kind, I posted a message on the FileMaker forum about this.

For the moment, we'll not try to do this JSON processing in FileMaker and use an external approach.

I will post back with any updates.

Thanks to all for the great suggestions.

I have found that this works reliably as FileMaker take care of any quoting and escaping...

"-X POST 
-H \"Content-type: application/json\" 
-H \"accept: application/json\" 
-H \"Authorization: <auth_here>\" 
-d @$jsonData"
3 Likes

The problem turned out to be that I didn't use the "@" in the '-d' portion of CURL options. I've never needed the "@" but I am happy to say that I learned something new and useful going forward.

Thanks again to all! :slight_smile:

4 Likes