Multiple REST api calls

I am new to working with the REST api. I have successfully created some VBA code within an excel spreadsheet that queries one of my BAQs. I pass in the parameters and the return string gives me exactly what I want.
I then attempt to call a different BAQ, again passing parameters. I get nothing back. I have verified my url string using the REST help on the server. I have tried declaring a second object but that does not help either.
Is there something I am missing making the second call? Here is my code:

Function Fill_Part_Data()

    Dim objRequest As Object, objRequest2 As Object
    Dim strUrl As String
    Dim blnAsync As Boolean
    Dim strResponse As String
    Dim strParentRev As String, strRevDate As String, strContract As String, strAuthDoc As String, strPartNum As String
    Dim strPartList As String, strDrawing As String, strRev As String, strTitle As String
    Dim intPos As Integer, intPos2 As Integer
    Dim strTemp As String, strDate As String, strESD As String
    
    strPartNum = "272A001100-01"
    strRev = "-"

    Set objRequest = CreateObject("MSXML2.XMLHTTP")
    blnAsync = True
    strUrl = "https://server/EpicorERPTest/api/v1/BaqSvc/ASI_DataList_Parent/?PartNumber='" & strPartNum & "'&Rev='" & strRev & "'"
    With objRequest
        .Open "GET", strUrl, blnAsync
        .SetRequestHeader "Content-Type", "application/json"
        .Send
        'spin wheels whilst waiting for response
        While objRequest.readyState <> 4
            DoEvents
        Wend
        strResponse = .ResponseText
    End With
    
    Debug.Print strResponse
    'parse apart the header data
...
    'now go get the detail data
    Set objRequest = Nothing
    Set objRequest2 = CreateObject("MSXML2.XMLHTTP")
    strUrl = "https://server/EpicorERPTest/api/v1/BaqSvc/ASI_IBOM_PartList/?BOM='" & strPartNum & "'&Revision='" & strRev & "'"
    With objRequest2
        .Open "GET", strUrl, blnAsync
        .SetRequestHeader "Content-Type", "application/json"
        .Send
        'spin wheels whilst waiting for response
        While objRequest2.readyState <> 4
            DoEvents
        Wend
        strResponse = .ResponseText
    Debug.Print strResponse
    End With
End Function

Shot in the dark as I’m not too familiar with VBA, but you do a .Open–does it possibly require a .Close to dispose of the object before making your next call?

Past (minimal) experience with the JIRA REST api I didn’t use a close. Don’t see one when searching either.

did you try to call the second one separately? as by itself in code without calling the first one.

Well I feel pretty silly. Turns out I was using a local variable for 2 different things and blew away my parameter I needed to pass to the second call, so it never could find what I was looking for. If you look in the code I posted I used strRev as a hard-coded value for testing. I then wiped that value out in the code I cut out to save space. When I called it the second time it had a bad value so the BAQ couldn’t find what I was looking for.

Thanks for the help!

1 Like