iOS SWIFT: statusCode 403

Solved
Highlighted
New Member
2 0 1

Hi guys.
We are developing a native iOS app based on SWIFT with ability to make purchases in Shopify. I created a private app, and try to send any requests (for example - get shop name, products). In response, I always get "http(statusCode: 403) The operation couldn’t be completed. (MobileBuySDK.Graph.QueryError error 1.)"

Here is an example of my code:

let shopDomain = "zerofydevtest.myshopify.com"
let apiKey = "api key for private app"
let client: Graph.Client = Graph.Client(shopDomain: shopDomain, apiKey: apiKey)
let query = Storefront.buildQuery { $0
    .shop { $0
     .name()
    }
   }   let task = client.queryGraphWith(query) { response, error in
    if let response = response {
     let name = response.shop.name
    } else {
     error.debugPrint()
    }
   }
   task.resume()
let limit = 100
   let productLimit = 25
   var cursor: String?
   var productCursor: String?   let query = Storefront.buildQuery { $0
    .collections(first: Int32(limit), after: cursor) { $0
     .pageInfo { $0
      .hasNextPage()
     }
     .edges { $0
      .cursor()
      .node { $0
       .id()
       .title()
       .descriptionHtml()
       .image(maxWidth: ShopifyClientQuery.maxImageDimension, maxHeight: ShopifyClientQuery.maxImageDimension) { $0
        .transformedSrc()
       }       .products(first: Int32(productLimit), after: productCursor) { $0
        .fragmentForStandardProduct()
       }
      }
     }
    }
   }   let task = self.client.queryGraphWith(query) { query, error in
    if let query = query {
     let edges = query.collections.edges
     let pageInfo = query.collections.pageInfo
    } else {
     error.debugPrint()
    }
   }
   task.resume()


Both of these requests return error 403.
I enabled the option "Allow this app to access your storefront data using the Storefront API" and got "Storefront access token" but I'm not sure where I have to use it in mobile-buy-sdk-ios.

Could please advise on the matter?
Best regards

1 Like
Highlighted
Shopify Staff
Shopify Staff
502 98 90

This is an accepted solution.

Hey @RomanShepel 

You will want to ensure you are using the Storefront Access Token vs. the API Key in your application. 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


2 Likes
Highlighted
New Member
2 0 1

Hi @vix , thank you for your response! Now it works!

0 Likes
Highlighted
New Member
4 0 0

I am slow here. How do you set the header in the mobile buy API? Thanks!

0 Likes