Organization not found for user's role

Hello,

We are creating an iOS app for customer. When we try to new user with createUser or createCustomer we are getting error like Organization not found for user’s role.

We have set clientkey, clientSecret key and Product Id into the app but still we are not able register customer on panel.

Please do some needful urgently.

Thank you!
Rakesh

In the customization function (where you set the productID), did you also set productMode = true ?

@joost

Can you please suggest exact function so we can get more idea. Below is code of our function.

ParticleCloud.sharedInstance().createCustomer(self.txtEmail.text!.TrimeString(), password: self.txtPassword.text!.TrimeString(), productId: XXXX, accountInfo: nil)

Can you suggest where in the above code we pass productMode=true ?

Thank you!

@joost

After doing more research we add the Particle-setup framework into our code. Also add same into pod file apart from Particle-SDK.

Now we are able to set code like this below:

let partysetup = ParticleSetupCustomization.sharedInstance()
partysetup?.productMode = true
let keys = FarmSimpleKeys()
ParticleCloud.sharedInstance().oAuthClientId = keys.oAuthClientId
ParticleCloud.sharedInstance().oAuthClientSecret = keys.oAuthSecret

But still we are getting still same error like “Organization not found for user’s role”.

Thank you!

hmm, I am not getting a clear picture of where you have all your code so here just a few thoughts to help:

  • I set oAuth credentials in AppDelegate. Naturally most apps will have several view controllers. In my case, I will always start or restart the app with a specific view controller to show first. That vc has the responsibility to determine if the app is authenticated or if we need to start the onboarding process i…e., use particle-setup-SDK to go through device sign-on, key exchange etc.
  • The “productMode = true” is part of the onboarding process. In your case it seems you run this just before your oAuth credentials - why? It needs to be run when you go through the particle-setup-SDK process (onboarding). Once that process has succesfully completed, setting your oAuth credentials then allows you to access the particle network.
  • Your first two lines of code are a bit peculiar: If you do “let partysetup = …” you should NOT have to call partysetup as a potential optional returning variable so instead of partysetup?.productMode = true it should be partysetup.productMode = true. The whole thing should really be an “if let {}” statement - I dont think this is your problem, just wanted to point that out.

My customization function looks like this:

private func customizeSetup()
{
  if let c = ParticleSetupCustomization.sharedInstance() {
      c.productMode = true
      c.productName = "your product name here"
      c.productId = <your product number here>
      c.networkNamePrefix = "your device onboarding network prefix here"
			
      c.brandImage = #imageLiteral(resourceName: "Logo")
      c.brandName = "your company name"
      c.brandImageBackgroundColor = .white
      c.pageBackgroundColor = .white
      c.elementBackgroundColor = .blue
      c.elementTextColor = .black
      c.lightStatusAndNavBar = false
      c.linkTextColor = .blue
			
      c.deviceName = "your device name/label"
      c.instructionalVideoFilename = "your mp4 file in main prj folder"
   }
}

Also make sure your product is not listed in the particle console as “private beta” - a private beta would require a release code and productMode=true would not work in that case.

hope this helps.

Hello @joost

We already have authentication into AppDelegate file.We tried putting customize setup after token and before token verification.

My product is also not defined as beta into account. Here i am attaching screenshot of our code for your reference.

Can you please suggest. As we still get same error and not able to proceed further.

Rakesh, you did not answer my question why you put “productMode = true” in appDelegate - you do this now by calling customizeSetup() (either before or after setting credentials). There are two seperate processes you need to be aware of:

a. the particle device setup
b. the particle login / using cloud etc.

Naturally, before your app can do anything with the particle cloud, you need to have credentials and your device setup to do this. So before your call any functions from part b. above, you need to finish part a. first. Makes sense? From your info it seems you have not gone through the setup process whereby the device is connected to your network, connected to the particle cloud and your app can reach your device. The “customizeSetup()” function is part of the (a) process, not the (b) process. (btw, I am assuming you are using the simple auth process)

In your AppDelegate() get and set your keys as you do now but remove customizeSetup(). Decide which of your viewControllers is going to be displayed first. Now you need to create some logic that determines if your device/app have been setup before or not - this could be a flag that gets set after your made a succesful connection or you can determine if you have authenticated the particle device (look in the SDK for the call) etc. For now, I’d say just hard code something in your viewWillAppear() call so you are not stunned by artifacts of this process. In viewWillAppear() we will just start the device onboarding process with calls to the particle setup sdk

viewWillAppear() {
  if let setupController = ParticleSetupMainController() {
    customizeSetup()

    if let customization = ParticleSetupCustomization.sharedInstance() {
      customization.allowSkipAuthentication = false
    }
    setupController.delegate = self as? UIViewController & ParticleSetupMainControllerDelegate

    setupController.modalPresentationStyle = .popover
    self.present(setupController, animated: true, completion:nil)
  }
}

That will get the onboarding process started. Now this viewcontroller will need to support the particle delegate so add an extension:

extension <your viewcontroller>: ParticleSetupMainControllerDelegate {
  func particleSetupViewController( _ controller:ParticleSetupMainController!,
                                                        didFinishWith result: ParticleSetupMainControllerResult,
                                                        device: ParticleDevice!) {
    switch result {
    case .succes:
    case .loggedIn:
    etc. etc.
    }
  }
}

Once the device/app go through that process, you should see your device attempting to connect to wifi and subsequently to particle cloud. You can verify proper connection by using the particle console. Your app should be connected to Wifi, then to the device’s softAP (the SDK calls will do all that), and subsequently back to your WiFi - it will then ask the particle cloud if the device has been registered and if so, get the device 24 character device ID.

For much more detail on the setup SDK go here; https://docs.particle.io/reference/SDKs/ios/#device-setup-library

For connecting to device once gone through the setup, go here: https://docs.particle.io/reference/SDKs/ios/#ios-cloud-sdk

Also read up on the authentication processes described by particle here: https://docs.particle.io/tutorials/device-cloud/authentication/

@joost

Basically we set the productMode= true for listing the customer under the specific Product. Also its like we want list all newly created customer to specific product list. I am attaching “ProductId.JPG”.

Also can you please suggest that is it mandatory to have the device already setup into my account and connected to it? Because i am just trying to achieve is the create customer under my product and later any customer can setup the device using my app.

So what i am trying to achieve is the below:
1> I have created particle account and setup the only product so have product id. No device is setup into my account.
2> Now i am making an iOS app when any customer who purchase my device should first register their account and then they can setup device individually under my product.
3> So to make customer register under my product i am first approaching the process of createUser or CreateCustomer API.
4> Once the customer setup the account later they can register the device.

So can you please suggest that “is it mandatory to have the device first connected to Particle cloud without having account setup?”

I am new and exploring the platform so i would like to get know how the process is because the documentation is not that well so anyone can understand

the flow system.

@joost

can you please suggest if i am missing anything in the my last message.

Thank you!

Hi @rakeshjiyani, I just wanted to check if you were able to get your issues resolved. If not, I can see about reaching out to our iOS developer to get some additional insight.

@mstanley Hi, my issue was not resolved yet. If get something insight help would be great help.

That's not the normal setup flow for simple auth. Any new customer can set up their device using any email address using simple auth. There's no support for limiting setup to pre-authorized customers.

In order to pre-create users and control who can create accounts with your product, you'll need to use two-legged auth. In two legged auth, you'll manage all of the customer accounts on your side, and only pass an authentication token between your server back-end and the mobile app.

@rickkas7

I am not creating any pre-user. Also we are not going to use any third party server for this (like two legged auth). we want to stick only with particle.io platform.

What i want is below:

1> I have created particle account and created product. I have product id and authclientId and authclientsecrete key. (note: I have not setup any device).

2> Now i have make one iOS app with having register form where user create account. we call
the api here as per doc:

ParticleCloud.sharedInstance().createCustomer(self.txtEmail.text!.TrimeString(), password: self.txtPassword.text!.TrimeString(), productId: XXXX, accountInfo: nil)

so can you please suggest do i am missing anything? from this?

Thank you!

It’s normally not necessary to create a customer for simple auth. The device setup SDK will create one automatically when the user signs up using your mobile app.

@rickkas7

Okay so can you please suggest what could be i need to use. if you can give one small example would help me. do its mandatory that particle device must be setup i.e. link to my account first?

You need to add the device ID to your product first. When you order devices in tray or larger quantities from the Particle wholesale store you’ll get a list of device IDs by email. For testing purposes, you can just add them manually.

You should not claim the device to your account first.

Just follow the instructions for using the Device Setup SDK for iOS or Android:

https://docs.particle.io/reference/SDKs/ios/
https://docs.particle.io/reference/SDKs/android/