1
Const vbDoubleQuote As String = """" 'represents 1 double quote (")
Const vbSingleQuote As String = "'" 'represents 1 single quote (')
Private WithEvents myOlItems  As Outlook.Items

Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
  Set olApp = Outlook.Application
  Set objNS = olApp.GetNamespace("MAPI")
  Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub myOlItems_ItemAdd(ByVal item As Object)

Dim Msg As Outlook.MailItem
Dim Title As String
Dim Body As String
Dim Message As String

  Set Msg = item

Title = Msg.Subject
Body = Msg.Body

TargetURL = "https://api.pushbullet.com/v2/pushes"


Set HttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HttpReq.Option(4) = 13056
HttpReq.Open "POST", TargetURL, False
HttpReq.SetCredentials "user", "password", 0

HttpReq.setRequestHeader "Authorization", "Bearer myAPI"
HttpReq.setRequestHeader "Content-Type", "application/json"


Message = "{""channel_tag"": ""myChannel"", ""type"": ""note"",  ""title"": " & _
  vbDoubleQuote & Title & vbDoubleQuote & ", ""body"": " & _
  vbDoubleQuote & Body & vbDoubleQuote & "}"
  HttpReq.Send (Message)

Hi everyone, sorry if the question is too easy for you guys, but I am clueless with this.

Above is my code, upon in message I put the title to read what I had define at the middle of the code:

 (""title"": " & _
  vbDoubleQuote & Title & vbDoubleQuote & ") as "Title = Msg.Subject". 

But still upon pushing the nothing but empty message without any message, just an empty message.

Am I defining the string wrongly ?

Comintern
  • 21,855
  • 5
  • 33
  • 80
Sap1
  • 21
  • 3
  • Add `Debug.Print Message` right before the `HttpReq.Send` line and look at it in the immediate window. Does it look correct? – Comintern Sep 23 '16 at 03:30
  • hi @Comintern , thanks for your help, upon adding that line, the message didn't push at all to my PushBullet. I noticed that, whenenever I define something after "Set Msg = item" The code stop pushing at all.. – Sap1 Sep 23 '16 at 03:42

1 Answers1

0

You need to close and re-open your string between line-continuations:

You may also need to declare a Const for vbDoubleQuote

Const vbDoubleQuote As String = """"

Message = "{""channel_tag"": ""myChannel"", ""type"": ""note""," & _
    """title"": " & _
    vbDoubleQuote & Title & vbDoubleQuote & ", ""body"": " & _
    vbDoubleQuote & Body & vbDoubleQuote & "}"

Gives

{"channel_tag": "myChannel", "type": "note","title": "MYTITLE", "body": "MYBODY"}

ThunderFrame
  • 9,352
  • 2
  • 29
  • 60
  • hmm, @ComIntern edited the question, this answer may no longer apply? – ThunderFrame Sep 23 '16 at 03:39
  • It looked like the OP was trying to add hard line breaks in the markup based on my copy and paste. That may or may not have been accurate. – Comintern Sep 23 '16 at 03:45
  • Hi @ThunderFrame, thanks for you help, however defining the message as your code does work. I'm trying to call the function that i've call earler in message. instead "MYTITLE" , i need it to read for "Msg.Subject" , which it is a properties from "Outlook.MailItem" that will read the email subject. thank for your help :) – Sap1 Sep 23 '16 at 03:51
  • Hi @ThunderFrame , ComIntern just help out to rearrange my code into a correct coding area. :) – Sap1 Sep 23 '16 at 06:40
  • Anyone would suggest me anything ? I am still studying this thing and didnt come out with any relevant reason why it is not working ... thanks in advance guys – Sap1 Sep 24 '16 at 16:54