Announcement

Collapse
No announcement yet.

passing array via MvCall?

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

    passing array via MvCall?

    Hi all,
    I am trying to duplicate this CURL using mvcall:

    Code:
    curl   https://vrapi.verticalresponse.com/api/v1/contacts 
              -H "Authorization: Bearer xxxxxxxxxxxxx"
              -H "Content-Type:application/json" 
              --request POST --data 
                '{
                    "contacts":[
                        {
                            "email":"[email protected]",
                            "first_name":"Hermione",
                            "last_name":"Granger"
                        },
                        {
                            "email":"[email protected]",
                            "first_name":"James",
                            "last_name":"Potter"
                        },
                        {
                            "email":"[email protected]",
                            "first_name":"Lily",
                            "last_name":"Evans"
                        }]
                }' | python -mjson.tool
    Unfortunately, I keep getting the response: "contacts:must be an array"

    Any suggestion on how to:
    - build the array (I have tried multiple methods including MvAssignArray.
    - pass the array in the mvcall (as a field, as a header, in the action ??

    FYI - authorization, etc are working fine, it is only the actual array that is failing.
    Bill
    William Gilligan - Orange Marmalade, Inc.
    www.OrangeMarmaladeinc.com

    #2
    Re: passing array via MvCall?

    Hmm...interesting...I don't think a native "mivascript" array would work outside of Miva. Do they support passing in data via XML format? That's the only way I've previously supplied array type information via MvCall.
    Bruce Golub
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment


      #3
      Re: passing array via MvCall?

      Originally posted by Bruce - PhosphorMedia View Post
      Hmm...interesting...I don't think a native "mivascript" array would work outside of Miva. Do they support passing in data via XML format? That's the only way I've previously supplied array type information via MvCall.

      Not that I have found.
      But I was thinking I should be able to pass the data in the same format as they show - ... just haven't figured it out.
      Apparently PHP and curl can do it, and RUBY:

      Code:
      require 'contact'
       
        VerticalResponse::API::Contact.create(
          :contacts =[
            {
       
              :email = '[email protected]',
              :first_name = 'Hermione',
              :last_name = 'Granger'
            },
            {
              :email ='[email protected]',
              :first_name = 'James',
              :last_name = 'Potter'
            }
          ]
        )
      William Gilligan - Orange Marmalade, Inc.
      www.OrangeMarmaladeinc.com

      Comment


        #4
        Re: passing array via MvCall?

        Wild Ass Guess...have you tried just a cgi array? I.e.,

        email: [email protected],[email protected],[email protected]
        first_name: foo, barry, frank

        etc.
        Bruce Golub
        Phosphor Media - "Your Success is our Business"

        Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
        phosphormedia.com

        Comment


          #5
          Re: passing array via MvCall?

          This is JSON data:
          Code:
          {
                          "contacts":[
                              {
                                  "email":"[email protected]",
                                  "first_name":"Hermione",
                                  "last_name":"Granger"
                              },
                              {
                                  "email":"[email protected]",
                                  "first_name":"James",
                                  "last_name":"Potter"
                              },
                              {
                                  "email":"[email protected]",
                                  "first_name":"Lily",
                                  "last_name":"Evans"
                              }]
                      }
          If I understand what you're trying to do, you should be able to pass all of this to the server as a string, i.e. just the way it is now; no conversion needed. Just be careful to preserve the quotes and other pucntuation.
          Last edited by Kent Multer; 02-23-15, 02:14 AM.
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Re: passing array via MvCall?

            Yea - so far I think I have tried every possible combination.
            The result is either internal error response or it accepts the "contacts" parameter, but does not recognize anything in it (must be an array).
            William Gilligan - Orange Marmalade, Inc.
            www.OrangeMarmaladeinc.com

            Comment


              #7
              Re: passing array via MvCall?

              This should work, assuming you have a valid Authorization header:

              PHP Code:
              <MvCAPTURE VARIABLE "l.json">
              {
                  
              "contacts":[
                      {
                          
              "email":"[email protected]",
                          
              "first_name":"Hermione",
                          
              "last_name":"Granger"
                      
              },
                      {
                          
              "email":"[email protected]",
                          
              "first_name":"James",
                          
              "last_name":"Potter"
                      
              },
                      {
                          
              "email":"[email protected]",
                          
              "first_name":"Lily",
                          
              "last_name":"Evans"
                      
              }]
              }
              </
              MvCAPTURE>


              <
              MvCALL METHOD          "RAW"
                      
              ACTION          "https://vrapi.verticalresponse.com/api/v1/contacts"
                      
              CONTENT-TYPE    "application/json"
                      
              HEADERS         "{ 'Authorization: Bearer xxxxxxx' $ asciichar( 13 ) $ asciichar( 10 ) }"
                      
              FIELDS          "l.json">
                  <
              MvEVAL EXPR "{ s.callvalue }">
              </
              MvCALL
              Last edited by burch; 02-23-15, 10:25 AM.

              Comment


                #8
                Re: passing array via MvCall?

                Originally posted by burch View Post
                This should work, assuming you have a valid Authorization header:
                Amazing. Worked flawlessly the very first time - thank you.
                In the words of the old guys - "Kudos to you!"
                William Gilligan - Orange Marmalade, Inc.
                www.OrangeMarmaladeinc.com

                Comment


                  #9
                  Re: passing array via MvCall?

                  Originally posted by wmgilligan View Post
                  Amazing. Worked flawlessly the very first time - thank you.
                  In the words of the old guys - "Kudos to you!"
                  Ok - seems I have another issue related to this...

                  When using the code as plain text, it works flawlessly.
                  However, when I use a while statement, I get a "bad gateway" error every time ...

                  Example (simplified) - this fails.....
                  Code:
                  --> Get records from database. 
                  
                  <MvAssign name="l.count" value="1">
                  <MvCAPTURE VARIABLE = "l.json">{"contacts":[
                  <MvWhile expr="{ NOT batch.d.EOF }">
                     <MvIf expr="{ l.count LT 3 }">
                           {
                              "email":"<MvEval expr="{batch.d.email}">"
                          },
                        <MvElse>
                        {
                              "email":"<MvEval expr="{batch.d.email}">"
                          }
                        </MvIf>
                     <MvAssign name="l.count" value="{ l.count + 1 }">
                     <MvSkip>
                  </MvWhile>
                  ]}
                  </MvCAPTURE>
                  But this works:
                  <MvAssign name="l.count" value="1">
                  Code:
                  <MvCAPTURE VARIABLE = "l.json">{"contacts":[
                  <MvWhile expr="{ NOT vrbatch.d.EOF }">
                     <MvIf expr="{ l.count LT 3 }">
                           {
                              "email":"[email protected]"
                          },
                        <MvElse>
                        {
                              "email":"[email protected]"
                          }
                        </MvIf>
                     <MvAssign name="l.count" value="{ l.count + 1 }">
                     <MvSkip>
                  </MvWhile>
                  ]}
                  </MvCAPTURE>
                  I have checked all resulting text, and they appear identical.
                  William Gilligan - Orange Marmalade, Inc.
                  www.OrangeMarmaladeinc.com

                  Comment


                    #10
                    Re: passing array via MvCall?

                    FIXED. trim the emails.
                    Seems some had blank spacing that was messing things up.
                    William Gilligan - Orange Marmalade, Inc.
                    www.OrangeMarmaladeinc.com

                    Comment

                    Working...
                    X