For “API integration test”, “Insert Text” is recommended

Hello.
I am Teruhiro Komaki of frudens Inc.

Insert From URL has been greatly improved than FileMaker 16.
The point that you can now use the cURL options is very big.

There seems to be many people who do not know, but even version 15 you could use httpspost etc.

https://www.filemaker.com/help/15/fmp/en/#page/FMP_Help%2Finsert-from-url.html

Insert From URL supports http, https, httppost, httpspost, ftp, ftps, and file protocols. FileMaker Pro downloads the resource that is specified by the URL to the target field.

However, when collaborating with external service, there are many things that can not be done with the default function, and I was executing the cURL command using BaseElements plugin.

https://baseelementsplugin.zendesk.com/hc/en-us/articles/203843738-BE-HTTP-POST

BE_HTTP_POST ( url ; parameters { ; username ; password } )

Does a http POST function and returns the results. This uses the curl library so output will be similar to that. This is used in conjunction with the BE_HTTP_Set_Custom_Header function to set custom headers in advance and the BE_HTTP_Response_Code and BE_HTTP_Response_Headers functions to get the result values after the POST is complete.

Take back the story.

When doing API integration, I write variously in the cURL option, but there are a few troublesome cases to write with the FileMaker calculation formula.

Dropbox upload etc.

For example, if you use upload with Dropbox API, you specify path as follows, but path It is tough to write.

https://www.dropbox.com/developers/documentation/http/documentation#files-upload

curl -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer token" \
    --header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @local_file.txt

When upload option is described by calculation formula

Let ( [
	~a = "curl -X POST" ;
	~b = "--header \"Authorization: Bearer __TOKEN__\"" ;
	~c = "--header \"Dropbox-API-Arg: {\\\"path\\\": \\\"__PATH__\\\",\\\"mode\\\": \\\"add\\\",\\\"autorename\\\": true,\\\"mute\\\": false}\"" ;
	~d = "--header \"Content-Type: application/octet-stream\"" ;
	~e = "--data-binary @$data" ;
	~list = List ( ~a ; ~b ; ~c ; ~d ; ~e ) ;
	~value = Substitute ( ~list ; [ "¶" ; " " ] ; [ "__TOKEN__" ; z_dropboxToken ] ; [ "__PATH__" ; path ] )
] ;
	~value
) /*let*/

and

Let ( [
	~list =
		List (
			"curl -X POST" ;
			"--header \"Authorization: Bearer __TOKEN__\"" ;
			"--header \"Dropbox-API-Arg: {\\\"path\\\": \\\"__PATH__\\\",\\\"mode\\\": \\\"add\\\",\\\"autorename\\\": true,\\\"mute\\\": false}\"" ;
			"--header \"Content-Type: application/octet-stream\"" ;
			"--data-binary @$data"
		) ;
	~value = Substitute ( ~list ; [ "¶" ; " " ] ; [ "__TOKEN__" ; z_dropboxToken ] ; [ "__PATH__" ; path ] )
] ;
	~value
) /*let*/

It must be written like.

Pick up upload path

Picking up only the above path will result in the following.

"--header \"Dropbox-API-Arg: {\\\"path\\\": \\\"__PATH__\\\",\\\"mode\\\": \\\"add\\\",\\\"autorename\\\": true,\\\"mute\\\": false}\""

Escape and so on are pretty tough.

Of course, I think that it is good to create a custom function after the test, but if you make a mistake in writing the API when testing, it will be inefficient.

Use “Insert Text” when testing API

Therefore, when testing the API, I think that it is better to write using Insert Text instead of calculating it by calculation.

filemaker-api-test-insert-text2-fs8

In the case of Insert Text, it is very convenient because you can set the raw text as a variable.

If the API test goes well, then it is better to define it with a custom function etc.

How about using the value of the field

The same thing can be done by using the value of the field, but since I have to be conscious of the context, I think that Insert Text personally is good.

An editor recommends when writing complicated calculation formulas

To write complicated formulas, we recommend editors.
Since it is hard to see it as a simple editor, I am setting it to highlight FileMaker’s code.

filemaker-api-test-insert-text3-fs8

It is easier to identify, because it makes it easier to see the color.
Using an editor makes it easy to find mistakes.

You can download from GitHub.

CotEditor

https://github.com/frudens/filemaker-syntax-coteditor

Sublime Text

https://github.com/frudens/filemaker-syntax

TextMate

https://github.com/frudens/filemaker-syntax-textmate

Vim

in preparation.

Afterword

Since I have talked about API integration with FileMaker Conference (Japan), I will write about API integration articles and related articles so please look forward to it.

I am a Japanese developer. (I am studying English.) I met the FileMaker Platform at the company I worked at the time. Develop a custom App as an in-house developer. Acting as freelance from 2014 and establishing frudens Inc. in 2016. Recently, I use 'Insert From URL'. I enjoy FileMaker and various services in Integration!

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.