(Solved) – VBA: Authentication issues for PUT request

(solved)-–-vba:-authentication-issues-for-put-request

I’m having trouble authenticating the below PUT request to the Freshdesk API v2 from Excel VBA. I’m new to this (VBA), but I think I’m SO CLOSE, can anyone tell me what’s wrong with this code and why I’m getting a debug message saying

{“code”:”invalid_credentials”,”message”:”You have to be logged in to perform this action.”}?

Sub PutJSON()

  Dim URL As String
  Dim JSONString As String
  Dim objHTTP As New WinHttpRequest
  Dim token As String
  Dim response As String

  URL = "https://ourcompany.freshdesk.com/api/v2/time_entries/14001545629"
  token = "1234567890:X"

  objHTTP.Open "PUT", URL, False
  objHTTP.setRequestHeader "Authorization", "Bearer " & token
  objHTTP.setRequestHeader "Content-Type", "application/json"

  JSONString = "{""billable"" : true, ""note"" : ""Updated from Excel!"", ""timer_running"" : false, ""agent_id"" : 14036310050, ""ticket_id"" : 37784, ""time_spent"" : ""02:00""}"
  objHTTP.send JSONString
  response = objHTTP.responseText

  Debug.Print response

End Sub

Leave a Reply

Your email address will not be published. Required fields are marked *