1 2 3 Previous Next 35 Replies Latest reply on Aug 12, 2017 8:38 AM by holstermedia@gmail.com

    Insert from URL - sub-objects in JSON-data are not passed to Mailchimp-webservice

    Menno

      Product and version FileMaker Advanced 16.0.1

      OS and version MacOSX10.12.5 and Windows 10 Pro x64

      Browser and version (for WebDirect only)

      Hardware Mac, HP

      Description Sub-objects in JSON in data-part in cURL-options for Insert From URL are not passed to the webservice See discussion below

      How to replicate See explanation below

      Workaround use the command line as indicated below

       

       

      I am trying to add subscribers to a mailing-list on mailchimp. The cURL-command to do that is:

      curl --request POST \

      --url 'https://us6.api.mailchimp.com/3.0/lists/b123456789/members' \

      --user 'myaddress@example.com:4d5751ea6cccc12345678902d4a01297-us6' \

      --data '{"email_address":"user@example.com","status":"pending","email_type":"html","merge_fields":{"FNAME":"FirstName","LNAME":"LastName"}}'

      If I translate this into "Insert from URL" it becomes:

      Insert from URL [ gResult ; "https://us6.api.mailchimp.com/3.0/lists/b123456789/members" ; curl-options:

      --request POST \

      --user myaddress@example.com:4d5751ea6cccc12345678902d4a01297-us6 \

      --data {"email_address":"user@example.com","status":"pending","email_type":"html","merge_fields":{"FNAME":"FirstName","LNAME":"LastName"}}

      The response from mailchimp then is:

      {
          
      "detail": "The resource submitted could not be validated. For field-specific details, see the 'errors' array.",
          
      "errors": [{
              
      "field": "",
              
      "message": "Schema describes object, NULL found instead"
          
      }],
          
      "instance": "",
          
      "status": 400,
          
      "title": "Invalid Resource",
          
      "type": "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/"
      }

      This result is caused by the "merge_fields"-object, so when I remove that object from the data-part, the subscriber will be created, however without the merge-fields. The response (shortened) from mailchimp is:

       

      {
           "id": "0264DB24CF12C037690758132A4BD5B8",
           "email_address": "myaddress@example.com",
           "unique_email_id": "0123456789",
           "email_type": "html",
           "status": "subscribed",

          
      "merge_fields": {
               "FNAME": "",
               "LNAME": ""
           },

           "stats": {
               "avg_open_rate": 0,
               "avg_click_rate": 0
           },
           "ip_signup": "",
           "timestamp_signup": "",
           "ip_opt": "127.0.0.1",
           "timestamp_opt": "2017-06-04T23:02:38+00:00",
           "member_rating": 2,
           "last_changed": "2017-06-04T23:02:38+00:00",
           "language": "",
           "vip": false,
           "email_client": "",
           "location": {
               "latitude": 0,
               "longitude": 0,
               "gmtoff": 0,
               "dstoff": 0,
               "country_code": "",
               "timezone": ""
           },
           "list_id": "b123456789",
           "_links": [
               {
                   "rel": "self",
                   "href": "https://us6.api.mailchimp.com/3.0/lists/b123456789/members/0264DB24CF12C037690758132A4BD5B8",
                   "method": "GET",
                   "targetSchema": "https://us16.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json"
               }
           ]
      }

       

       

      If I use the command line and send the command as in the first quote-block above the same subscriber is created with the merge-fields. The response (shortened) form mailchimp then is:

      {
           "id": "0264DB24CF12C037690758132A4BD5B8",
           "email_address": "myaddress@example.com",
           "unique_email_id": "0123456789",
           "email_type": "html",
           "status": "subscribed",

          
      "merge_fields": {
               "FNAME": "FirstName",
               "LNAME": "LastName"
           },

           "stats": {
               "avg_open_rate": 0,
               "avg_click_rate": 0
           },
           "ip_signup": "",
           "timestamp_signup": "",
           "ip_opt": "127.0.0.1",
           "timestamp_opt": "2017-06-04T23:02:38+00:00",
           "member_rating": 2,
           "last_changed": "2017-06-04T23:02:38+00:00",
           "language": "",
           "vip": false,
           "email_client": "",
           "location": {
               "latitude": 0,
               "longitude": 0,
               "gmtoff": 0,
               "dstoff": 0,
               "country_code": "",
               "timezone": ""
           },
           "list_id": "b123456789",
           "_links": [
               {
                   "rel": "self",
                   "href": "https://us6.api.mailchimp.com/3.0/lists/b123456789/members/0264DB24CF12C037690758132A4BD5B8",
                   "method": "GET",
                   "targetSchema": "https://us16.api.mailchimp.com/schema/3.0/Definitions/Lists/Members/Response.json"
               }
           ]
      }

       

      So the problem is that adding

      ,"merge_fields":{"FNAME":"FirstName","LNAME":"LastName"}

      to the data-part in FM result in an error, where the same addition on the command line works perfectly and adds a new subscriber. Is this a bug in "insert URL" or am I doing something wrong?

        • 1. Re: Insert from URL (mailchimp) - cURL options trouble
          user19752

          It is confusing that you'r curl-options doesn't have tons of backslashes, it need on FM calculation like

          "--data {\"abc\":123}"

          • 2. Re: Insert from URL (mailchimp) - cURL options trouble
            Menno

            sorry for causing the confusion, that's because i stored the curl-options in a field. I do that for better readability and less errors. I can assure you that my code works (without the merge_fields-object in the data-option) just as shown here.

            • 3. Re: Insert from URL (mailchimp) - cURL options trouble
              user19752

              OK, so your real option in the step is

              someTable::someField

               

              Have you checked the option values don't contain space or special characters which should be encoded?

              • 4. Re: Insert from URL (mailchimp) - cURL options trouble
                Menno

                it works flawless as long as i leave the merge_fields-object out of the data-option. No encoding what so ever is needed.

                 

                it seems that objects enclosed in an object don't "work" with FileMaker. Anyone has the same experience with other api's?

                • 5. Re: Insert from URL (mailchimp) - cURL options trouble
                  user19752

                  You'd need a line for content-type

                  --header content-type:application/json

                  notice, there is no space after : so that FM send whole string as header value, space is separator.

                  using single quote like curl command line doesn't work here.

                   

                  With urlencode option,

                  --data-urlencode {\"a\": 20,\"b\":{\"c\":2, \"d\":3}}

                  server (php code) returns 13 as CONTENT_LENGTH. First "{" and space looks correctly encoded, but second "{" is not.

                  I'm not sure but this is your issue, could be a bug.

                   

                  Using variable for data succeeded.

                  --data @$data

                  this get 28 as CONTENT_LENGTH. ($data contains raw data, not urlencoded)

                  • 6. Re: Insert from URL (mailchimp) - cURL options trouble
                    Menno

                    user19752 thank you for your suggestion, but I posted the examples here without the header-option, because the mailchimp-API only known json and it turned out that the cURL-command worked fine without the custom-header. However to make sure, I did again test both variants on both the command line and in IFU (insert from url). There is no difference in how the webservice reacts to the methods with or without a custom-header.

                     

                    When I enter for the data:

                    --data {"email_address":"user@example.com","status":"pending","email_type":"html"}

                    the subscriber is created and there are no errors, but do I enter for the data:

                    --data {"email_address":"user@example.com","status":"pending","email_type":"html","merge_fields":{"FNAME":"FirstName","LNAME":"LastName"}}

                    The error is returned, when POST is used to enter a new subscriber and when PATCH is used to edit an existing subscriber, nothing changes, no error is returned.

                     

                    I did the very same POST on the command line and there both "--data-lines" resulted in a new subscribers. The PATCH on the cmd-line obviously edited the subscriber as expected.

                     

                    So using IFU: making a connection works, adding data works, even changing (status for example) works, just not adding data to the merge_fields. Not when creating a new subscriber with POST-method, nor with updating an existing subscriber with PATCH-method.

                     

                    I have tested every possible variant, only I tested everything on MacOSX 10.12.5 ..... maybe it does work on Windows, so I will test that next and will let you know.

                    • 7. Re: Insert from URL (mailchimp) - cURL options trouble
                      Menno

                      Tried it on windows  10 now, but the results are identical. On the command-line it works adding data to the merge_fields, it doesn't using IFU in FileMaker. I will make a bug-report out of this discussion.

                      • 8. Re: Insert from URL (mailchimp) - cURL options trouble
                        fmpdude

                        Do you really "have" to use the curl options?


                        Can't you instead, just use INSERT FROM URL and pass multiple variables like this:

                         

                        URL format: server.com?variable1=value1&variable2=value2&variable3=value3

                         

                        INSERT FROM URL handles post automatically if you use httpost.

                         

                        And regular INSERT FROM URL handles https

                         

                        Insert From URL

                         

                        HOPE THIS HELPS.

                        • 9. Re: Insert from URL (mailchimp) - cURL options trouble
                          Menno

                          Yes have to, see the mailchimp-documentation: http://developer.mailchimp.com/documentation/mailchimp/reference/overview/

                           

                          A simple get will not do the trick, because you have to authenticate with a user/key. The username is an email address so simply adding user:pass@ at the beginning of the url will not work.

                           

                          Another problem would be that using the PATCH-method can't be done like that .... there is no httppatch or httpput or httpdelete available.

                          1 of 1 people found this helpful
                          • 10. Re: Insert from URL - sub-objects in JSON-data are not passed to Mailchimp-webservice
                            Menno

                            I edited my original post a bit. It started as a question, but meanwhile I think this is a product-issue. The only work-around is to either use the command-line with a script or use one of the suitable plugins. TroiURL, BaseElementPlugin etc.

                             

                            Just to have the problem clear: I can communicate with mailchimp and I can create new subscribers. I cannot add data in the so called merge_fields in mailchimp, not during creating the subscriber, nor by editing an existing one. The only thing needed to not make it work is adding sub-objects in the JSON in the data-part of the cURL-options in IFU.

                            • 11. Re: Insert from URL (mailchimp) - cURL options trouble
                              fmpdude

                              Gotcha.

                               

                              I don't have FMP 16, but even If I did, this whole connection is so much easier in Java. So, from FMP 14, I just call my microserivce on the server (using a GET call and INSERT FROM URL) with the right call so my service knows the right code to call.

                               

                              Doing any kind of URL is simple and inutiitve in Java. And, I can return whatever I need to back to FMP:

                               

                                URL url = new URL(requestURL);
                                httpConn
                              = (HttpURLConnection) url.openConnection();
                                httpConn
                              .setRequestMethod("POST");
                                httpConn
                              .setRequestProperty("X-HTTP-Method-Override", "PATCH");

                                httpConn
                              .setRequestProperty("Content-Type", "application/json");
                                httpConn
                              .setRequestProperty("Authorization", authorization);
                                httpConn
                              .setRequestProperty("charset", "utf-8");

                              .

                              .

                              .

                              • 12. Re: Insert from URL - sub-objects in JSON-data are not passed to Mailchimp-webservice
                                Menno

                                I know there are several possible solutions, but that's not the point here. Since FM16 we have the possibility to call a webservice native from FM using IFU with custom-headers and other cURL-options.

                                 

                                People (including myself) have asked FMI to build in such options and now they did. For the most part, things seem to work pretty well, but there are issues and this is one of them.

                                 

                                I have this going using plugins and also without plugins, using scripts and the commandline, but I would like to do it natively, so I use it on my iPad for example.

                                 

                                Java maybe intuitive to you, but unfortunately not to me and a few others here. Even so I do appreciate your comments though, thank you.

                                1 of 1 people found this helpful
                                • 13. Re: Insert from URL (mailchimp) - cURL options trouble
                                  user19752

                                  On command line you need single quote to enclose data containing space (separator character between options).

                                  --data '{"email_address":.....

                                  In the script option, there is no such syntax, so instead you'd need using variable.

                                  --data @$var

                                  Your data doesn't contain space, so it looks bug on parsing string. But you can use variable all the time.

                                  1 of 1 people found this helpful
                                  • 14. Re: Insert from URL (mailchimp) - cURL options trouble
                                    Menno

                                    user19752 wrote:

                                     

                                    On command line you need single quote to enclose data containing space (separator character between options).

                                    --data '{"email_address":.....

                                    In the script option, there is no such syntax, so instead you'd need using variable.

                                    --data @$var

                                    Your data doesn't contain space, so it looks bug on parsing string. But you can use variable all the time.

                                    The problem is not in the text-strings I use or quotes that I should or should not include, because they all work as expected on the command-lines and they also work perfectly in FileMaker in the IFU-cURL-options

                                     

                                    only after adding:

                                    ,"merge_fields":{"FNAME":"FirstName","LNAME":"LastName"}

                                    into the flawless working data-string in the FileMaker IFU-command's cURL-options causes the problem. Everything else just works as expected and doesn't need trouble-shooting

                                     

                                    If I add ' into my particular code as you suggest, the IFU-command's cURL-options aren't parsed at all anymore and no subscriber is created even without merge_fields-object added.

                                    1 2 3 Previous Next