Issue with donation request

64 views
Skip to first unread message

Atrijit Dasgupta

unread,
Dec 11, 2012, 11:32:11 PM12/11/12
to globalgi...@googlegroups.com
Hi
I am sending the XML as:
<?xml version='1.0' encoding='UTF-8'?>
<donation>
<auth_request>
<email>atr...@gmail.com</email>
<password>fgfgfgfg</password>
<api_key>xxxxxxxx</api_key>
<auth_request>
<refcode>1355285276421#tki...@7casp.com</refcode>
<transactionId>1355285276421#tki...@7casp.com</transactionId>
<email>tki...@7casp.com</email>
<amount>92</amount>
<project><id>1733</id></project><payment_detail><firstname></firstname><lastname></lastname><address>23 Bol Avenue</address><city>Bangalore</city><state>Karnataka</state><iso3166CountryCode>356</iso3166CountryCode><zip>560071</zip><creditCardNumber>9228722562782637</creditCardNumber><securityCode>212</securityCode><expiryDateMonth>12</expiryDateMonth><expiryDateYear>2019</expiryDateYear></payment_detail></donation>

And the Java code snippet that makes the post is:

private String getResponse(String URLStr) {
String requestXml = this.getRequestXml();
System.out.println(requestXml);
URL url = null;
try {
url = new URL(URLStr);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpURLConnection hConn = null;
try {
hConn = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
hConn.setRequestMethod("POST");
} catch (ProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
hConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
hConn.setDoInput(true);
hConn.setDoOutput(true);
hConn.setUseCaches(false);
hConn.setRequestProperty("Content-Language", "en-US");
hConn.setRequestProperty("Content-Length", ""
+ Integer.toString(requestXml.getBytes().length));
hConn.setAllowUserInteraction(true);
DataOutputStream printout = null;
try {
printout = new DataOutputStream(hConn.getOutputStream());
if(printout == null){
System.out.println("Something is Rotten");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
printout.writeBytes(requestXml);
printout.flush();
printout.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
BufferedReader in = null;
try {
in = new BufferedReader(new java.io.InputStreamReader(hConn
.getInputStream()));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String line;
StringBuffer responseBuf = new StringBuffer("");
try {
while ((line = in.readLine()) != null) {
responseBuf.append(line);

}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(responseBuf.toString());
hConn.disconnect();

return responseBuf.toString();
}


I am getting this response: 
java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.globalgiving.org/api/secure/givingservice/donations?is_test=true&api_key=xxxxxxxx

I am passing the api_key in two places: in the params with the URL, aand within <auth_request> tags inside the XML.

Can someone tell me where I am going wrong? Once I see the response XML I can write the parser for it and close this.

I have masked the actual email ids and api key values,project ids etc, of course.

Atrijit


Steve Rogers

unread,
Dec 12, 2012, 10:09:23 AM12/12/12
to globalgi...@googlegroups.com
Hi,  First of all have you requested for your API key to be able to post donations? Please review the terms of conditions document here: https://www.globalgiving.org/to-go/terms-of-service.html

ALso, submitting a donation request requires an authorization token to be obtained prior to the donations call. https://www.globalgiving.org/to-go/submit-a-donation.html

Do let me know if this helps!
Steve


On Tuesday, December 11, 2012 11:32:11 PM UTC-5, Atrijit Dasgupta wrote:
Hi
I am sending the XML as:
<?xml version='1.0' encoding='UTF-8'?>
<donation>
<auth_request>
<email>atr...@gmail.com</email>
<password>fgfgfgfg</password>
<api_key>xxxxxxxx</api_key>
<auth_request>
<refcode>1355285276421#tkimura@7casp.com</refcode>
<transactionId>1355285276421#tkim...@7casp.com</transactionId>

Atrijit Dasgupta

unread,
Dec 13, 2012, 4:17:19 AM12/13/12
to globalgi...@googlegroups.com
Hi Steve
Thanks for the reply. Yes, I have acquired the API Key needed to post donations. In the code I pasted here, I masked the value.
I missed out on the access token part I think. Can you tell me, is this access token to be collected individually for each request? Or does this have a time bound validity?

Thanks

Atrijit

Atrijit Dasgupta

unread,
Dec 13, 2012, 4:20:24 AM12/13/12
to globalgi...@googlegroups.com
Hi Steve,
Pl ignore my last reply...the documentation says it is per session. Let me try that out, would revert.

Thanks

Atrijit

On Wednesday, 12 December 2012 20:39:23 UTC+5:30, Steve Rogers wrote:

Atrijit Dasgupta

unread,
Dec 13, 2012, 5:23:16 AM12/13/12
to globalgi...@googlegroups.com
Hi Steve,
When I try getting the auth token I get the same error:

<?xml version='1.0' encoding='UTF-8'?><auth_request><user><email>SOME-EMAIL</email><password>SOME-PASSWORD</password></user><api_key>SOME-API-KEY</api_key></auth_request>

2012-12-13 15:48:31,796 ERROR [STDERR] java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.globalgiving.org/api/userservice/tokens

I am using the same method as before to post the request. Any ideas what could be going wrong?

Thanks

Atrijit


On Wednesday, 12 December 2012 20:39:23 UTC+5:30, Steve Rogers wrote:
Reply all
Reply to author
Forward
0 new messages