Alaska Software Inc. - Json request
Username: Password:
AuthorTopic: Json request
Rudolf ReinthalerJson request
on Fri, 10 Oct 2014 10:40:04 +0200
Hello,
have successfully called some funcitions in the Mailchimp API with 
ASINET, but now I stuck with posting a associative array. Attached 
what's needed regarding the docs at 
http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php

regards
Rudolf




My code:

  cCGIValue := "apikey=" + cKey
  cCGIValue += "&id=" + cList
  cCGIValue += "&email=" + '{"email": "r.reinthaler@c-tec.at","euid": 
"123xyz","leid": "45897abc"}'

  cURL      := "https://us5.api.mailchimp.com/2.0/lists/subscribe"

  cResponse := 
LoadFromUrl(cURL,INTERNET_DEFAULT_HTTPS_PORT,INTERNET_COMMUNICATION_SECURE,,,"POST", 
cCGIValue)
  cResponse := json_pretty_out(cResponse)
  xmemowrit("json.txt",cResponse)
  txtview(cResponse)




The response:


{
    "status" : "error" ,
    "code" : -100 ,
    "name" : "ValidationError" ,
    "error" : "Validation error: {\"email\":\"Please enter a 
struct\\\/associative array\"}"
}










Needed JSON struct:
{
     "apikey": "example apikey",
     "id": "example id",
     "email": {
         "email": "example email",
         "euid": "example euid",
         "leid": "example leid"
     },
     "merge_vars": {
         "new-email": "example new-email",
         "groupings": [
             {
                 "id": 42,
                 "name": "example name",
                 "groups": [
                     "..."
                 ]
             }
         ],
         "optin_ip": "example optin_ip",
         "optin_time": "example optin_time",
         "mc_location": {
             "latitude": "example latitude",
             "longitude": "example longitude",
             "anything": "example anything"
         },
         "mc_language": "example mc_language",
         "mc_notes": [
             {
                 "note": "example note",
                 "id": 42,
                 "action": "example action"
             }
         ]
     },
     "email_type": "example email_type",
     "double_optin": true,
     "update_existing": true,
     "replace_interests": true,
     "send_welcome": true
}

---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com
Andreas HerdtRe: Json request
on Fri, 10 Oct 2014 11:53:16 +0200
Hi Rudolph,

Xbase++ 2.0 currently has a (yet undocumented) function Var2Json(). For 
creating a request you would do something like that:

   o := DataObject():new()
   o:apikey := "example apikey"
   o:id     := "example id"
   o:email := DataObject():new()
   o:email:email := "example email"
   o:email:euid  := "example euid"
   o:email:leid  := "example leid"
   o:merge_vars := DataObject():new()
   o:merge_vars:&("new-email") := "example new-email"
   o:merge_vars:groupings := DataObject():new()
   o:merge_vars:groupings:id := 42
   o:merge_vars:groupings:name := "example name"
   o:merge_vars:groupings:groups := "..."

Attention: Json2Var() is not ready yet, you would have to deal with a Json 
result for your own.

  Andreas Herdt
  Alaska Software

--------------------------------------------------------------------

Technical Support:      support@alaska-software.com

News Server:            news.alaska-software.com
Homepage:               http://www.alaska-software.com
WebKnowledgeBase:       http://www.alaska-software.com/kbase.shtm

Fax European Office:    +49 (0) 61 96 - 77 99 99 23
Fax US Office:          +1 (646) 218 1281
--------------------------------------------------------------------

"Rudolf Reinthaler" wrote in message 
news:6f3482f4$4f0931c9$214d@news.alaska-software.com...
> Hello,
> have successfully called some funcitions in the Mailchimp API with ASINET, 
> but now I stuck with posting a associative array. Attached what's needed 
> regarding the docs at 
> http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
>
> regards
> Rudolf
>
>
>
>
> My code:
>
>  cCGIValue := "apikey=" + cKey
>  cCGIValue += "&id=" + cList
>  cCGIValue += "&email=" + '{"email": "r.reinthaler@c-tec.at","euid": 
> "123xyz","leid": "45897abc"}'
>
>  cURL      := "https://us5.api.mailchimp.com/2.0/lists/subscribe"
>
>  cResponse := 
> LoadFromUrl(cURL,INTERNET_DEFAULT_HTTPS_PORT,INTERNET_COMMUNICATION_SECURE,,,"POST", 
> cCGIValue)
>  cResponse := json_pretty_out(cResponse)
>  xmemowrit("json.txt",cResponse)
>  txtview(cResponse)
>
>
>
>
> The response:
>
>
> {
>    "status" : "error" ,
>    "code" : -100 ,
>    "name" : "ValidationError" ,
>    "error" : "Validation error: {\"email\":\"Please enter a 
> struct\\\/associative array\"}"
> }
>
>
>
>
>
>
>
>
>
>
> Needed JSON struct:
> {
>     "apikey": "example apikey",
>     "id": "example id",
>     "email": {
>         "email": "example email",
>         "euid": "example euid",
>         "leid": "example leid"
>     },
>     "merge_vars": {
>         "new-email": "example new-email",
>         "groupings": [
>             {
>                 "id": 42,
>                 "name": "example name",
>                 "groups": [
>                     "..."
>                 ]
>             }
>         ],
>         "optin_ip": "example optin_ip",
>         "optin_time": "example optin_time",
>         "mc_location": {
>             "latitude": "example latitude",
>             "longitude": "example longitude",
>             "anything": "example anything"
>         },
>         "mc_language": "example mc_language",
>         "mc_notes": [
>             {
>                 "note": "example note",
>                 "id": 42,
>                 "action": "example action"
>             }
>         ]
>     },
>     "email_type": "example email_type",
>     "double_optin": true,
>     "update_existing": true,
>     "replace_interests": true,
>     "send_welcome": true
> }
>
> ---
> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus 
> Schutz ist aktiv.
> http://www.avast.com
>
Rudolf ReinthalerRe: Json request
on Fri, 10 Oct 2014 12:21:24 +0200
Hello Andreas,
thank you, but I use 1.9, so I cannot use it.
regards
Rudolf

Am 10.10.2014 11:53, schrieb Andreas Herdt:
> Hi Rudolph,
>
> Xbase++ 2.0 currently has a (yet undocumented) function Var2Json(). For
> creating a request you would do something like that:
>
>    o := DataObject():new()
>    o:apikey := "example apikey"
>    o:id     := "example id"
>    o:email := DataObject():new()
>    o:email:email := "example email"
>    o:email:euid  := "example euid"
>    o:email:leid  := "example leid"
>    o:merge_vars := DataObject():new()
>    o:merge_vars:&("new-email") := "example new-email"
>    o:merge_vars:groupings := DataObject():new()
>    o:merge_vars:groupings:id := 42
>    o:merge_vars:groupings:name := "example name"
>    o:merge_vars:groupings:groups := "..."
>
> Attention: Json2Var() is not ready yet, you would have to deal with a
> Json result for your own.
>


---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com
Erik Re: Json request
on Fri, 10 Oct 2014 08:25:58 -0400
In 1.9 I used ot4xb, there is a JSON library that was fairly easy to 
implement.




On 10/10/2014 6:21 AM, Rudolf Reinthaler wrote:
> Hello Andreas,
> thank you, but I use 1.9, so I cannot use it.
> regards
> Rudolf
>
> Am 10.10.2014 11:53, schrieb Andreas Herdt:
>> Hi Rudolph,
>>
>> Xbase++ 2.0 currently has a (yet undocumented) function Var2Json(). For
>> creating a request you would do something like that:
>>
>>    o := DataObject():new()
>>    o:apikey := "example apikey"
>>    o:id     := "example id"
>>    o:email := DataObject():new()
>>    o:email:email := "example email"
>>    o:email:euid  := "example euid"
>>    o:email:leid  := "example leid"
>>    o:merge_vars := DataObject():new()
>>    o:merge_vars:&("new-email") := "example new-email"
>>    o:merge_vars:groupings := DataObject():new()
>>    o:merge_vars:groupings:id := 42
>>    o:merge_vars:groupings:name := "example name"
>>    o:merge_vars:groupings:groups := "..."
>>
>> Attention: Json2Var() is not ready yet, you would have to deal with a
>> Json result for your own.
>>
>
>
> ---
> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
> Schutz ist aktiv.
> http://www.avast.com
>
Rudolf ReinthalerRe: Json request
on Fri, 10 Oct 2014 18:51:18 +0200
Hello Eric,
but how to solve in 1.9 ? I have OT4XB and posted also in XB4WIN 
newsgrout, it seems that is no solution than purchasing the XB4NET 
version for HTTPS
regards
Rudolf

Am 10.10.2014 14:25, schrieb Erik:
> In 1.9 I used ot4xb, there is a JSON library that was fairly easy to
> implement.
>
>
>
>
> On 10/10/2014 6:21 AM, Rudolf Reinthaler wrote:
>> Hello Andreas,
>> thank you, but I use 1.9, so I cannot use it.
>> regards
>> Rudolf
>>
>> Am 10.10.2014 11:53, schrieb Andreas Herdt:
>>> Hi Rudolph,
>>>
>>> Xbase++ 2.0 currently has a (yet undocumented) function Var2Json(). For
>>> creating a request you would do something like that:
>>>
>>>    o := DataObject():new()
>>>    o:apikey := "example apikey"
>>>    o:id     := "example id"
>>>    o:email := DataObject():new()
>>>    o:email:email := "example email"
>>>    o:email:euid  := "example euid"
>>>    o:email:leid  := "example leid"
>>>    o:merge_vars := DataObject():new()
>>>    o:merge_vars:&("new-email") := "example new-email"
>>>    o:merge_vars:groupings := DataObject():new()
>>>    o:merge_vars:groupings:id := 42
>>>    o:merge_vars:groupings:name := "example name"
>>>    o:merge_vars:groupings:groups := "..."
>>>
>>> Attention: Json2Var() is not ready yet, you would have to deal with a
>>> Json result for your own.
>>>
>>
>>
>> ---
>> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
>> Schutz ist aktiv.
>> http://www.avast.com
>>
>


---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com
Erik Re: Json request
on Fri, 10 Oct 2014 13:47:34 -0400
Maybe I misunderstood, thought you were able to post to the mailchimp 
API but having problems building the JSON response?


On 10/10/2014 12:51 PM, Rudolf Reinthaler wrote:
> Hello Eric,
> but how to solve in 1.9 ? I have OT4XB and posted also in XB4WIN
> newsgrout, it seems that is no solution than purchasing the XB4NET
> version for HTTPS
> regards
> Rudolf
>
> Am 10.10.2014 14:25, schrieb Erik:
>> In 1.9 I used ot4xb, there is a JSON library that was fairly easy to
>> implement.
>>
>>
>>
>>
>> On 10/10/2014 6:21 AM, Rudolf Reinthaler wrote:
>>> Hello Andreas,
>>> thank you, but I use 1.9, so I cannot use it.
>>> regards
>>> Rudolf
>>>
>>> Am 10.10.2014 11:53, schrieb Andreas Herdt:
>>>> Hi Rudolph,
>>>>
>>>> Xbase++ 2.0 currently has a (yet undocumented) function Var2Json(). For
>>>> creating a request you would do something like that:
>>>>
>>>>    o := DataObject():new()
>>>>    o:apikey := "example apikey"
>>>>    o:id     := "example id"
>>>>    o:email := DataObject():new()
>>>>    o:email:email := "example email"
>>>>    o:email:euid  := "example euid"
>>>>    o:email:leid  := "example leid"
>>>>    o:merge_vars := DataObject():new()
>>>>    o:merge_vars:&("new-email") := "example new-email"
>>>>    o:merge_vars:groupings := DataObject():new()
>>>>    o:merge_vars:groupings:id := 42
>>>>    o:merge_vars:groupings:name := "example name"
>>>>    o:merge_vars:groupings:groups := "..."
>>>>
>>>> Attention: Json2Var() is not ready yet, you would have to deal with a
>>>> Json result for your own.
>>>>
>>>
>>>
>>> ---
>>> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
>>> Schutz ist aktiv.
>>> http://www.avast.com
>>>
>>
>
>
> ---
> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
> Schutz ist aktiv.
> http://www.avast.com
>
Thomas BraunRe: Json request
on Fri, 10 Oct 2014 14:41:05 +0200
Andreas Herdt wrote:

>    o:merge_vars:groupings:id := 42

I especially like that one 

Thomas
Osvaldo RamirezRe: Json request
on Sat, 11 Oct 2014 22:14:21 -0600
Hello Rudolf

As you noted, I am using two function from Pablo Botella's lib

JSon and TServerXMLHttpRequest() ...


This is a code that I have

   oJson := JSON_Container():New()
   oJson:num_ticket     := val(str(nNumeroTCK,6,0))
   oJson:clave_sucursal := val(str(nsucursal,3,0))
   oJson:subtotal       := nSubtotal
   oJson:iva            := nTotIva
   oJson:total          := nTotal
   oJson:codigo         := cWebTck
   oJson:fecha          := cfecha

   aDetalle := { {"750565656",2,500.55,23.00},;
                 {"750333336",1,200.55,23.00},;
                 {"750223333",4,100.55,0.00}}

   aJSonDetalle := array( len( aDetalle ))
   for i := 1 to len( aDetalle )
       aJsonDetalle[i] := JSON_Container():New()
       aJsonDetalle[i]:producto := aDetalle[i][1]
       aJsonDetalle[i]:cantidad := aDetalle[i][2]
       aJsonDetalle[i]:precio   := aDetalle[i][3]
       aJsonDetalle[i]:iva      := aDetalle[i][4]
   next
   oJson:partidas := aJSonDetalle

  cJsonString := json_serialize( oJSon )


   oHttp := TServerXMLHTTPRequest():New()
   oHttp:Open("POST",cURL,.f.)
   oHttp:SetReQuestHeader( 'Content-Type', 'application/json;charset=UTF-8')

   oHttp:Send( cJsonString )
   cResponse := oHttp:responseText
   if oHttp:status = 200
     msgbox( cResponse  , "Tck insertado!")
   endif
   oHttp:release()

HTH

Best Regards
Osvaldo Ramirez



rudolfOn 10/10/2014 2:40 AM, Rudolf Reinthaler wrote:
> Hello,
> have successfully called some funcitions in the Mailchimp API with
> ASINET, but now I stuck with posting a associative array. Attached
> what's needed regarding the docs at
> http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
>
> regards
> Rudolf
>
>
>
>
> My code:
>
>   cCGIValue := "apikey=" + cKey
>   cCGIValue += "&id=" + cList
>   cCGIValue += "&email=" + '{"email": "r.reinthaler@c-tec.at","euid":
> "123xyz","leid": "45897abc"}'
>
>   cURL      := "https://us5.api.mailchimp.com/2.0/lists/subscribe"
>
>   cResponse :=
> LoadFromUrl(cURL,INTERNET_DEFAULT_HTTPS_PORT,INTERNET_COMMUNICATION_SECURE,,,"POST",
> cCGIValue)
>   cResponse := json_pretty_out(cResponse)
>   xmemowrit("json.txt",cResponse)
>   txtview(cResponse)
>
>
>
>
> The response:
>
>
> {
>     "status" : "error" ,
>     "code" : -100 ,
>     "name" : "ValidationError" ,
>     "error" : "Validation error: {\"email\":\"Please enter a
> struct\\\/associative array\"}"
> }
>
>
>
>
>
>
>
>
>
>
> Needed JSON struct:
> {
>      "apikey": "example apikey",
>      "id": "example id",
>      "email": {
>          "email": "example email",
>          "euid": "example euid",
>          "leid": "example leid"
>      },
>      "merge_vars": {
>          "new-email": "example new-email",
>          "groupings": [
>              {
>                  "id": 42,
>                  "name": "example name",
>                  "groups": [
>                      "..."
>                  ]
>              }
>          ],
>          "optin_ip": "example optin_ip",
>          "optin_time": "example optin_time",
>          "mc_location": {
>              "latitude": "example latitude",
>              "longitude": "example longitude",
>              "anything": "example anything"
>          },
>          "mc_language": "example mc_language",
>          "mc_notes": [
>              {
>                  "note": "example note",
>                  "id": 42,
>                  "action": "example action"
>              }
>          ]
>      },
>      "email_type": "example email_type",
>      "double_optin": true,
>      "update_existing": true,
>      "replace_interests": true,
>      "send_welcome": true
> }
>
> ---
> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
> Schutz ist aktiv.
> http://www.avast.com
>
Rudolf ReinthalerRe: Json request
on Sun, 12 Oct 2014 11:47:23 +0200
Hello Osvaldo,
got it working ! a little bit tricky, but now I can subscribe in 
Mailchimp with my Xbase++ Application.
regards
Rudolf







Am 12.10.2014 06:14, schrieb Osvaldo Ramirez:
> Hello Rudolf
>
> As you noted, I am using two function from Pablo Botella's lib
>
> JSon and TServerXMLHttpRequest() ...
>
>
> This is a code that I have
>
>    oJson := JSON_Container():New()
>    oJson:num_ticket     := val(str(nNumeroTCK,6,0))
>    oJson:clave_sucursal := val(str(nsucursal,3,0))
>    oJson:subtotal       := nSubtotal
>    oJson:iva            := nTotIva
>    oJson:total          := nTotal
>    oJson:codigo         := cWebTck
>    oJson:fecha          := cfecha
>
>    aDetalle := { {"750565656",2,500.55,23.00},;
>                  {"750333336",1,200.55,23.00},;
>                  {"750223333",4,100.55,0.00}}
>
>    aJSonDetalle := array( len( aDetalle ))
>    for i := 1 to len( aDetalle )
>        aJsonDetalle[i] := JSON_Container():New()
>        aJsonDetalle[i]:producto := aDetalle[i][1]
>        aJsonDetalle[i]:cantidad := aDetalle[i][2]
>        aJsonDetalle[i]:precio   := aDetalle[i][3]
>        aJsonDetalle[i]:iva      := aDetalle[i][4]
>    next
>    oJson:partidas := aJSonDetalle
>
>   cJsonString := json_serialize( oJSon )
>
>
>    oHttp := TServerXMLHTTPRequest():New()
>    oHttp:Open("POST",cURL,.f.)
>    oHttp:SetReQuestHeader( 'Content-Type',
> 'application/json;charset=UTF-8')
>
>    oHttp:Send( cJsonString )
>    cResponse := oHttp:responseText
>    if oHttp:status = 200
>      msgbox( cResponse  , "Tck insertado!")
>    endif
>    oHttp:release()
>
> HTH
>
> Best Regards
> Osvaldo Ramirez
>
>
>
> rudolfOn 10/10/2014 2:40 AM, Rudolf Reinthaler wrote:
>> Hello,
>> have successfully called some funcitions in the Mailchimp API with
>> ASINET, but now I stuck with posting a associative array. Attached
>> what's needed regarding the docs at
>> http://apidocs.mailchimp.com/api/2.0/lists/subscribe.php
>>
>> regards
>> Rudolf
>>
>>
>>
>>
>> My code:
>>
>>   cCGIValue := "apikey=" + cKey
>>   cCGIValue += "&id=" + cList
>>   cCGIValue += "&email=" + '{"email": "r.reinthaler@c-tec.at","euid":
>> "123xyz","leid": "45897abc"}'
>>
>>   cURL      := "https://us5.api.mailchimp.com/2.0/lists/subscribe"
>>
>>   cResponse :=
>> LoadFromUrl(cURL,INTERNET_DEFAULT_HTTPS_PORT,INTERNET_COMMUNICATION_SECURE,,,"POST",
>>
>> cCGIValue)
>>   cResponse := json_pretty_out(cResponse)
>>   xmemowrit("json.txt",cResponse)
>>   txtview(cResponse)
>>
>>
>>
>>
>> The response:
>>
>>
>> {
>>     "status" : "error" ,
>>     "code" : -100 ,
>>     "name" : "ValidationError" ,
>>     "error" : "Validation error: {\"email\":\"Please enter a
>> struct\\\/associative array\"}"
>> }
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> Needed JSON struct:
>> {
>>      "apikey": "example apikey",
>>      "id": "example id",
>>      "email": {
>>          "email": "example email",
>>          "euid": "example euid",
>>          "leid": "example leid"
>>      },
>>      "merge_vars": {
>>          "new-email": "example new-email",
>>          "groupings": [
>>              {
>>                  "id": 42,
>>                  "name": "example name",
>>                  "groups": [
>>                      "..."
>>                  ]
>>              }
>>          ],
>>          "optin_ip": "example optin_ip",
>>          "optin_time": "example optin_time",
>>          "mc_location": {
>>              "latitude": "example latitude",
>>              "longitude": "example longitude",
>>              "anything": "example anything"
>>          },
>>          "mc_language": "example mc_language",
>>          "mc_notes": [
>>              {
>>                  "note": "example note",
>>                  "id": 42,
>>                  "action": "example action"
>>              }
>>          ]
>>      },
>>      "email_type": "example email_type",
>>      "double_optin": true,
>>      "update_existing": true,
>>      "replace_interests": true,
>>      "send_welcome": true
>> }
>>
>> ---
>> Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus
>> Schutz ist aktiv.
>> http://www.avast.com
>>
>


---
Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv.
http://www.avast.com