Announcement

Collapse
No announcement yet.

Error Making an API call via a Miva Module

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Error Making an API call via a Miva Module

    I'm working on a module that needs to send a POST request with a header and get a valid 200 response. However, whenever I try to make the request, I get this error:
    Error Code: MER-URL-TASK-2
    Description: Failed To Update: Unable to open URL 'https://staging.manage.enshield.com/api/auth': Error connecting to staging.manage.enshield.com on port 443: Connection timed out
    This is what my code looks like and every time I run it, it just stalls out and returns with a 500 error and shows the error above. It seems like its not using the API key.

    Code:
    <MvASSIGN NAME="l.header" VALUE="{ 'accept: */*' $ asciichar( 13 ) $ asciichar( 10 ) }">
    <MvASSIGN NAME="l.header" VALUE="{l.header $ 'Content-Length: 0' $ asciichar( 13 ) $ asciichar( 10 ) }">
    <MvASSIGN NAME="l.header" VALUE="{ l.header $ 'Content-Type: application/json' $ asciichar(13) $ asciichar(10) }">
    <MvASSIGN NAME="l.header" VALUE="{l.header $ 'X-Api-Key: xxxxxxxx ' $ asciichar( 13 ) $ asciichar( 10 ) }">
    
    
    <MvCALL ACTION = "{l.url}"
    METHOD = "POST"
    HEADERS="{ l.header }"
    CONTENT-TYPE = "application/json"
    >
    
    <MvASSIGN NAME="l.response_header" VALUE="{s.callreturnheader1}">
    <MvASSIGN NAME="l.response" VALUE="{l.response $ callvalue}">
    </MvCALL>
    
    <MvIF EXPR="{l.response_header EQ 'HTTP/1.1 200 OK'}">
    ...
    <MvELSE>
    ...
    <MvFUNCRETURN VALUE="0">
    </MvIF>

    This is a valid request:
    curl -X 'POST' \ 'https://staging.manage.enshield.com/api/auth' \ -H 'accept: */*' \ -H 'X-Api-Key: xxxxxxx' \ -H 'X-CSRF-TOKEN: ' \ -d ''

    So is this:
    POST /api/auth HTTP/1.1
    Accept: */*
    Accept-Encoding: deflate, gzip
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
    Host: staging.manage.enshield.com
    X-Api-Key: xxxxxx
    Content-Type: application/json
    Content-Length: 0

    So I'm not sure why the MivaScript code isn't valid

    #2
    cbarber Have you run logging to confirm that the call and headers are being sent correctly?

    Here is a video on how to get it setup: https://www.youtube.com/watch?v=3PVVh15FLGg&t=5s

    If you need additional help you can email [email protected]
    Nicholas Adkins
    Technical Training Specialist / Miva, Inc.
    [email protected]
    https://www.miva.com/mivalearn

    Comment


      #3
      You are not even connecting to the server when using MvCALL, so the issue isn't the headers. This seems to be more of an issue of the request being ignored based on the requesting IP address. Unless you are running MivaScript locally, the MvCALL is going to be coming from your server that may not have access to the endpoint while your local machine does (when you use curl). For example, both MvCALL and curl time out on my local machine hitting that endpoint.
      David Carver
      Miva, Inc. | Software Developer

      Comment


        #4
        cbarber please open a ticket or send me a direct email about this; I can try to assist. This is failing because of a network block of malicious traffic originating from Digital Ocean, who does not police their network or act against compromised servers. The block is affecting your traffic out to that endpoint, which lives at Digital Ocean.
        David Hubbard
        CIO
        Miva
        [email protected]
        http://www.miva.com

        Comment

        Working...
        X