API - HTTP POST Error 500, an internal error has occured
Hi - I've spent hours trying to figure why the POST below (in Swift) fails. Status code is HTTP 500 which according to the doc means "Wild Apricot's server has encountered an error and cannot fulfill the request." API Key and authentication are all good since GET requests to the same API work fine.
The event is very simple defined to have only fields first and last name and email. The event is public. I've triple checked all the Id's - event, contact, reg type id etc.
Any ideas much appreciated..
Thanks
David
Post URL is https://api.wildapricot.org/v2/accounts/{acctid}/EventRegistrations/
Post Body is - {"RegistrationTypeId":2394243,"Event":{"Id":1805601},"RegistrationFields":[{"Value":"John","FieldName":"First name"},{"Value":"Barrett","FieldName":"Last name"},{"Value":"fred@gmail.com","FieldName":"e-Mail"}],"Contact":{"Id":26450615}}
Response is -
Status 500
{"Message":"An internal error has occured. Please contact Wild Apricot support.\r\n Request ID:8bc7b4458b4c47b784f9c45dcf3f34ce."}
Swift Code
println("\nPOST Url ----------->(url!)\n")
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "POST"
let auth = NSString(format: "Bearer %@", accessToken)
request.setValue(auth, forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Accept")
let params /: [AnyObject]/ = [
"Event": ["Id": 1805601], //ev 4
"RegistrationTypeId": 2394243, // for ev 4
"Contact": ["Id": 26450615], //mem2
"RegistrationFields": [
["FieldName": "First name", "Value": "John"],
["FieldName": "Last name", "Value": "Barrett"],
["FieldName": "e-Mail", "Value": "fred@gmail.com"],
] /*,
"IscheckedIn": false,
"IsPaid": false,
"ShowToPublicIsPaid": true,
"Memo":"Important member",
"GuestRegistrationsSummary": ["NumberOfGuests": 1] */
] as Dictionary
var err: NSError?
var bodyData = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err)
var bodyStr = NSString(data: bodyData!, encoding: NSUTF8StringEncoding)!
println("body ----------->(bodyStr)")
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &err)
var response: NSURLResponse?
var error: NSErrorPointer = nil
var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: &response, error: error)
var reply = NSString(data: data!, encoding: NSUTF8StringEncoding)
//println("\n\nerror ----------->(error)")
println("\nresponse ----------->(response!)")
println(reply!)
-
Dmitry Smirnov commented
Your code looks correct. I think this problem is connected with creating / updating new contact without membership. This is known issue, it will be fixed soon.