Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

How to extract this flavor of json from rest api call ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to extract this flavor of json from rest api call ?

    Hi, who can help me with this riddle:

    From a succesfull rest api call I get this response:

    ?varResponse
    = body = {"value":[{"id":"970396fe-534f-4a68-a3ac-cb2a98ab389a","IsArchived":false,"AdditionalName":null,"ChamberOfCommerceCity":null,"ChamberOfCommerceNumber":null,"City":null,"EMail":"[email protected]","Name":"Buchhalter.ln","SearchName":"Buchhalter.ln","IdentifierNumber":1}]}
    error_code = 0
    error_text = ""
    headers = HTTP/1.1 200 OK
    Cache-Control: no-cache
    Pragma: no-cache
    Content-Type: application/json; charset=utf-8
    Content-Language: nl-NL
    Expires: -1
    X-Content-Type-Options: nosniff
    X-Frame-Options: deny
    Date: Wed, 13 Jan 2016 21:49:31 GMT
    Connection: close
    Content-Length: 272
    +parsed_headers.
    I can't find a json method which extracts the json content form varResponse.body
    And sending back the content without adjustments to control result in the browser (using: e._set.result.value = response.body) throws a javascript error.......

    thanks in advance

    Ger
    Ger Kurvers
    Alpha Anywhere / V4.6.1.9- Build 6488 (production) / V4.6.5.1 - 8722-5683(testing)
    Development: Mysql, windows 10 64 Applicationserver: standard on Windows server 2019

    #2
    Re: How to extract this flavor of json from rest api call ?

    i do not know dutch to interpret the company you are reaching for your api and what they supply,
    this result shown seems not just json response. it is contained in the entire response generated by the server.
    your call to the server should be reevaluated to limit to single response end point or the header should include the api call is json not general html as it appears, i could be wrong.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    [email protected]
    Skype:[email protected]
    1 914 924 5171

    Comment


      #3
      Re: How to extract this flavor of json from rest api call ?

      Hi Gandhi,

      Thanks for looking in to it. Some clarification. varResponse is a pointer filled with a http_fetch request to the rest-api, so:

      dim varRespons as P
      varResponse = http_fetch(settings)

      What I showed was the content of varResponse in the interactive window of the code editor.
      The request is ok, but where i'm stuk is getting the (json?) data from varResponse.body which seems to contain:

      {"value":[{"id":"970396fe-534f-4a68-a3ac-cb2a98ab389a","IsArchived":false,"AdditionalName":null,"ChamberOfCommerceCity":null,"ChamberOfCommerceNumber":null,"City":null,"EMail":"[email protected]","Name":"Buchhalter.ln","SearchName":"Buchhalter.ln","IdentifierNumber":1}]}
      Makes this the puzzle clearer?

      Thanks,

      Ger
      Ger Kurvers
      Alpha Anywhere / V4.6.1.9- Build 6488 (production) / V4.6.5.1 - 8722-5683(testing)
      Development: Mysql, windows 10 64 Applicationserver: standard on Windows server 2019

      Comment


        #4
        Re: How to extract this flavor of json from rest api call ?

        i understand. do it in the i.e. or safari or chrome and then,
        what i will do is inspect this in web inspector or f12 and check the response
        then assign the varResponse to one that gives json.
        because http_fetch(settings) is showing the http not json.
        or look into your http_fetch see if you can set the header to data/json.
        thanks for reading

        gandhi

        version 11 3381 - 4096
        mysql backend
        http://www.alphawebprogramming.blogspot.com
        [email protected]
        Skype:[email protected]
        1 914 924 5171

        Comment


          #5
          Re: How to extract this flavor of json from rest api call ?

          would please post your api call statement , you can remove username, password if any.
          thanks for reading

          gandhi

          version 11 3381 - 4096
          mysql backend
          http://www.alphawebprogramming.blogspot.com
          [email protected]
          Skype:[email protected]
          1 914 924 5171

          Comment


            #6
            Re: How to extract this flavor of json from rest api call ?

            Originally posted by GGandhi View Post
            would please post your api call statement , you can remove username, password if any.
            Yes of course, any help appriciated!
            It is a testaccount, so i left the username/password (will change it tomorrow :-)


            dim varHeader as C

            varHeader = "Accept: application/json" + crlf() + "Authorization: Basic UkxaQVBJOnNtdXJmMTI=" + crlf() + "Accept-Charset: iso-8859-1" + crlf() + "Accept-Encoding: gzip,deflate" + crlf() + "Accept-Language: nl-NL"

            dim pQuery as P
            pQuery.administration = ""
            pQuery.body = ""


            dim varQuery as C = ""


            dim settings as p
            settings.header = varHeader
            settings.host = "portal.reeleezee.nl"
            settings.method = "GET"
            settings.body = pQuery.body
            settings.page = "/API/v1/Customers"
            settings.query_string = varQuery
            settings.SSL_ON = .T.
            settings.ssl_ValidateCert = .F.

            dim varResponse as p = http_fetch(settings)
            Ger Kurvers
            Alpha Anywhere / V4.6.1.9- Build 6488 (production) / V4.6.5.1 - 8722-5683(testing)
            Development: Mysql, windows 10 64 Applicationserver: standard on Windows server 2019

            Comment


              #7
              Re: How to extract this flavor of json from rest api call ?

              okay, the call seems to be correct using http_fetch, i think the answer could be in alpha.

              you are using http_fetch() alpha function ( i use javascript scripts on mine)
              the pointer variable does contain all the info you posted.
              i would add
              Code:
              dim desired_value as c
              desired_value = varResponse.body
              then
              you could use json_parse to parse it out.
              thanks for reading

              gandhi

              version 11 3381 - 4096
              mysql backend
              http://www.alphawebprogramming.blogspot.com
              [email protected]
              Skype:[email protected]
              1 914 924 5171

              Comment


                #8
                Re: How to extract this flavor of json from rest api call ?

                Thanks for checking!

                I have tried that before and just now again. Unfotunately no succes. But I see that right now I get a different response, looks like hex value pairs, which alpha recognizes as Blob. So no chance that json_parse will work.

                I Will check with the api provider and see wether they are working at their api and messed things up at the moment :-(

                Originally posted by GGandhi View Post
                okay, the call seems to be correct using http_fetch, i think the answer could be in alpha.

                you are using http_fetch() alpha function ( i use javascript scripts on mine)
                the pointer variable does contain all the info you posted.
                i would add
                Code:
                dim desired_value as c
                desired_value = varResponse.body
                then
                you could use json_parse to parse it out.
                Ger Kurvers
                Alpha Anywhere / V4.6.1.9- Build 6488 (production) / V4.6.5.1 - 8722-5683(testing)
                Development: Mysql, windows 10 64 Applicationserver: standard on Windows server 2019

                Comment


                  #9
                  Re: How to extract this flavor of json from rest api call ?

                  I tested with your credentials and it is returning hex representation.
                  however using the data you had earlier in interactive window

                  Code:
                  dim jsP as p
                  
                  jsP = {"value":[{"id":"970396fe-534f-4a68-a3ac-cb2a98ab389a","IsArchived":false,"AdditionalName":null,"ChamberOfCommerceCity":null,"ChamberOfCommerceNumber":null,"City":null,"EMail":"[email protected]","Name":"Buchhalter.ln","SearchName":"Buchhalter.ln","IdentifierNumber":1}]}
                  ?jsP.value
                  +[1].
                  
                  ?jsp.value[1].id
                  = "970396fe-534f-4a68-a3ac-cb2a98ab389a"
                  ?jsp.value[1].IsArchived
                  = .F.
                  so I would add
                  dim desired_result as p
                  desired_result = varResponse.body.value
                  then parse that one.
                  thanks for reading

                  gandhi

                  version 11 3381 - 4096
                  mysql backend
                  http://www.alphawebprogramming.blogspot.com
                  [email protected]
                  Skype:[email protected]
                  1 914 924 5171

                  Comment


                    #10
                    Re: How to extract this flavor of json from rest api call ?

                    Code:
                    ?varResponse
                    = body = 0000 : 1f 8b 08 00 00 00 00 00 04 00 74 8e b1 6e c3 30 
                    0010 : 0c 44 ff 85 b3 55 b4 71 9a 58 9e 9a 1a 1d 3c d4 
                    0020 : 19 32 06 19 28 89 82 09 d0 32 a0 58 01 0a c3 ff 
                    0030 : 1e 15 45 da 2e 1e 79 8f e4 bd 19 6e 28 89 a0 3e 
                    0040 : cf c0 0e 6a d0 fb e7 52 ef 3c a9 d7 72 eb d5 16 
                    0050 : 77 95 c2 12 ad b2 66 83 ba 42 53 56 1a a1 80 f6 
                    0060 : 7a 88 b6 e7 1b e5 1b 8f 72 a5 02 0e ce f1 c4 63 
                    0070 : 40 e9 70 c8 1f 43 12 29 a0 e9 71 30 14 8f be 19 
                    0080 : 87 81 a2 a5 86 a7 af 55 d8 a5 ef f9 17 ff 5b fd 
                    0090 : f8 44 96 ec c7 c1 8f 6f 26 d9 be 47 99 28 3e 05 
                    00a0 : c9 36 3f 85 f0 fe 17 4b c8 f1 89 30 4b ae c0 d6 
                    00b0 : 51 98 d8 33 c5 47 e9 cb 72 59 ee 03 00 bb d9 0a 
                    00c0 : 99 10 01 00 00 
                    error_code = 0
                    error_text = ""
                    headers = HTTP/1.1 200 OK
                    Cache-Control: no-cache
                    Pragma: no-cache
                    Content-Type: application/json; charset=utf-8
                    Content-Encoding: gzip
                    Content-Language: nl-NL
                    Expires: -1
                    Vary: Accept-Encoding
                    X-Content-Type-Options: nosniff
                    X-Frame-Options: deny
                    Date: Thu, 14 Jan 2016 17:16:35 GMT
                    Connection: close
                    Content-Length: 197
                    +parsed_headers.
                    
                    ?varResponse.body
                    = 0000 : 1f 8b 08 00 00 00 00 00 04 00 74 8e b1 6e c3 30 
                    0010 : 0c 44 ff 85 b3 55 b4 71 9a 58 9e 9a 1a 1d 3c d4 
                    0020 : 19 32 06 19 28 89 82 09 d0 32 a0 58 01 0a c3 ff 
                    0030 : 1e 15 45 da 2e 1e 79 8f e4 bd 19 6e 28 89 a0 3e 
                    0040 : cf c0 0e 6a d0 fb e7 52 ef 3c a9 d7 72 eb d5 16 
                    0050 : 77 95 c2 12 ad b2 66 83 ba 42 53 56 1a a1 80 f6 
                    0060 : 7a 88 b6 e7 1b e5 1b 8f 72 a5 02 0e ce f1 c4 63 
                    0070 : 40 e9 70 c8 1f 43 12 29 a0 e9 71 30 14 8f be 19 
                    0080 : 87 81 a2 a5 86 a7 af 55 d8 a5 ef f9 17 ff 5b fd 
                    0090 : f8 44 96 ec c7 c1 8f 6f 26 d9 be 47 99 28 3e 05 
                    00a0 : c9 36 3f 85 f0 fe 17 4b c8 f1 89 30 4b ae c0 d6 
                    00b0 : 51 98 d8 33 c5 47 e9 cb 72 59 ee 03 00 bb d9 0a 
                    00c0 : 99 10 01 00 00 
                    
                    dim jsP as p
                    jsP = varResponse.body
                    ?jsP.value[1].id
                    = "970396fe-534f-4a68-a3ac-cb2a98ab389a"
                    I ran your code again, it does give hex but I assigned it to an object and the value extracted.
                    if it is in an ux, you can assign that value to any control.
                    thanks for reading

                    gandhi

                    version 11 3381 - 4096
                    mysql backend
                    http://www.alphawebprogramming.blogspot.com
                    [email protected]
                    Skype:[email protected]
                    1 914 924 5171

                    Comment


                      #11
                      Re: How to extract this flavor of json from rest api call ?

                      Ger,

                      The code you posted for the api is different than the code you used to produce the results from your first post. The code you posted encodes the response body. The code you originally ran does not.

                      If you run the code below, the reponse body will match what you first posted. Using json_parse() on the response body will create a dot variable array which you can then get at.

                      Code:
                      dim varHeader as C 
                      
                      'varHeader = "Accept: application/json" + crlf() + "Authorization: Basic UkxaQVBJOnNtdXJmMTI=" + crlf() + "Accept-Charset: iso-8859-1" + crlf() + "Accept-Encoding: gzip,deflate" + crlf() + "Accept-Language: nl-NL"
                      
                      varHeader = "Accept: application/json" + crlf() + "Authorization: Basic UkxaQVBJOnNtdXJmMTI="
                      
                      dim pQuery as P
                      pQuery.administration = ""
                      pQuery.body = ""
                      
                      
                      dim varQuery as C = ""
                      
                      
                      dim settings as p
                      settings.header = varHeader
                      settings.host = "portal.reeleezee.nl"
                      settings.method = "GET"
                      settings.body = pQuery.body
                      settings.page = "/API/v1/Customers"
                      settings.query_string = varQuery
                      settings.SSL_ON = .T.
                      settings.ssl_ValidateCert = .F.
                      
                      dim varResponse as p = http_fetch(settings)	
                      
                      dim resp as p = json_parse(varResponse.body)
                      Now, resp.value[1].EMail has the value [email protected], and resp.value[1].id has the value 970396fe-534f-4a68-a3ac-cb2a98ab389a.

                      Some of the returned items are null and therefore do not get returned in the dot variable. E.g. "AdditionalName":null,"ChamberOfCommerceCity":null,"ChamberOfCommerceNumber":null,"City":null,"

                      So these items will not show up in the dot variable. If you're looking for these values you'd need to test the dot variable for a value and that will confirm a returned null value.

                      https://s3-us-west-2.amazonaws.com/a...sc/apiResp.PNG
                      Last edited by Davidk; 01-14-2016, 02:33 PM.

                      Comment


                        #12
                        Re: How to extract this flavor of json from rest api call ?

                        Hi Gandhi, David,

                        Both thanks for your effort. Gandhi for keeping me on the right track, I was getting desperate and your findings were really reassuring that I was on the right track.

                        David, you discovered the real culprit: I indeed added the header "Accept-Encoding: gzip,deflate" (because that is requested by the api provider).

                        This has as effect that without additional adjustment:
                        the statements like

                        dim jsP as p
                        jsp = json_parse(varResponse.body)

                        dim varBody as c
                        varBody = jsP.value[1].id

                        throw an xbasic error:
                        Error executing Ajax callback. Error executing Ajax callback function 'get_administrations ': command: varBody = jsP.value[1].EMail 'json_generate(jsP) Property not found jsP.value[] subelement not found.
                        Also other methods for giving back the response to controls of the component fail, for example e._state.response_body.value = json_generate(jsP) result in an empty json string {} in the control

                        It works for now without that header.
                        But how to work with that header? What is the right function to decode varResponse.body before putting it into an xbasic pointer or using it in xbasic functions?
                        Ger Kurvers
                        Alpha Anywhere / V4.6.1.9- Build 6488 (production) / V4.6.5.1 - 8722-5683(testing)
                        Development: Mysql, windows 10 64 Applicationserver: standard on Windows server 2019

                        Comment


                          #13
                          Re: How to extract this flavor of json from rest api call ?

                          But if you're using the encoding header stuff then you're getting back binary data in the body. The body is binary. So... based on the api provider... what is it? They would tell you what is coming back. If you know what's coming back then it can, most likely, be dealt with.

                          One thing for sure, you're not getting back JSON when using that encoding header... and therefore you cannot parse it.

                          Comment


                            #14
                            Re: How to extract this flavor of json from rest api call ?

                            you are using http_fetch.
                            regardless of what the provider provides the http_fetch will return a pointer variable. nothing to do with the provider.
                            the pointer variable contains the body which is a character which is in json format and you can parse that to an object to get dot variables.
                            when you use the gzip, deflate, the http_fetch is some how converted to low level http_get, by alpha, and the returns the binary data, the same data in binary format. again nothing to do with the provider it is the alpha thing.
                            in short
                            you can use all the stuff in the header except for gzip, deflate encoding.
                            and parse the varResponse.body
                            and the value inside can be found by various dot variables in the parsed value[1] dot notation
                            for example
                            Code:
                            dim jsp as p
                            jsp = json_parse(varResponse.body)
                            dim customer_id as c
                            customer_id = jsp.value[1].id
                            now you can set value of any control with that value.
                            if you must use gzip, deflate encoding ( i did not see that as a requirement in english translation of that site or did not see it in proper place ) then you would get the same data same mechanism to get the dot variables, the limitation is you need to know all the stuff contained in the value to get at it. or look in the browser they will translate the binary data to human readable format, i am sure.
                            thanks for reading

                            gandhi

                            version 11 3381 - 4096
                            mysql backend
                            http://www.alphawebprogramming.blogspot.com
                            [email protected]
                            Skype:[email protected]
                            1 914 924 5171

                            Comment


                              #15
                              Re: How to extract this flavor of json from rest api call ?

                              here is an implementation using your code minus gzip, deflate

                              http://screencast.com/t/jFqPZvpFs
                              thanks for reading

                              gandhi

                              version 11 3381 - 4096
                              mysql backend
                              http://www.alphawebprogramming.blogspot.com
                              [email protected]
                              Skype:[email protected]
                              1 914 924 5171

                              Comment

                              Working...
                              X