0

When calling "cart_customer.addresses" magento API in order to place an order from iOS, I got the HTTP Error 500. However, it works properly on my testing api page written by PHP by following the example here.

I don't know why HTTP 500 Error occurred when I call it from iOS. Below is my Objective-C source code:

// Create billing address dictionary
NSMutableDictionary *billingAddressDict = [[[NSMutableDictionary alloc] init] autorelease];

[billingAddressDict setObject:@"billing" forKey:@"mode"];
[billingAddressDict setObject:@"testFirstname" forKey:@"firstname"];
[billingAddressDict setObject:@"testLastname" forKey:@"lastname"];
[billingAddressDict setObject:@"testCompany" forKey:@"company"];
[billingAddressDict setObject:@"testStreet" forKey:@"street"];
[billingAddressDict setObject:@"testCity" forKey:@"city"];
[billingAddressDict setObject:@"testRegion" forKey:@"region"];
[billingAddressDict setObject:@"testPostcode" forKey:@"postcode"];
[billingAddressDict setObject:@"SG" forKey:@"country_id"];
[billingAddressDict setObject:@"0123456789" forKey:@"telephone"];
[billingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_shipping"];
[billingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_billing"];

// Create shipping address dictionary
NSMutableDictionary *shippingAddressDict = [[[NSMutableDictionary alloc] init] autorelease];

[shippingAddressDict setObject:@"shipping" forKey:@"mode"];
[shippingAddressDict setObject:@"testFirstname" forKey:@"firstname"];
[shippingAddressDict setObject:@"testLastname" forKey:@"lastname"];
[shippingAddressDict setObject:@"testCompany" forKey:@"company"];
[shippingAddressDict setObject:@"testStreet" forKey:@"street"];
[shippingAddressDict setObject:@"testCity" forKey:@"city"];
[shippingAddressDict setObject:@"testRegion" forKey:@"region"];
[shippingAddressDict setObject:@"testPostcode" forKey:@"postcode"];
[shippingAddressDict setObject:@"SG" forKey:@"country_id"];
[shippingAddressDict setObject:@"0123456789" forKey:@"telephone"];
[shippingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_shipping"];
[shippingAddressDict setObject:[NSNumber numberWithInt:0] forKey:@"is_default_billing"];
request = [[XMLRPCRequest alloc] initWithURL: url];

NSArray *addressArray = [NSArray arrayWithObjects:shippingAddressDict, billingAddressDict, nil];

params = [NSArray arrayWithObjects:[NSNumber numberWithInt:cartId], addressArray, nil];
[request setMethod:@"call" withParameters:[NSArray arrayWithObjects:sessionId, @"cart_customer.addresses", params, nil]];

response = [self getResponse:request];

This is the definition of getResponse function:

- (XMLRPCResponse *)getResponse: (XMLRPCRequest *)request {
    NSError *error = nil;
    XMLRPCResponse *response = [XMLRPCConnection sendSynchronousXMLRPCRequest:request error:&error];

    if (nil != error) {
        NSLog(@"error = %@", [error description]);
        return nil;
    }

    if (nil == response) {
        return nil;
    }

    if ([response isFault]) {
        NSLog(@"Fault with code: %d means: %@", [response.faultCode intValue], response.faultString);
        return nil;
    }

    return [[response retain] autorelease];
}

I use Magento 1.5.0.1

Important Update:

When I try removing 'telephone' from the dictionary, the server returns an validating message: Please enter a telephone number. But if I place 'telephone' there again, the error will occur as I showed you. What wrong with the telephone number, I tried using Singapore number (8 digits) as well as US number (digit only, no space, no '-') but the error still remains. Anyway, the official example provided by magento used a dummy one: "0123456789" and it works, so it should work for me too, right?

xyz
  • 2,277
  • 2
  • 25
  • 41
Quan
  • 473
  • 7
  • 16
  • 1. it would be very useful if you would add more info regarding `XMLRPCRequest` & `XMLRPCResponse` you're using as they don't exist in `Cocoa`. 2. I would suggest you use `SOAP` instead. In pass i've encountered many issues when trying to use `XML-RPC` along with `Magento` – xyz May 19 '12 at 10:24
  • 1. This is XMLRPC source code that I'm using: http://www.mediafire.com/?wiba28yx6rl4qf1 . 2. I will try it later. Thanks for your comment. – Quan May 19 '12 at 15:48
  • Were you able to find a solution? Is this an issue in Magento? – detj Jun 12 '14 at 22:58

0 Answers0