Comments

8 comments

  • Avatar
    Andrey Terentyev

    Hello,

    Could you please provide the following information: OS version, VMS build?

    Could you please elaborate on what is your objective and what are you doing to achieve it?

    As far as I understood the sceenshot, you're trying to launch a js script in the browser. Am I right? Could you share the code?

    0
    Comment actions Permalink
  • Avatar
    Thar Nyi

    OS: Windows 10 Home x64
    VMS Build: Nx Meta v5.0.0.35744
    Setup: Currently, I installed Nx Meta v5.0.0.35744 Client & Server in my local. In my local Nx Meta Client, I’m using with cloud user account.
    Objective: I want to develop a livestream feature in my Next.js application. I’m trying to connect to the Nx Witness HTTP Stream API through token authentication. And, I want to access all owner API from Nx Meta through API call with bearer token in my Next.js application.
    My code screenshot:

    Thanks!

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hi,

    Try running your server on another address than localhost.

    0
    Comment actions Permalink
  • Avatar
    Thar Nyi

    Hi Andrey,

    Which one?

    1.

    2.

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    I mean your server which runs node.js application.

    0
    Comment actions Permalink
  • Avatar
    Thar Nyi

    Currently, I'm testing from next.js application.

    0
    Comment actions Permalink
  • Avatar
    Andrey Terentyev

    Hi,

    Could you create an example and share your source code as a text file, please?

    0
    Comment actions Permalink
  • Avatar
    Thar Nyi

    Hi Andrey,

    const getAccessToken = async () => {

        await axios

          .get(`https://localhost:7001/api/ping`)

          .then(async (response) => {

            console.log(response)

            if (response.status === 200) {

              const { data: response } = await axios.get(

                `https://localhost:7001/api/moduleInformation?allModules=true`

              )

              const cloudSystemId = response.reply[0].cloudSystemId

              console.log('cloudSystemId: ', response.reply[0].cloudSystemId)

              if (cloudSystemId) {

                const data = {

                  username: 'username',

                  password: 'password',

                  setCookie: true,

                }

                const headersConfig = {

                  headers: {

                    'Content-Type': 'application/json',

                    'Access-Control-Allow-Origin': '*',

                  },

                }

                const { data: response } = await axios.post(

                  `https://localhost:7001/rest/v1/login/sessions`,

                  data,

                  headersConfig

                )

                const accessToken = `Bearer ${response.token}`

                console.log('accessToken: ', accessToken)

                getDeviceRecords(accessToken)

              }

            } else {

            }

          })

          .catch(function (error) {

            console.log(error)

          })

          .then(function () {

            console.log('End.')

          })

      }

      const getDeviceRecords = async (accessToken) => {

        const { data: response } = await axios.get(

          `https://localhost:7001/rest/v1/devices`,

          {

            headers: {

              Authorization: accessToken,

            },

          }

        )

        console.log('getDeviceRecords: ', response)

      }

    I already tested with this article <https://support.networkoptix.com/hc/en-us/articles/360016266074-Cloud-API-Route-API-Calls-via-Nx-Cloud>. It works for me. But, I want to create login session with local user in my local system. When I'm testing with local user and nx witness local server(default:; https://localhost:7001), I can't call API.

    Thanks.

    0
    Comment actions Permalink

Please sign in to leave a comment.