-2

Is it possible to use Alamofire like so:

AF.request("https://api.smartsheet.com/2.0/sheets/",method: .get).responseJSON { Data in debugPrint(Data.result) }

in Swift to interact with the Smartsheet API?

I'd hope that swapping out the current https with an reasonable one would do what I want.

I would like to get information from the API. The error thrown is that I don't have authorization for the API:

Swift.Result<Any, Alamofire.AFError>.success({ errorCode = 1004; message = "You are not authorized to perform this action."; refId = 1ca40zco0itdd; }).
  • What do you mean by "interact with the API"? What are you actually trying to achieve? And what's the result you get with your current code? – Dávid Pásztor Aug 04 '20 at 16:46
  • The goal is to make an app that will take the current location, some inputs of a user and post it to the Smartsheet API. Also, I would like to get information from the API. The error thrown is that I don't have authorization for the API: Swift.Result.success({ errorCode = 1004; message = "You are not authorized to perform this action."; refId = 1ca40zco0itdd; }). I think the swift tag is inappropriate for this question so I'll remove it. – Chris Jacobs Aug 04 '20 at 16:53
  • I think you should edit and update your question instead of writing clarifications in a comment. – Scratte Aug 04 '20 at 17:08

1 Answers1

0

I just needed to understand end points better and read the documentation on Alamofire. I changed my code to the following and it worked!

let headers: HTTPHeaders = [
           "Authorization": "Bearer " + api_key_smartsheet,
          "Accept": "application/json"
      ]

 AF.request("https://api.smartsheet.com/2.0/sheets/?includeAll=True", method: .get,headers: headers).responseJSON { response in
          debugPrint(response)
      }'''