1

we are trying to import users into a specific group but cant figure out how the json should go. Currently we have:

[
    {
        "@model": "User",
        "attributes": {
            "username": "name@example.com",
            "firstName": "john",
            "lastName": "smith",
            "email": "name@example.com",
            "pending": "0",
            "lastLoginDate": "2017-08-11 04:12:06",
            "dateCreated": "2017-11-06 12:04:04",
            "dateUpdated": "2017-11-06 12:04:04"
        },
        "content": {
            "fields": {
                "customField": "00000"
            }
        },
        "settings": {
            "groups": {
                "groupId": "1"
            }
        }
    }
]

We've tried several variations on settings, permissions, and putting groups under content and attributes but nothing has worked so far.

  • You could just create the user by yourself. It requires only about 15 lines of php code to solve your issue and takes only about 5 minutes. I have used sprout because I always made those things by myself so I could help you writing your own code if you like – Robin Schambach Nov 8 '17 at 18:08
  • I have over 130,000 users to add so I need to do it this way to make it easier. – Indigo Viking Nov 8 '17 at 19:22
  • There is no difference if you want to save 10 users or 10000 users your php code won't change just your import data. I just wanted to state that such import functions are really easy to create in craft/yii so - if no one else can answer your question - writing your own or letting others write it for you might be less time consuming and more flexible for you – Robin Schambach Nov 8 '17 at 19:30
  • Thanks! We may go that route but I wanted to try this first since it is already available. Do you have a sample of the code to do what you are talking about? – Indigo Viking Nov 8 '17 at 19:37
  • Not right now since I'm not in my office currently. I just copied the code from crafts userController, removed some conditions, changed the populateModelFromPost() (or something like that) line to the normal populateModel and used my own array that has exactly the same structure like the form in your cp - you just need to inspect the html. It took me about 10 minutes to create that import. To be honest I don't think sprout did something much more complicated. You could insert a var_dump into crafts userController and try to create the same structure in your array for sprout – Robin Schambach Nov 8 '17 at 20:01
1

Sprout Import for Craft 3 supports importing Users and assigning them to User Groups. See the Users page of documentation for more info.

To do so, you just need to assign the User Group ID to the groups attribute:

[
  {
    "@model": "barrelstrength\\sproutimport\\importers\\elements\\User",
    "attributes": {
      "username": "username",
      "firstName": "First",
      "lastName": "Last",
      "email": "user@website.com",
      "pending": 1,
      "lastLoginDate": "2014-12-11 04:12:06",
      "dateCreated": "2014-04-09 12:04:04",
      "dateUpdated": "2015-04-04 06:04:08",
      "admin": "1",
      "groups": [1,2]
    }
  }
]

LEGACY RESPONSE:

Sprout Import does not yet support importing to User Groups.

While we do hope to add this feature in the future, we currently don't have an ETA. Please feel free to reach out to us directly if you'd like to discuss custom development options to help get this feature implemented.

You can add comments to or follow this feature here.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.