Search code examples
swifthttprequestquickbooksintuit-partner-platform

Quickbooks create a TimeActivity


How can I make a POST request to create a time activity for my company on Quickbooks from a mobile app? I've got authorisation working fine, now I just need to know how to create items. For the HTTPBody of the request, what should I enter?


Solution

  • let url = NSURL(string:”Some Fancy URL“)
    let request = NSMutableURLRequest(URL: url!)
    var err: NSError?
    
    var bodyData = “myBodyKey=myBodyValue“ as NSString
    request.HTTPMethod = "POST"
    request.HTTPBody = bodyData.dataUsingEncoding(NSUTF8StringEncoding)!
    

    This is (a way) of setting the HTTPBody of a request

    In regards to Quickbooks, they have a api documentation regarding the time activity.

    They explain here how to send a JSON Create Request.
    And use as example

    {
        "TxnDate":"2013-01-28",
        "NameOf":"Vendor",
        "VendorRef":{
            "value":"61"
        },
        "CustomerRef":{
            "value":"60"
        },
        "DepartmentRef":{
            "value":"3"
        },
        "ItemRef":{
            "value":"4"
        },
        "ClassRef":{
            "value":"100100000000000321202"
        },
        "BillableStatus":"Billable",
        "Taxable":true,
        "HourlyRate":251,
        "BreakHours":1,
        "BreakMinutes":0,
        "StartTime":"2013-01-28T08:00:00-08:00",
        "EndTime":"2013-01-28T17:00:00-08:00",
        "Description":"Single activity time sheet",
        "domain":"QBO",
        "sparse":false
    }
    

    As A data you would need to create a dictionary and encode this as json.