Reply

Trouble getting any WAPI example script to run from Node/JavaScript with axios

New Member
Posts: 5
1351     0

 

OK. I’m pretty puzzled by node/JavaScript behavior while writing test scripts for WAPI Infoblox access. So I got several queries working using Postman which always seems to be a good place to start. The following is the Node and Axios example I exported from Postman. I have added the dependency Axios module.

 

import axios from 'axios';

 

var data = JSON.stringify({

  "name": “mytest-shared”,

  "network_view": “default,

  "networks": [

    {

      "_ref": "network/ZG5zLm5…iRtDrGt:10.0.2.128/27/default”

    },

    {

      "_ref": "network/iRtDrGt…iRtDrGt:10.0.2.160/27/default”

    }

  ]

});

 

var config = {

  method: 'post',

  maxBodyLength: Infinity,

  url: 'https://gridm.privatecompany.com/wapi/v2.11/sharednetwork',

  headers: {

    'Authorization': 'Basic randomjunk0OQ==',

    'Content-Type': 'application/json'

  },

  data : data

};

 

axios(config)

.then(function (response) {

  console.log(JSON.stringify(response.data));

})

.catch(function (error) {

  console.log(error);

});

 

 

I was getting the error ”self signed cert in chain”. So I set my host name to an absolutely confirmed GM with hostname with a good certificate. It produces no errors in Chrome or Edge when I go to https://gridm.privatecompany.com/ui/ and view the certificate from the lock icon in the browser.

 

 

(venv-python) userid@macbook nodejs %                

 

Proxy-related environment variables set.

Proxy successfully connected.

(proxy on)                            

                                                                                    

(venv-python) userid@macbook nodejs % node POST-create-sharednetwork.js

AxiosError: self-signed certificate in certificate chain

    at AxiosError.from (/Users/vaeq6f/Documents/repos/infoblox-wapi/nodejs/node_modules/axios/dist/node/axios.cjs:825:14)

... blah blah

 

But still as you can see I am receiving the warning about "self-signed certificate blah blah blah”. I’m pretty puzzled as to why this would still be being produced. I also have tried it with disabling our company proxy settings. Should I add the proxy settings in the axios config?

 

Running out of ideas since this seems to be straightforward. It works so easily from Postman, Python or curl.

 

Re: Trouble getting any WAPI example script to run from Node/JavaScript with axios

New Member
Posts: 5
1352     0

Here's best work around. Do this environment variable in your shell in order to get Node JavaScript to ignore SSL cert issues.

 

export NODE_TLS_REJECT_UNAUTHORIZED=0

Showing results for 
Search instead for 
Did you mean: 

Recommended for You