SWIFT POST products.json Returning error code 200 with nil body

New Member
4 0 0

As the title suggests, I am attempting to add a new product to my store via the Admin API products.json via POST.


I did some searching in the forums on the topic, and I checked two things. One, I do have read/write access enabled for products. Two, I "believe" I have disabled cookies in the request with httpShouldHandleCookies = false, as this seems to be the most likely cause. Here is my code:


class func createNewSerializedRentalProduct(rentalInstrument:AimsiRentalInstrument, serializedInstrument:AimsiSerializedInstrument, completion: @escaping (ProductViewModel) -> Void) {
        let urlString = "https://" + apiKey + ":" + apiPassword + "@mystore.myshopify.com/admin/api/2019-07/products.json"
        guard let url = URL(string: urlString) else {return}
        var request = URLRequest(url: url)
        request.httpMethod = "POST"
        let session = URLSession.shared
        request.httpShouldHandleCookies = false
        let parameters:[String:Any] = ["product":["title":"\(rentalInstrument.category) Rental | \(rentalInstrument.sku)", "body_html":rentalInstrument.instrumentName, "vendor":"Yandas Music", "product_type":"\(rentalInstrument.category) Rental", "variants":["option1":"Serial Number", "price":"50.00", "sku":serializedInstrument.serial]]]
        do {
            request.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
        } catch let error {

        //HTTP Headers
        request.addValue("application/json", forHTTPHeaderField: "Content-Type")
        request.addValue("application/json", forHTTPHeaderField: "Accept")
        session.dataTask(with: request) { (data, response, error) in
            if error != nil {
            } else {
                if let data = data {
                    let json = JSON(data)
Shopify Expert
9928 77 1442

Do you have an example of the data you're sending to the API? That's a good place to start as we only see aspects of your code and the not the result of it.

If you won't want to share - that's aok. Take the response and pop it into Postman (or similar) instead. If that call then works you can be quite confident it's down to the set up of your stack. 


If you're really, really stuck then grab the Request ID from the headers in the response and paste it here.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
New Member
4 0 0

I put the request into postman, which revealed I did incorrectly format my JSON. After changing the formatting in postman the POST request goes through normally.


I made the correction in my SWIFT project, but I'm still getting the same error. It's sending me to the login screen, as if I'm not logged in? Here is the JSON in the body of the request:


  "product" : {

    "title" : "Clarinet Rental | USEDARTLEYCLART",

    "body_html" : "Used Artley Clarinet",

    "variants" : [


        "sku" : "7000813",

        "price" : "50.00",

        "option1" : "Serial Number"



    "vendor" : "Yandas Music",

    "product_type" : "Clarinet Rental"



New Member
4 0 0

The only difference between the two request bodies is that SWIFT likes to put in a few spaces, as you can see above. Would this possibly cause the error I'm experiencing?