Hello Chris, i know this is like a year later, but i am learning, i know you asked which API that we are interested in seeing you show how to connect, anyways, i need to connect to REST API Shift4Shop, to retrieve my orders, trying to create an app that will monitor my orders. i think i learned enough from your videos, the issue is the jsonObject format is a little confusing of what i need to put in it. so any help would be greatly appreciated. i can send you a link for the api documentation or the project i am working n so far. maybe i am asking too much, I did everything as you show in the How To Work With Any API (API Tutorial using URL Requests), i keep getting Error parsing response data.
i have the PrivateKey, the Token, i think i just need to know the format and what goes in the let jsonObject = , i need to get a list of my orders, i think i should use “GET”, but in your video you use “POST”
any help is appreciated.
i can send my project or the link for the REST API .
regards.
Ibrahim
here is my code ( my Private key & Token are correct on my end, but will alter them for security)
// ViewController.swift
// SlipGrip Mobile
//
// Created by Ibrahim Kawar on 10/4/22.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
//URL
let url = URL(string: "https://apirest.3dcart.com/3dCartWebAPI/v1/Orders?")
guard url != nil else {
print("Error creating url object")
return
}
// URL Request
var request = URLRequest(url: url!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10)
// Specify the header
let header = ["Content-Type": "application/xml", "Accept": "application/json", "SecurURL": " https://slipgripcarmounts-com.3dcartstores.com/", "PrivateKey": "c8885c354e34876a35ad21d98429139b", "Token": "e3686bf39eae59a416a400e40306c57d5b"]
request.allHTTPHeaderFields = header
// Specify the body
let jsonObject = ["url": "https://apirest.3dcart.com/3dCartWebAPI/v1/Orders?", "orderstatus": "NEW"]
do {
let requestBody = try JSONSerialization.data(withJSONObject: jsonObject, options: .fragmentsAllowed)
request.httpBody = requestBody
}
catch {
print("Error creating the data object fron json")
}
// Set the request type
request.httpMethod = "POST"
// Get the URLSession
let session = URLSession.shared
// Ceate the data task
let dataTask = session.dataTask(with: request) { (data, response, error) in
// check for errors
if error == nil && data != nil {
// try to parse out the data
do {
let dictionary = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! [String:Any]
print("THANK YOU LORD!!!")
print("Success: \(dictionary)")
}
catch {
print("Error parsing response data")
}
}
}
// Fire off the data task
dataTask.resume()
}