Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I peeked at the API doc and from the looks of it, you don't actually pass an object in the request. You pass a tag/value pair list of strings.</p> <p>Here is an excerpt from the API documentation showing an example for creating a bank account:</p> <pre><code>curl https://api.balancedpayments.com/v1/bank_accounts \ -u ak-test-oAm876JsVLRmHwrswIGZ1kaelufk8Cmy: \ -d "routing_number=121000358" \ -d "type=checking" \ -d "name=Johann Bernoulli" \ -d "account_number=9900000001" </code></pre> <p>In order to understand this example, you'll need the reference from curl, found <a href="http://curl.haxx.se/docs/manpage.html" rel="nofollow noreferrer">here</a>.</p> <p>-u Passes the user ID "ak-test-oAm876JsVLRmHwrswIGZ1kaelufk8Cmy" with no password.</p> <p>-d Indicates a tag/value pair in the HTTP POST body. As you can see, there are four lines, each representing one attribute of a bank account.</p> <p>So unless something is terribly wrong, the following code ought to do it:</p> <pre><code>Dim postData As String = "routing_number=121000358&amp;type=checking&amp;name=Johann+Bernoulli&amp;account_number=9900000001" Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) request.ContentType = "application/x-www-form-urlencoded" request.ContentLength = byteArray.Length Dim dataStream As Stream = request.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() </code></pre> <p>If this isn't working for you please post additional specifics about the problem.</p> <p>Incidentally, there's a trick to putting together a well-formed tag value pair list. If you create a NameValueCollection using the ParseQueryString static method, it is created internally as an HttpValueCollection and can be used to render querystrings. Check it out:</p> <pre><code>Dim myCollection as NameValueCollection = HttpUtility.ParseQueryString(""); //Create empty collection myCollection["routing_number"] = "121000358"; myCollection["type"] = "checking"; myCollection["name"] = "Johann Bernoulli"; myCollection["account_number"] = "99900000001"; Dim postData as String = myCollection.ToString(); //Magic!! Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData) </code></pre> <p>This will be a lot easier than building the strings yourself when your object has a lot of properties and/or contains data that require escaping.</p> <hr> <h2>Passing an object with JSON</h2> <p>The API documentation lacks any examples demonstrating the passing of objects. Seems we're going to have to guess. Boo!</p> <p>I poked about on the web and it seems pretty typical and standard for a RESTful service to pass complex data structures using a format known as a <a href="http://www.json.org/" rel="nofollow noreferrer">json string</a> (JavaScript Object Notation) which looks something like this:</p> <p>"address" : { "line1" : "This is line 1 of the address","city":"Seattle","state":"WA"}</p> <p>Here is a much more <a href="http://json.org/example.html" rel="nofollow noreferrer">elaborate example</a> but I would suggest starting simple just to ensure this is what the API wants. </p> <p>Try hardcoding a simple json string following this pattern and pass it to the service just to see if it works. </p> <p>If it does the trick, we can look at easier ways to build the json. If you're on .NET 4.5, check <a href="http://msdn.microsoft.com/en-us/library/system.json.jsonvalue(v=vs.95).aspx" rel="nofollow noreferrer">here</a>. Otherwise you have to do just a little bit more work and implement your own function <a href="https://stackoverflow.com/questions/1056121/how-to-create-json-string-in-c-sharp">like this one</a> or as explained in <a href="http://weblogs.asp.net/scottgu/archive/2007/10/01/tip-trick-building-a-tojson-extension-method-using-net-3-5.aspx" rel="nofollow noreferrer">this article</a>.</p> <p>But the first trick is to verify my guess. It's a pretty good guess since the Balanced Payments API uses json in the response messages (as can be clearly seen in the examples). Try it and out and let me know what you find.</p> <hr> <h2>Passing an object using the Balanced Payments API's funny syntax</h2> <p>OK I kept poking around that API document and found a <a href="https://docs.balancedpayments.com/current/api.html?language=bash#credit-a-new-bank-account" rel="nofollow noreferrer">good example of passing an object</a>.</p> <pre><code>curl https://api.balancedpayments.com/v1/marketplaces/TEST-MP5is34cQM5VCKcHcIfXxLGw/credits \ -u ak-test-oAm876JsVLRmHwrswIGZ1kaelufk8Cmy: \ -d "amount=10000" \ -d "bank_account[routing_number]=121000358" \ -d "bank_account[type]=checking" \ -d "bank_account[name]=Johann Bernoulli" \ -d "bank_account[account_number]=9900000001" </code></pre> <p>I infer from this example that the way to pass an "object" is to provide the object name and include its properties, one by one, in square brackets.</p> <p>So in your case it ought to be</p> <pre><code>Dim postData as String = "name=John Doe&amp;address[line1]=123 Main St&amp;address[city]=Baltimore&amp;address[state]=MD&amp;address[postal_code]=21224&amp;email=jdoe@domain.com" </code></pre> <p>etc.</p> <p>Give that a try. Third time is the charm?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload