in IBM Maximo 7.6.0.8 I would like to create PO from a PR using REST API and VBA (HTTP requests).
My code is:
Dim PostData() As Byte
Dim IE As InternetExplorerMedium
Set IE = New InternetExplorerMedium
PostData = "~date=23-08-2018"
PostData = StrConv(PostData, vbFromUnicode)
myheader = myheader & "x-http-method-override: createPOsFromPR" & vbNewLine
myheader = myheader & "Content-Type: application/json" & vbCrLf
IE.Navigate "https://host:port/maxrest/rest/mbo/pr/123", 0, "myIE", PostData, myheader
But I get Error 500. Authentication is not the problem.
In general I would like to be albe to copy (assign) PR lines to POs and RFQs.
Is this the way to do this? Does someone has working solution?
Thanks!
You could use the New REST API that allows you to directly call an automation script.
You'd add the PR number and date as request parameters and use them in the script to call
the PR.createPOsFromPR method.
Your call would look like this:
http://maximohost/maximo/oslc/script/genPOsScript?prnum=ABC&date=2019-11-21
You might want to add the site as param too because PR is a site level object.
You can see an example here:
https://developer.ibm.com/static/site-id/155/maximodev/restguide/Maximo_Nextgen_REST_API.html#_automation_scripts
Related
I'm trying to catch a Response to a POST Request using XMLHTTP using the code below
Dim XMLPage As New MSXML2.XMLHTTP60
Dim HTMLDoc As New MSHTML.HTMLDocument
Dim htmlEle1 As MSHTML.IHTMLElement
Dim htmlEle2 As MSHTML.IHTMLElement
Dim URL As String
Dim elemValue As String
URL = "https://www.informadb.pt/pt/pesquisa/?search=500004064"
XMLPage.Open "GET", URL, False
XMLPage.send
HTMLDoc.body.innerHTML = XMLPage.responseText
For Each htmlEle1 In HTMLDoc.getElementsByTagName("div")
Debug.Print htmlEle1.className
If htmlEle1.className = "styles__SCFileModuleFooter-e6rbca-1 kUUNkj" Then
elemValue = Trim(htmlEle1.innerText)
If InStr(UCase$(elemValue), "CONSTITU") > 0 Then
'Found Value
Exit For
End If
End If
Next htmlEle1
The problem is that I can't find the ClassName "styles__SCFileModuleFooter-e6rbca-1 kUUNkj", because I notice that when I manually insert the value (500004064) in the search box of the URL : https://www.informadb.pt/pt/pesquisa/, the Web Page generates addicinal traffic and turns up at an end point URL : https://www.informadb.pt/pt/pesquisa/empresa/?Duns=453060832, where that className can be found in the Request ResponseText.
My goal is to use the First URL to retrieve the Duns number '453060832', to be able to access the information in the ResponseText of the EndPoint URL. And to catch Duns Number, I need to find a way to get the Endpoint URL, or try to get The POST request response below, and get that value using JSON parser:
{'TotalResults': 1,
'NumberOfPages': 1,
'Results': [{'Duns': '453060832',
'Vat': '500004064',
'Name': 'A PANIFICADORA CENTRAL EBORENSE, S.A.',
'Address': 'BAIRRO DE NOSSA SENHORA DO CARMO,',
'Locality': 'ÉVORA',
'OfficeType': 'HeadOffice',
'FoundIn': None,
'Score': 231.72766,
'PageUrl': '/pt/pesquisa/empresa/?Duns=453060832'}]}
I'm not being able to capture what is really happening using the XMLHTTP Browser request, that seems to be the below steps:
navigate to https://www.informadb.pt/pt/pesquisa/?search=500004064
Webpage generates additional traffic
Amongst that additional traffic is an API POST XHR request which
returns search results as JSON. That request goes to
https://www.informadb.pt/Umbraco/Api/Search/Companies and includes
the 500004064 identifier amongst the arguments within the post body
Based on the API results the browser ends up at the following URI
https://www.informadb.pt/pt/pesquisa/empresa/?Duns=453060832
Can someone help me please, I have to do it using VBA.
Thanks in advance.
A small example how to POST data to your website using VBA, and how to use bare-bones string processing to extract data from the result, as outlined in my comments above.
Function GetVatId(dunsNumber As String) As String
With New MSXML2.XMLHTTP60
.open "POST", "https://www.informadb.pt/Umbraco/Api/Search/Companies", False
.setRequestHeader "Content-Type", "application/json"
.send "{""Page"":0,""PageSize"":5,""SearchTerm"":""" & dunsNumber & """,""Filters"":[{""Key"":""districtFilter"",""Name"":""Distrito"",""Values"":[]},{""Key"":""legalFormFilter"",""Name"":""Forma Jurídica"",""Values"":[]}],""Culture"":""pt""}"
If .status = 200 Then
MsgBox "Response: " & .responseText, vbInformation
GetVatId = Mid(.responseText, InStr(.responseText, """Vat"":""") + 7, 9)
Else
MsgBox "Repsonse status " & .status, vbExclamation
End If
End With
End Function
Usage:
Dim vatId As String
vatId = GetVatId("453060832") ' => "500004064"
For a more robust solution, you should use a JSON parser and -serializer, something like https://github.com/VBA-tools/VBA-JSON.
I research regarding retrieving or displaying emails from gmail without using outlook and it led me here on using Gmail API. I'm confused because I don't have idea on how to solve my problem.
Here's the code:
Attribute VB_Name = "Gmail"
' Setup client and authenticator (cached between requests)
Private pGmailClient As WebClient
Private Property Get GmailClient() As WebClient
If pGmailClient Is Nothing Then
' Create client with base url that is appended to all requests
Set pGmailClient = New WebClient
pGmailClient.BaseUrl = "https://www.googleapis.com/gmail/v1/"
' Use the pre-made GoogleAuthenticator found in authenticators/ folder
' - Automatically uses Google's OAuth approach including login screen
' - Get API client id and secret from https://console.developers.google.com/
' - https://github.com/timhall/Excel-REST/wiki/Google-APIs for more info
Dim Auth As New GoogleAuthenticator
Auth.Setup CStr(Credentials.Values("Google")("id")), CStr(Credentials.Values("Google")("secret"))
Auth.AddScope "https://www.googleapis.com/auth/gmail.readonly"
Auth.Login
Set pGmailClient.Authenticator = Auth
End If
Set GmailClient = pGmailClient
End Property
' Load messages for inbox
Function LoadInbox() As Collection
Set LoadInbox = New Collection
' Create inbox request with userId and querystring for inbox label
Dim Request As New WebRequest
Request.Resource = "users/{userId}/messages"
Request.AddUrlSegment "userId", "me"
Request.AddQuerystringParam "q", "label:inbox"
Dim Response As WebResponse
Set Response = GmailClient.Execute(Request)
If Response.StatusCode = WebStatusCode.Ok Then
Dim MessageInfo As Dictionary
Dim Message As Dictionary
For Each MessageInfo In Response.Data("messages")
' Load full messages for each id
Set Message = LoadMessage(MessageInfo("id"))
If Not Message Is Nothing Then
LoadInbox.Add Message
End If
Next MessageInfo
End If
End Function
' Load message details
Function LoadMessage(MessageId As String) As Dictionary
Dim Request As New WebRequest
Request.Resource = "users/{userId}/messages/{messageId}"
Request.AddUrlSegment "userId", "me"
Request.AddUrlSegment "messageId", MessageId
Dim Response As WebResponse
Set Response = GmailClient.Execute(Request)
If Response.StatusCode = WebStatusCode.Ok Then
Set LoadMessage = New Dictionary
' Pull out relevant parts of message (from, to, and subject from headers)
LoadMessage.Add "snippet", Response.Data("snippet")
Dim Header As Dictionary
For Each Header In Response.Data("payload")("headers")
Select Case Header("name")
Case "From"
LoadMessage.Add "from", Header("value")
Case "To"
LoadMessage.Add "to", Header("value")
Case "Subject"
LoadMessage.Add "subject", Header("value")
End Select
Next Header
End If
End Function
Sub Test()
Dim Message As Dictionary
For Each Message In LoadInbox
Debug.Print "From: " & Message("from") & ", Subject: " & Message("subject")
Debug.Print Message("snippet") & vbNewLine
Next Message
End Sub
I'm using the blank file from this GitHub Link that enables this code above. I was stuck on this error:
Still I don't have the idea what's the output of this API because it's my first time using this one. I have my id and secret already from Gmail API i just removed it from the code. I guess it was really hard if I don't have someone I can do brainstorming regarding on this matter.
Hoping someone have encountered this problem or anyone is interested. Thanks.
I have an function in Excel:
Function getState(Defects As Object) As String
Dim str As String
Dim res As String
Dim was As Boolean
Dim sURL As String
Dim oRequest As Object
Set oRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
was = False
For Each defect In Defects
If was = False Then
str = "(FormattedID = """ & defect & """)"
res = str
was = True
Else
res = res & " OR " & str
End If
Next defect
sURL = "https://rally1.rallydev.com/slm/webservice/v2.0/defect?query=(" & res & ")&fetch=FormattedID,State"
oRequest.Open "GET", sURL, True
oRequest.setRequestHeader "Content-Type", "application/json;charset=UTF-8"
oRequest.Send
oRequest.WaitForResponse
' Set Defects = oRequest.ResponseText
Debug.Print (oRequest.ResponseText)
End Function
Unfortunately, i get rubbish instead of json in response like:
? i?ANA0E?=A(utU
¤RoP°irC°%'.o$%·CI{OOYO????uApeaBRM?Zb?u?OWo?"{oSCy5?(}e??e?qBA"qnu~E·Uu?|?aRbE?a>anµ?c?9P=?A[Oul?0i O {PZS?Af~???^??k??R˜?|©?#iEoPNO|?¦'y?vO^Ol? ]?g?#?AjAa?\aC¤y %©e»]"IHog??#:?· (??"¶E9yog?Az?7bw?/#?eWp^u?ZU?u??3?q?A)cy7µe?E
Could you please take a look at it and provide an solution how it can be fixed?
Thank you in advance!
Larry's answer is correct.
As an aside, if you need to pull data from Rally into Excel, your best bet is the Rally Add-in for Excel:
https://help.rallydev.com/rally-add-excel
Since you mentioned VBA, you may be working to build some automation in Excel, which the Excel add-in doesn't support. There is an alpha-level Rally Rest Toolkit for VBA. It handles the authentication and REST serialization/de-serialization for you, so it could ease some of your coding effort.
It is unofficial and not supported by Rally, but could be worth trying. Since it is unsupported though, Rally can't help you out if you run into issues. You'd have to refactor your own code against the VBA toolkit to pull the data you want:
https://github.com/markwilliams970/RallyRestToolkitForVBA
The response is compressed. Either try setting a request header for Accept-Encoding: identity or decompress the response.
In my app I'm making a call to an API.
I start by building the URL...
Dim url As String = "http://" & Home.sn_username & ":" & Home.sn_password & "#" & Home.sn_ip & "/command.htm?number=" & phonenumber
url = Replace(url, Chr(13), "")
I want to make sure the URL its attempting to call is correct, so i've dumped it to the console...
Console.WriteLine("DIALING: " & url)
The URL is spot on, so finally I call the URL with Net.Webclient...
Dim client As New Net.WebClient
client.DownloadString(url)
This does not work.
An exception is thrown and I get a 401 Unauthorised error.
Am i doing something wrong?
The final URL is like this:
http://username:passwrd#domainame.com/command.htm?Number=01611234565
If i take that and paste it directly into my browser it works fine! (its for an IP phone API... my desk phone dials the number!).
Do i need to look at a different way of supplying the credentials or something?
Thanks in advance!
Try adding your authentication credentials directly to the WebClient instead of prepending them before the url before executing.
client.Credentials = new NetworkCredential(Home.sn_username, Home.sn_password)
I am receiving a "400 Bad Request" error when using the following VBA code to exchange a valid Authorization token for an access token in the Google API. Can anyone shed light as to why, I have been struggling with this one for over a week.
Dim http As MSXML2.XMLHTTP
Dim sUrl As String
Dim sUrlHeader As String
Dim svarbody As String
Set http = New MSXML2.XMLHTTP
sUrl = "https://accounts.google.com/o/oauth2/token? HTTP/1.1"
http.Open "POST", sUrl
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
svarbody = "code=4%2FXAjmXiUlBXUAUGCnMvNKsxdyuJEJ.8kfzzrqo3wwTuJJVnL49Cc9gML_lbgI&" & _
"client_id=50487549202#-q27v28nvhmjhc0uobq35tjn09lhrh47r.apps.googleusercontent.com&" & _
"redirect_uri=http%3A%2F%2Flocalhost&" & _
"scope=https%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds&" & _
"client_secret=<secret delete for this post>&" & _
"grant_type=authorization_code"
http.send svarbody
Me.Text3 = http.status & vbCrLf & http.statusText & vbCrLf & http.responseText
this is a very very common problem. You may try to solve it doing many approaches and tests... but...
The really one you should try in the first place is:
UPDATE YOUR SERVER/COMPUTER WINDOWS CLOCK, USE time.nist.gov (or brothers). Double-click in your Windows Hour-Date (on the bottom of your screen and change Internet Time in this way)
SntsDev
In my experience using Oauth 2.0 in VBA this error happens when you use the code more than once for requesting a token. The usage sequence I use based on the documentation and experience is:
access GET https://accounts.google.com/o/oauth2/auth once for geting the code
access POST https://accounts.google.com/o/oauth2/token once for geting the token
after that use the token as long as it is valid
It is possible that you need set up billing info in your google account.