Skip to main content
Jon Card
Inspiring
Apr 5, 2023 10:56 AM UTC
Question

Connect to API

I am trying to connect to an API and need some help
Using RHEL 7 and Universe 11.3.4
The curl example they provided works in RHEL.

curl -X 'GET'
  'https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips?vagusAPIKey=1A2B3C-1533-CMBD-8537-123456789'
  -H 'accept: text/plain'

This is my BASIC Code
      URL = "https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips"
      KEY = '1A2B3C-1533-CMBD-8537-123456789'
      X = addAuthenticationRule(X.CONTEXT,2, "VerificationStrength", "generous")
      X.DEPTH = 2
      X.SERVER.OR.CLIENT = 2             ; * CLIENT
      X.RTN.CODE = setAuthenticationDepth(X.CONTEXT, X.DEPTH, X.SERVER.OR.CLIENT)
      X.RTN.CODE = addAuthenticationRule(X.CONTEXT, 2, "ServerName", "stagingapi.vagustracker.com")
      HTTP.METHOD="GET"
      X.RTN.CODE = createSecureRequest(URL,HTTP.METHOD,X.HANDLE,X.CONTEXT)
      *X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "application/json")
      X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "text/plain")
      X.RTN.CODE = setRequestHeader(X.HANDLE, "vagusAPIKey",KEY)
      X.RTN.CODE = submitRequest(X.HANDLE,'','',X.RESPONSE.HEADERS,X.RESPONSE.DATA,X.HTTP.STATUS)

When I added the ServerName I could see I was connecting with the service but I think it does not like my key configuration.

Jon Card
Combined Transport Inc

    4 replies

    Neil Morris
    Rocketeer
    Apr 5, 2023 11:32 AM UTC

    I am trying to connect to an API and need some help
    Using RHEL 7 and Universe 11.3.4
    The curl example they provided works in RHEL.

    curl -X 'GET'
      'https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips?vagusAPIKey=1A2B3C-1533-CMBD-8537-123456789'
      -H 'accept: text/plain'

    This is my BASIC Code
          URL = "https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips"
          KEY = '1A2B3C-1533-CMBD-8537-123456789'
          X = addAuthenticationRule(X.CONTEXT,2, "VerificationStrength", "generous")
          X.DEPTH = 2
          X.SERVER.OR.CLIENT = 2             ; * CLIENT
          X.RTN.CODE = setAuthenticationDepth(X.CONTEXT, X.DEPTH, X.SERVER.OR.CLIENT)
          X.RTN.CODE = addAuthenticationRule(X.CONTEXT, 2, "ServerName", "stagingapi.vagustracker.com")
          HTTP.METHOD="GET"
          X.RTN.CODE = createSecureRequest(URL,HTTP.METHOD,X.HANDLE,X.CONTEXT)
          *X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "application/json")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "text/plain")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "vagusAPIKey",KEY)
          X.RTN.CODE = submitRequest(X.HANDLE,'','',X.RESPONSE.HEADERS,X.RESPONSE.DATA,X.HTTP.STATUS)

    When I added the ServerName I could see I was connecting with the service but I think it does not like my key configuration.

    Jon Card
    Combined Transport Inc

    Jon, have your tried adding protocolLogging() to your program to see if it provides any more specifics on the behavior?

    Jon Card
    Jon CardAuthor
    Inspiring
    Apr 5, 2023 11:45 AM UTC

    I am trying to connect to an API and need some help
    Using RHEL 7 and Universe 11.3.4
    The curl example they provided works in RHEL.

    curl -X 'GET'
      'https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips?vagusAPIKey=1A2B3C-1533-CMBD-8537-123456789'
      -H 'accept: text/plain'

    This is my BASIC Code
          URL = "https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips"
          KEY = '1A2B3C-1533-CMBD-8537-123456789'
          X = addAuthenticationRule(X.CONTEXT,2, "VerificationStrength", "generous")
          X.DEPTH = 2
          X.SERVER.OR.CLIENT = 2             ; * CLIENT
          X.RTN.CODE = setAuthenticationDepth(X.CONTEXT, X.DEPTH, X.SERVER.OR.CLIENT)
          X.RTN.CODE = addAuthenticationRule(X.CONTEXT, 2, "ServerName", "stagingapi.vagustracker.com")
          HTTP.METHOD="GET"
          X.RTN.CODE = createSecureRequest(URL,HTTP.METHOD,X.HANDLE,X.CONTEXT)
          *X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "application/json")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "text/plain")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "vagusAPIKey",KEY)
          X.RTN.CODE = submitRequest(X.HANDLE,'','',X.RESPONSE.HEADERS,X.RESPONSE.DATA,X.HTTP.STATUS)

    When I added the ServerName I could see I was connecting with the service but I think it does not like my key configuration.

    Jon Card
    Combined Transport Inc

    Yes I have protocolLogging()  turned on. The log file is attached.

    Jon Card
    Combined Transport Inc

    Philip Moore
    New Participant
    Apr 6, 2023 10:36 AM UTC

    I am trying to connect to an API and need some help
    Using RHEL 7 and Universe 11.3.4
    The curl example they provided works in RHEL.

    curl -X 'GET'
      'https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips?vagusAPIKey=1A2B3C-1533-CMBD-8537-123456789'
      -H 'accept: text/plain'

    This is my BASIC Code
          URL = "https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips"
          KEY = '1A2B3C-1533-CMBD-8537-123456789'
          X = addAuthenticationRule(X.CONTEXT,2, "VerificationStrength", "generous")
          X.DEPTH = 2
          X.SERVER.OR.CLIENT = 2             ; * CLIENT
          X.RTN.CODE = setAuthenticationDepth(X.CONTEXT, X.DEPTH, X.SERVER.OR.CLIENT)
          X.RTN.CODE = addAuthenticationRule(X.CONTEXT, 2, "ServerName", "stagingapi.vagustracker.com")
          HTTP.METHOD="GET"
          X.RTN.CODE = createSecureRequest(URL,HTTP.METHOD,X.HANDLE,X.CONTEXT)
          *X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "application/json")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "text/plain")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "vagusAPIKey",KEY)
          X.RTN.CODE = submitRequest(X.HANDLE,'','',X.RESPONSE.HEADERS,X.RESPONSE.DATA,X.HTTP.STATUS)

    When I added the ServerName I could see I was connecting with the service but I think it does not like my key configuration.

    Jon Card
    Combined Transport Inc

    I am no expert, but I ran into an API where the URL and the secret has to be encoded.  So for example your URL would be encoded as:

    https%3A%2F%2Fstagingapi.vagustracker.com%2FCoreVagusAPI%2Ftrip%2FAvailableTrips%3FvagusAPIKey%3D1A2B3C-1533-CMBD-8537-123456789



    Are you executing from a .bat script?   If so, and you use percentage symbols, you have to double them or the bat script misbehaves. So, the above example, the percent symbols would be %%














    Nik Kesic
    Participating Frequently
    Apr 6, 2023 3:23 PM UTC

    I am trying to connect to an API and need some help
    Using RHEL 7 and Universe 11.3.4
    The curl example they provided works in RHEL.

    curl -X 'GET'
      'https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips?vagusAPIKey=1A2B3C-1533-CMBD-8537-123456789'
      -H 'accept: text/plain'

    This is my BASIC Code
          URL = "https://stagingapi.vagustracker.com/CoreVagusAPI/trip/AvailableTrips"
          KEY = '1A2B3C-1533-CMBD-8537-123456789'
          X = addAuthenticationRule(X.CONTEXT,2, "VerificationStrength", "generous")
          X.DEPTH = 2
          X.SERVER.OR.CLIENT = 2             ; * CLIENT
          X.RTN.CODE = setAuthenticationDepth(X.CONTEXT, X.DEPTH, X.SERVER.OR.CLIENT)
          X.RTN.CODE = addAuthenticationRule(X.CONTEXT, 2, "ServerName", "stagingapi.vagustracker.com")
          HTTP.METHOD="GET"
          X.RTN.CODE = createSecureRequest(URL,HTTP.METHOD,X.HANDLE,X.CONTEXT)
          *X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "application/json")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "Content-Type", "text/plain")
          X.RTN.CODE = setRequestHeader(X.HANDLE, "vagusAPIKey",KEY)
          X.RTN.CODE = submitRequest(X.HANDLE,'','',X.RESPONSE.HEADERS,X.RESPONSE.DATA,X.HTTP.STATUS)

    When I added the ServerName I could see I was connecting with the service but I think it does not like my key configuration.

    Jon Card
    Combined Transport Inc

    Hello Jon,

    You did not show the curl output.

    Is it "Not Authorized for Available Trips"

    Is that correct?, I modified your code a little and get that same answer. 

    I think you left out the authentication bit and the basic code is also missing the create CONTEXT piece.

    Nik Kesic