Fred Zimmerman
Fred Zimmerman

Reputation: 1238

pulling vivContext.userId into an Action

I want to access $vivcontext.userId. I can successfully retrieve the userId as a standalone Action, but it is failing when I try to do it in the midst of another Action.

I created action AccessVivContext.js & models for Userid, DummyInput, and AccessVivContext. Using {intent: goal: AccessVivContext} I can successfully retrieve userId in the Simulator.

I want to call the userId function during my checkEntitlements function like so:


function checkEntitlements() {

  var userid = $vivContext.userId
  console.log('userid is', userid)
  var options = {
    passAsJson: true,
    returnHeaders: true,
    headers:
      { accept: 'application/json'},
    format: 'json'
  };

  // Note Bixby HTTP API is asynchronous - no need for a promise or callback
  var response = http.postUrl('https://altbrains.com/api/user/check_entitlements', options, userid)
    console.log(response)
  return response;

This function is in GetRemoteContent.js which is called by GetContent.js.

I get an error message in the GetContent.js Action ReferenceError: "$vivContext" is not defined.

Upvotes: 1

Views: 79

Answers (2)

jiggysoo
jiggysoo

Reputation: 1638

Please note that $vivContext.userId is deprecated (https://bixbydevelopers.com/dev/docs/dev-guide/release-notes/deprecations.6785), use $vivContext.bixbyUserId instead.

Upvotes: 0

Pete Haas
Pete Haas

Reputation: 1800

You need to pass $vivContext into your function. Otherwise, it will be undefined. For example:

function checkEntitlements($vivContext) {
// YOUR CODE HERE
}

Upvotes: 5

Related Questions