I am writing a Mac app using objective-c. It is a Shopify private app, basically meaning the authentication is simple. Just specify your credentials in the url. I am able to retrieve my products just fine, comes back as JSON data. Using the same URL as specified in the docs, I am unable to add a product. I do not get an error, but the product does not get posted. Here is the current code:
NSData* JSONItemAsData = [self addJSONDataForListingItem:listingItem];
NSMutableString* urlString = [NSMutableString stringWithFormat:@"https:/
NSURL* shopifyUrl = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:shopifyUrl];
request.HTTPMethod = @"POST";
request.HTTPBody = JSONItemAsData;
NSURLSessionConfiguration* configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.timeoutIntervalForResource = 40.0f;
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
NSURLSessionDataTask* dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data,
NSURLResponse *response,
NSError *error) {
if (error) {
NSLog(@"error: %@",error);
}
else{
[self processData:data response:response error:error forCallType:callTypeAddItem];
}
}
];
[dataTask resume];
Here is the JSON data:
{
product = {
"inventory_quantity" = 1;
price = 25;
tags = test;
title = "test number two";
};
And here is the response:
<NSHTTPURLResponse: 0x610000627c00> { URL: https:/
"Cache-Control" = "no-cache, no-store";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Security-Policy" = "default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https:/
"Content-Type" = "text/html; charset=utf-8";
Date = "Wed, 27 Sep 2017 18:17:08 GMT";
P3P = "CP=\"NOI DSP COR NID ADMa OPTa OUR NOR\"";
"Referrer-Policy" = "origin-when-cross-origin";
Server = nginx;
"Shopify-Auth-Mechanisms" = password;
"Strict-Transport-Security" = "max-age=7776000";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding";
"X-Content-Type-Options" = "nosniff, nosniff, nosniff";
"X-Dc" = "chi2,ash";
"X-Download-Options" = noopen;
"X-Frame-Options" = DENY;
"X-Permitted-Cross-Domain-Policies" = none;
"X-Request-ID" = "aa8c7214-3ed2-4c6a-9f63-057ccef7e08b";
"X-ShardId" = 8;
"X-ShopId" = 19762815;
"X-Shopify-Login-Required" = true;
"X-Sorting-Hat-PodId" = "8, 8";
"X-Sorting-Hat-PodId-Cached" = "0, 0";
"X-Sorting-Hat-Section" = "pod, pod";
"X-Sorting-Hat-ShopId" = "19762815, 19762815";
"X-Sorting-Hat-ShopId-Cached" = "0, 0";
"X-XSS-Protection" = "1; mode=block; report=/xss-report?source%5Baction%5D=login&source
the status code is 200, but I expected a 201. I have also tried using an NSURLSessionUploadTask, same result.