I am attempting to do some API calls into SP. I would like to build a small query process using VB.net using an APIKEY authorization. (I already have an apikey generated). I have been all over this site but have not found any vb.net examples. I just need a few samples on authenticating and passing parameters to an API call.
Any assistance is greatly appreciated!
vb.net using apikey examples
Forum rules
- Check the documentation first. Before posting questions, please check the documentation to ensure it doesn't already cover what you need.
- No spam. All automated messages, advertisements, and links to competitor websites will be deleted immediately.
- Post in relevant sub-forums only. Messages posted in the wrong topic area will be removed and placed in the correct sub-forum by moderators.
- Respect other users. No flaming or abusing fellow forum members. Users who continue to post inflammatory, abusive comments will be deleted from the forum after two warnings are issued by moderators.
- Harassment. No threats or harassment of other users will be tolerated. Any instance of threatening or harassing behavior is grounds for deletion from the forums.
- Adult content. No profanity or pornography is allowed. Posts containing adult material will be deleted.
- Bandwidth. All images and signatures must be 500 x 500 pixels or smaller. Posts containing over-sized images and signatures will be removed.
- Illegal content. No re-posting of copyrighted materials or other illegal content is allowed. Any posts containing illegal content or copyrighted materials will be deleted.
Re: vb.net using apikey examples
Hi, this is pretty rough but hope it helps.
API key (Bearer grabbed from textbox)
this takes PDF attachments from emails (MS outlook) and saves them as attachments to the job
API key (Bearer grabbed from textbox)
this takes PDF attachments from emails (MS outlook) and saves them as attachments to the job
Code: Select all
Sub Mail()
Dim olApp As Microsoft.Office.Interop.Outlook.Application
Dim ns As [NameSpace]
Dim Inbox As MAPIFolder
Dim Item As MailItem
Dim SubFolder As MAPIFolder
Dim Atmt As Attachment
Dim FileName As String
Dim Num As Integer
Dim cnt3
Dim SF
Dim Loc
Dim bearer
Dim companies
Dim f2 As New Form2
Dim minval
Dim Rf
Dim Rj
Dim UrL
Dim FileType
Dim Bodytext As String
SF = f2.TextBox6.Text
Loc = f2.TextBox5.Text
bearer = f2.TextBox2.Text
minval = f2.TextBox4.Text
UrL = f2.TextBox1.Text
Rf = f2.TextBox7.Text
Rj = f2.TextBox8.Text
'###########################################
'Look in inbox subfolder iauditor for emails
'###########################################
olApp = CreateObject("Outlook.Application")
ns = olApp.GetNamespace("MAPI")
Inbox = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox)
SubFolder = Inbox.Folders(SF)
For Each Item In SubFolder.Items
cnt3 = 0
If IsNumeric(Item.Subject) Then
Num = Convert.ToDouble(Item.Subject)
If Num > minval Then
companies = Company(Num)
Dim fn As String
Bodytext = Item.Body
FileType = FormType(Bodytext)
For Each Atmt In Item.Attachments
fn = GetExtension(Atmt.FileName)
If fn = "pdf" Then
fn = Atmt.DisplayName
FileName = Loc & Num & ".pdf"
cnt3 = cnt3 + 1
Atmt.SaveAsFile(FileName)
Item.Delete()
Dim httpObject As Object
httpObject = CreateObject("MSXML2.XMLHTTP")
Dim OrDer
Dim Bs
Dim sRequest As String
Dim sgetresult As String
Dim sURL As String
Dim DT = DateTime.Parse(Now()).ToString("dd_MM_yyyy_HH_mm")
Dim JSONString As String
Bs = ConvertFileToBase64("C:\Enable_Daily_CSV\8_Scope\" & Num & ".pdf")
JSONString = "{""Filename"":""" & FileType & "_" & DT & "_" & Num & ".pdf"",""Public"": true,""Base64Data"":""" & Bs & """}"
OrDer = Num
sURL = UrL & companies & "/jobs/" & Num & "/attachments/files/"
sRequest = sURL
httpObject.Open("Post", sRequest, False)
httpObject.setRequestHeader("Authorization", bearer)
httpObject.setRequestHeader("Content-Type", "application/json")
httpObject.send(JSONString)
sgetresult = httpObject.responseText
'MessageBox.Show("Attachment created in SimPRO")
FileSystem.MoveFile(FileName, "C:\some folder\8_Scope\Actioned\" & Num & "_" & FileType & ".pdf", FileIO.UIOption.AllDialogs, FileIO.UICancelOption.ThrowException)
End If
Next Atmt
If cnt3 < 1 Then
Item.Reply()
Item.Body = Rf
Item.Send()
End If
Else
Item.Reply()
Item.Body = Rj
Item.Send()
End If
Else
Item.Reply()
Item.Body = Rj
Item.Send()
End If
Next Item
End Sub 'Main Code
DEVELOPER CENTER