3 Replies Latest reply on Jul 30, 2017 6:47 PM by bigtom

    JSON lexical error

    cdunkake

      Hi folks,

       

      I'm trying to find my mistake for hours, maybe one of you sees it right away...

       

      I'm want to connect to the PivotalTracker API (Pivotal Tracker API - Essentials ).

       

      Every request that does not require body parameter / is a GET request works great.

      E.g. (to get details about a story): PT want

      curl -X GET -H "X-TrackerToken: $TOKEN" "https://www.pivotaltracker.com/services/v5/projects/$PROJECT_ID/stories/559"

      I give them

      and everything is good.

       

      Whatever I try a request that actually requires a body end up with a lexical error what ever I try.

      PT want e.g.

      curl -X POST -H "X-TrackerToken: $TOKEN" -H "Content-Type: application/json" -d '{"current_state":"started","estimate":1,"name":"Exhaust ports are ray shielded   "}'

      The body part being

      -d '{"current_state":"started","estimate":1,"name":"Exhaust ports are ray shielded   "}'

      I always get something like

      {"code":"could_not_parse_body","kind":"error","error":"Cannot parse the JSON-encoded request body.","general_problem":"Couldn't parse the content of the request's body.","possible_fix":"The parser returned the following error message:  lexical error: invalid char in json text.\n                                       '{\\\"name\\\":\\\"NEW\n                     (right here) ------^\n"}

       

      It seems that the requires "'"s confuse FM since it apparently does escape all the content. But I cannot get rid of the escapes since then the calculation in FM is not accepted.

      Any hints?

        • 1. Re: JSON lexical error
          Menno

          I had a similar problem a while ago with connecting to mailchimp. It turned out that I had to change the way the body-part is inserted. The answer was in this help-article. So you can change the curl-options in this way and enter this formula in the "curl-options"

          Let ( [

                $token = "your pivotal token" ;

               $H1 = "X-TrackerToken: " & $token ;

               $H2 = "Content-Type: application/json" ;

               $data = JSONSetElement ( "" ;

                         [ "current_state" ; "started" ; JSONString ] ;

                         [ "estimate" ; 1 ; JSONNumber ] ;

                         [ "name" ; "Exhaust ports are ray shielded   " ; JSONString ] )

          ] ;

               " -X POST" &

               " -H " & Quote ( $H1 ) &

               " -H " & Quote ( $H2 ) &

               " -d @$data"

          )

          FileMaker will magically replace @$data into the contents of the $data-parameter. I have not tried Pivotal Tracker API myself, but I think this can solve your problem.

           

          [edit]I tried this setup and I get an nice answer:

          {"kind":"story","id":149786262,"project_id":2087813,"name":"Exhaust ports are ray shielded   ","story_type":"feature","current_state":"started","estimate":1,"requested_by_id":2957781,"owner_ids":[],"labels":[],"created_at":"2017-07-30T18:16:24Z","updated_at":"2017-07-30T18:16:24Z","url":"https://www.pivotaltracker.com/story/show/149786262"}

          So this works fine :-)[/edit]

          1 of 1 people found this helpful
          • 2. Re: JSON lexical error
            wimdecorte

            cdunkake wrote:

             

             

            -d '{"current_state":"started","estimate":1,"name":"Exhaust ports are ray shielded "}'

             

             

            What's that whitespace at the end, after "shielded"?  Maybe there's something there that the web service does not like.

            • 3. Re: JSON lexical error
              bigtom

              I have found many web services have troubles with spaces in a JSON values from FM. This seems to be a bug in the JSONSetElement function. The only workaround I have found is to manually JSON escape the spaces.

               

              Try a one word test like -d {"current_state":"started","estimate":1,"name":"Exhaust"}

              2 of 2 people found this helpful