Curl in FMP21 & square

Hello, new here. Hoping someone can help. I am attempting to use insert from URL script step to connect to Square's API. I've tested within the Square API Sandbox and the following seems to work okay, but when attempting to access from FMP 21, I get a "?* Line, Column 1, Syntax error: value, object or array expected. Here's my config:

Environment: Mac OS, FMP 21,
I put the following into the 'Specify Curl Options' in the Insert from URL options

" -X POST
-H Square-Version: 2024-12-18
-H Authorization: Bearer " & $accesskey & "
-H Content-Type: application/json
-d @$JSONData"

$JSONData is standard, I think:

{
"company_name" : "BigPlans",
"email_address" : "helmut@schmidlap.com",
"family_name" : "Helmut",
"given_name" : "Schmidlap",
"idempotency_key" : "012348768"
}

I've set the url for the site (Square's sandbox to: "https://connect.squareupsandbox.com/v2/payments" as a variable which VAR I put into the 'Specify URL' option dialog for the Insert from URL script Step.

But, I keep getting syntax error in line 1 column 1 when the script is executed.

I think the options should be enclosed in quotation marks.

" -X POST -H "Square-Version: 2024-12-18" -H "Authorization: Bearer " & $accesskey & "" -H Content-Type: "application/json" -d "& Quote($JSONData)

(Please add the escape characters)

Jan

2 Likes

I'm not sure I've it the way you suggested, here's what I put for the Curl option:

" -X POST -H "Square-Version: 2024-12-18" -H "Authorization: Bearer " & $accesskey & " -H Content-Type: "application/json" -d @$JSONData"

But, I get the same error.

I tried this version as well:

" -X POST -H "Square-Version: 2024-12-18" -H "Authorization: Bearer " & $accesskey & "" -H Content-Type: "application/json" -d " & Quote($JSONData)

Please use the FileMaker JSON functions to generate the JSON to ensure that your JSON has the correct syntax.

Jan

Hi @vidkid98

Here's a simple test file. You'll notice a few differences from what you are doing:

  1. using JSON functions to ensure we create proper JSON

  1. Headers are given using single-quoted values with " \" line continuation characters, like this:

When I run this test, I get a 1627 Authentication Failed error which I think means the syntax is correct.

Here's the file:

curltest2.fmp12.zip (147.2 KB)

(username: admin no password)

2 Likes

Try wrapping each header line in escape quotes.

-H \”Authorization: Bearer “ & $token & “\”
-H \”Content-Type: application/json\”
etc

Sometimes I’ve had trouble with the shorthand for data. So instead of “-d” try “—data”
Your “-X POST” line looks right

Sometimes the api needs the double quotes. I don’t know why, but I’ve seen this with a few others.

1 Like