question

motorhomer avatar image
motorhomer asked

VRM API request setup help please

I am trying to do an API request to the VRM but getting 401 return.

When I do the login request I get the user id and authorisation code. I have put this in a HTTP JSON request as shown below but not getting any data back. Can someone please help point me in the write direction.

<html>
    <head>
    <?php   
    header('X-Authorization: Token {...}');
    ?>
    <script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="crossorigin="anonymous"></script>
    <script>
        $(document).ready(function () {
           getData();
        };
        function getData() {
            $.ajax({
                 url: "https://vrmapi.victronenergy.com/v2/users/57713/installations",
                 type: "GET",
                 success: function (data) {
                     console.log(data);
                 }
             });
        }

    </scrip
</head>
<body>
    <h1>Victron</h1>
</body>
</html>
VRM
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

2 Answers
Teun Lassche avatar image
Teun Lassche answered ·

Hi,


Please note that sharing your token here is not safe.

Your authorization header should be like this:


X-Authorization: Bearer your-token-here

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

motorhomer avatar image
motorhomer answered ·

I have tried X-Authorization: Bearer with in PHP tags and outside the tags as HTML and still nothing.

As a HTML header it just displays the code on the DOM and no console log

    <head>
    X-Authorization: Bearer  {token}

As PHP get either 401 or page does not load

    <?php   
    header('X-Authorization: Bearer  {token}'); //401 response
    ?>
    // following page does not load
    <?php   
    X-Authorization: Bearer  {token};
    ?>


2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.