I have this code where I am trying to create a new customer on my website using prestashop mode. But I keep getting error in the response
NSString *xmlPath = [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"xml"];
NSString *xmlStr = [[NSString alloc] initWithContentsOfFile:xmlPath encoding:NSUTF8StringEncoding error:nil];
NSString *encodedurlstring = (__bridge NSString*) CFURLCreateStringByAddingPercentEscapes (NULL, (__bridge CFStringRef) xmlStr, NULL, (CFStringRef)@"!*'();:@&=+$,/?%#[]",kCFStringEncodingUTF8);
NSString *urlStr = [NSString stringWithFormat:@"http://passkey:@farma-web.it/api/customers/?Xml=%@",encodedurlstring];
NSURL *webURL = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:webURL];
[request setHTTPMethod:@"POST"];
[request setValue: @"text/xml" forHTTPHeaderField: @"Content-Type"];
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *response = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"response - %@",response);
The XML that I have attached is
<prestashop>
<customers>
<customer>**I DO NOT KNOW WHAT TO WRITE HERE**</customer>
<email>abc@abc.com</email>
<passwd>12344321</passwd>
<firstname>ABC</firstname>
<lastname>DEF</lastname>
</customers>
</prestashop>
The response that I am getting is
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message>
</error>
</errors>
</prestashop>
I ran into similar issues and here's what I found out on prestashop version 1.6.0.9:
1) As @adrien-g points out, change from
define('_PS_MODE_DEV_', false);
to define('_PS_MODE_DEV_', true); http://doc.prestashop.com/display/PS16/Setting+Up+Your+Local+Development+Environment#SettingUpYourLocalDevelopmentEnvironment-Displayingerrormessages2) Next you will start seeing more meaningful errors like the one simulated with this CURL command:
3) Then some experimentation like adding the
passwd
andprestashop
tags will finally lead you down a path where you see customers successfully being created:Worth noting:
<?xml ...><prestashop></prestashop>
versus xml=<?xml ...><prestashop></prestashop>
doesn't make any difference in the version I played around with.<prestashop>
versus<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
doesn't make any difference in the version I played around with."customer" is not an independant field but a container for all the other fields like firstname, lastname, email, etc.
The best way to create a customer is to retrieve and blank sheet and to fill it with your data: http://your-prestashop.com/api/customers?schema=blank