11 Replies Latest reply on Jul 23, 2017 4:22 AM by RALees

    Insert From URL cURL Options Data Issues

    alecgregory

      I am having various issues including data in the cURL Options of Insert From URL. It seems that the data is not being sent at all or being sent incorrectly. The example below uses the FileMaker Data Api as this should be something that others can test.

       

      I am able to successfully obtain a token using Insert From URL using the following options:

       

      -X POST -H "Content-Type: application/json" -d {"layout":"Transaction","password":"<password>","user":"<username>"}

       

      I then attempt a PUT request with Insert From URL to update a record by setting the following cURL options:

       

      Let (

           $data =

                JSONSetElement (

                     "";

                     "data";

                     JSONSetElement (

                          "";

                          "Title";

                          "Artwork - Updated By The REST API";

                          JSONString

                     );

                     JSONObject

                );

           "-X PUT"

                & " -H \"Content-Type: application/json\""

                & " -H \"FM-Data-token: "

                & $token

                & "\""

                & " -d @$data"

      )

       

      When running the request using Insert From URL the response is:

       

      {"errorMessage":"Data is missing.","errorCode":"10"}

       

      The response header is:

       

      HTTP/1.1 415 Unsupported Media Type

      Date: Thu, 06 Apr 2017 14:28:01 GMT

      Server: Apache/2.4.25 (Unix) LibreSSL/2.2.7

      Content-Type: application/json; charset=utf-8

      Content-Length: 41

      ETag: W/"29-4JiBp9g8zSbEXaQYl2hHsg"

      Vary: Accept-EncodingX-Frame-Options: SAMEORIGIN

      X-XSS-Protection: 1; mode=block

      X-Content-Type-Options: nosniff

       

      When running the PUT request using the BaseElements function BE_HTTP_PUT_DATA and using the JSON

       

      {"data":{"Title":"Artwork - Updated By The REST API"}}

       

      as the data parameter the request works as expected: I get the JSON response "OK" and the record is updated. With BaseElements the options and headers are set using a separate function so they aren't passed in the data parameter.

       

      I've tried formatting the data in all the ways suggested in the JSON section of the help file. E.g. --data @$data and literals. But nothing seems to work. From the errors it seems like the FileMaker Data API just isn't seeing the data. I've had the same issue with other APIs too.

       

      Has anyone been able to pass data to the FileMaker Data API in the cURL Options of Insert From URL? If so, I'd appreciate it if you could share your method.

        • 1. Re: Insert From URL cURL Options Data Issues
          Ralph_Buechle

          try this:

           

          "-X PUT"

                    & " -H \"Content-Type: application/json\""

                   & " -H \"FM-Data-token: @$token\""

                    & " -d @$data"

          )

           

          normal variables sometimes don't work there, although it is an calculation editing box.

          • 2. Re: Insert From URL cURL Options Data Issues
            psijmons

            This was recently pointed out to me and proved to be a very good tool for testing the FM DATA API

            Postman | Supercharge your API workflow

             

            There is a free version which you can use for single use, teams require a small monthly fee

            • 3. Re: Insert From URL cURL Options Data Issues
              alecgregory

              psijmons wrote:

               

              This was recently pointed out to me and proved to be a very good tool for testing the FM DATA API

              Postman | Supercharge your API workflow

               

              There is a free version which you can use for single use, teams require a small monthly fee

              Thank you. This is a useful tool for general API testing.

               

              It can't directly analyze the Insert From URL script step, but it does allow certain things to be ruled out.

              • 4. Re: Insert From URL cURL Options Data Issues
                psijmons

                Correct, this is  a quote from the FMI manual:

                The FileMaker Data API does NOT support:

                • uploading data into container fields
                • access to data in external ODBC data sources
                • FileMaker plug-ins
                • executing FileMaker scripts
                • activating script triggers

                 

                FileMaker 16 Data API Guide

                1 of 1 people found this helpful
                • 5. Re: Insert From URL cURL Options Data Issues
                  alecgregory

                  Ralph_Buechle wrote:

                   

                  try this:

                   

                  "-X PUT"

                  & " -H \"Content-Type: application/json\""

                  & " -H \"FM-Data-token: @$token\""

                  & " -d @$data"

                  )

                   

                  normal variables sometimes don't work there, although it is an calculation editing box.

                  Thanks for the suggestion. Unfortunately this doesn't help. The result is the same.

                  • 6. Re: Insert From URL cURL Options Data Issues
                    alecgregory

                    psijmons wrote:

                     

                    Correct, this is a quote from the FMI manual:

                    The FileMaker Data API does NOT support:

                    • uploading data into container fields
                    • access to data in external ODBC data sources
                    • FileMaker plug-ins
                    • executing FileMaker scripts
                    • activating script triggers

                     

                    FileMaker 16 Data API Guide

                    Sure, but I'm just dealing with text which is supported supported. Is there a part of this quote relevant to the issue that I'm missing?

                    • 7. Re: Insert From URL cURL Options Data Issues
                      ch0c0halic

                      Try adding these debugging parameters.

                      --show-error

                      --dump-header $$header

                      --trace $$trace

                       

                       

                      --show-error --dump-header $$header --trace $$trace

                       

                      They allow you to see what's happening inside the cURL command. The trace is hard to read because it's a combination of Hex and ASCII. But it seams to contain the complete cURL transaction.

                      3 of 3 people found this helpful
                      • 8. Re: Insert From URL cURL Options Data Issues
                        user19752

                        Your $data doesn't have {"data": part which BE succeeded.

                        1 of 1 people found this helpful
                        • 9. Re: Insert From URL cURL Options Data Issues
                          alecgregory

                          Yeah, I realized that but unfortunately fixing it didn't help. I've edited the original post to make it clear now. I did try with the same literal as with base elements but that didn't work either.

                          • 10. Re: Insert From URL cURL Options Data Issues
                            alecgregory

                            ch0c0halic wrote:

                             

                            Try adding these debugging parameters.

                            --show-error

                            --dump-header $$header

                            --trace $$trace

                             

                             

                            --show-error --dump-header $$header --trace $$trace

                             

                            They allow you to see what's happening inside the cURL command. The trace is hard to read because it's a combination of Hex and ASCII. But it seams to contain the complete cURL transaction.

                            Many thanks for this, it's really helped.

                             

                            From the trace I've worked out that the problem was with the token. I'm not sure why the header was giving me an unsupported media type error.

                             

                            With the correct token I was able to get things working but only after replacing the @$token reference. The @$ notation isn't supported in headers, which is consistent with the documentation.

                             

                            For reference, the final calc in cURLOptions that worked was

                             

                            Let (

                                $data =

                                      JSONSetElement (

                                          "";

                                          "data";

                                          JSONSetElement (

                                                "";

                                                "Title";

                                                "Artwork - Updated By The REST API";

                                                JSONString

                                          );

                                      JSONObject

                                );

                                "-X PUT"

                                      & " -H \"Content-Type: application/json\""

                                      & " -H \"FM-Data-token: "

                                      & Session_Utility::FmDataApiToken & "\""

                                      & " -d @$data"

                            )

                             

                            Thanks to everyone who replied!

                            • 11. Re: Insert From URL cURL Options Data Issues
                              RALees

                              Alec

                               

                              First - Thank you so much for posting this information! I think this is the only explicitly described example of cURL options pertaining to the FM Data API that exists!

                               

                              Second - Since you provided an example of a valid cURL that you used to obtain a token, I was able to debug my own issue.

                              It seems the function 'JSONFormatElements' corrupts the JSON and causes all methods that communicate to the FM Data API to fail. (Days of my life I will never get back but I thank you for ending the pain!)

                               

                              Third - So now I can POST to Authenticate and get a token, I can GET data, but POSTing actual data remains a problem for me.

                               

                              Using the new native methods to POST data I get a "Value in field failed calculation test of validation entry option","errorCode":"507"

                               

                              Using Goya's Base Elements I get "500 : Field not found error"

                               

                              Any response would be deeply appreciated!