Method Community

 

HTTP Post an array?

Last post 10-04-2013 2:02 PM by Method_David. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 09-29-2013 7:01 PM

    HTTP Post an array?

    The information at https://www.methodintegration.com/MethodAPI/service.asmx?op=MethodAPIInsertV2 appears to indicate that you can call the API with a simple HTTP post. I would like to avoid the overhead of SOAP. I tried guessing a few delimters to pass the arrInsertValueArray and arrInsertValueArray but I didn't get anywhere. Is this possible?

  • 09-30-2013 12:49 PM In reply to

    Re: HTTP Post an array?


    Hi nsmith_piano,

    It can be done....but without know what language you are using, I'm not sure where to point you.

    I'm gonna advise in this case you google 'HTTP Post an array?'. That should help you find the solution pretty quick.

     

    Dave

     

     

  • 09-30-2013 1:16 PM In reply to

    Re: HTTP Post an array?


    Thanks for your response Dave.

    I am hoping to use Google App Engine with Python. I am using the urllib.urlencode() function. In my dictionary I have {arrInsertFieldArray : ['name', 'assignedTo']}. I pass the dictionary to urlencode() and send the resulting string to Method, but I am not getting a good response. I don't have my app in front of me now. I'll post specific examples later.

    The content type in the post example in the documentation is x-www-form-urlencoded. I understand that content to be form data encoded as name/value pairs, similar to a URI query string.

    If there is one name "arrInsertFieldArray" and multiple values in an array, how would the Method server like to receive multiple values?

    I was able to get my app to talk to Method in simple requests like MethodAPITableListV2 that only reqired single-valued parameters.

  • 09-30-2013 8:56 PM In reply to

    Re: HTTP Post an array?

    Here is my Python:

    import webapp2
    import urllib
    from google.appengine.api import urlfetch

    class MainHandler(webapp2.RequestHandler):

        def get(self):
            self.response.headers['Content-Type'] = 'text/plain'

            url = 'https://www.methodintegration.com/MethodAPI/service.asmx/MethodAPIInsertV2'
            form_fields = {
              "strCompanyAccount": "myAccount",
              "strLogin": "myUser",
              "strPassword": "myPassword",
              "strSessionID": "",
              "strTable":"Campaign",
              "arrInsertFieldsArray": ["Name","AssignedTo"],
              "arrInsertValueArray": ["Test","Randy"],
            }
            form_data = urllib.urlencode(form_fields)
            result = urlfetch.fetch(url=url,
                payload=form_data,
                method=urlfetch.POST,
                headers={'Content-Type': 'application/x-www-form-urlencoded'})
            self.response.write('posted: ' + form_data + '<br/>result is now: ' + result.content)

            
    app = webapp2.WSGIApplication([
        ('/', MainHandler)
    ], debug=True)

    It is posting this:

    arrInsertFieldsArray=%5B%27Name%27%2C+%27AssignedTo%27%5D&strSessionID=&strPassword=myPassword&strCompanyAccount=myAccount&strTable=Campaign&strLogin=myPassword&arrInsertValueArray=%5B%27APICampaign%27%2C+%27Randy%27%5D

    The response content is:

    It does not appear the field '['Name', 'AssignedTo']' exists in the table.

  • 10-04-2013 2:02 PM In reply to

    Re: HTTP Post an array?

    Hi nsmith_piano

    Sorry about the delay...rough week...

    I'm not a python expert but is that the correct way to declare an array in python?

    Why don't you declare the array outside your call to form_fields = .... and then just pass the array?

     

    Dave


Page 1 of 1 (5 items)