1
0
-1

Hi,

I'm trying to automate the creation of user logins when a new contact is added to one of our groups. What object type is that in the HTTP API? I tried creating a "users" which looked the closest even though it had a bunch of extra fields, but although the request seems to have been successful, I can't find the new user anywhere on the website (it didn't create a new user login for the specified Contact ID).

Thanks,

Louis

  1. Louis Goldstein

    Sorry, there was an issue with my code... it actually wasn't succeeding. It took a bit to figure out that the required field "userType" is actually a security role (maybe roles?). The docs do not list this as a queryable field, and if I do add it to the list of fields to retrieve, in does indeed say it's an invalid field, so I found it by trial and error. 

    I'm still having problems getting it to work; it's being created, but it's not associating the login with the userContactID I'm specifying. What would cause it to leave this field blank on create?

    I've also run into another problem; if I delete the login from the web page, I still can't add another login that uses the same email address. Deleted items (that are no longer accessible from the web view) shouldn't block adding new logins, correct? I also tried a different email, and the userLogin (message says "user name") blocks it too.

    Thanks,

    Louis

CommentAdd your comment...

1 answer

  1.  
    1
    0
    -1

    Louis,

    Deleting a User marks the status as Deleted, but does not actually delete the record (for security and history purposes).  You would have to find the user and change it's status back to Active.

    My guess is that a User is in fact being created, but you can't see it because it's not active.

    I believe that the the userType would be either Volunteer or Website.  The purpose of that field is only for the initial User creation so the system know which email/links to use (either your public website URL or the RescueGroups.org account URL).

    I would strongly recommend that you use the define action on any endpoints you are planning to use.  That will give you the full definition including the acceptable values.  Here's an example of a define on the Users endpoint:

    {
        "token":"{{token}}",
        "tokenHash":"{{tokenHash}}",
        "objectType":"users",
        "objectAction":"define"
    }

     

    Also, here's an example payload that would add a User:

    {
        "token":"{{token}}",
        "tokenHash":"{{tokenHash}}",
        "objectType":"users",
        "objectAction":"add",
        "values":
        [
            {
    			"userLogin": "test122343",
    			"userPassword": "testing123",
    			"userSalutation": "Mr.",
    			"userFirstname": "Testing",
    			"userLastname": "Person",
    			"userAddress": "123 S.",
    			"userCity": "Nowhere",
    			"userState": "MO",
    			"userPostalcode": "34341",
    			"userPlus4": "1234",
    			"userCountry": "United States",
    			"userPhoneHome": "3018055081",
    			"userPhoneWork": "3018055081",
    			"userPhoneWorkExt": "123",
    			"userPhoneCell": "3018055081",
    			"userFax": "3018055081",
    			"userEmail": "test@yahoo.com",
    			"userEmailAlt": "",
    			"userEmailPager": "",
    			"userContactID": "{{contactID}}",
    			"userType": "Volunteer"
            }
        ]
    }
    1. Louis Goldstein

      Thanks for the tip on the "define" action, that is very useful. However, I'm still having problems creating the User. The only "required" fields according to the define data are userLogin, userContactID, and userType. However, if I try to create a user with just these fields, I get a General API error. 

      Request:

      {
        "values": [
          {
            "userLogin": "rtest5",
            "userContactID": 4497778,
            "userType": "Volunteer"
          }
        ],
        "token": "<token>",
        "tokenHash": "<tokenhash>",
        "objectType": "users",
        "objectAction": "add"
      }

      Reply:

      {
        "status": "error",
        "messages": {
          "generalMessages": [
            {
              "messageCriticality": "error",
              "messageText": "General API error.",
              "messageID": "1000"
            }
          ],
          "recordMessages": []
        }
      }

      If I include userEmail, userFirstname, and userLastname it succeeds (just email also produces the General API error):

      Request:

      {
        "values": [
          {
            "userLogin": "rtest5",
            "userContactID": 4497778,
            "userType": "Volunteer",
            "userEmail": "lrg12345@gmail.com",
            "userFirstname": "Rachel",
            "userLastname": "Test"
          }
        ],
        "token": "<token>",
        "tokenHash": "<tokenhash>",
        "objectType": "users",
        "objectAction": "add"
      }

      Reply:

      {
        "status": "ok",
        "messages": {
          "generalMessages": [],
          "recordMessages": [
            {
              "status": "ok",
              "ID": 1033457,
              "messageID": "1003",
              "messageCriticality": "info",
              "messageText": "Successfully saved the record."
            }
          ]
        },
        "foundRows": 0,
        "data": []
      }

      But the new User 1033457 is not associated with a Contact!

      If I submit an edit request to set it, it also succeeds:

      Request:

      {
        "values": [
          {
            "userID": 1033457,
            "userContactID": 4497778
          }
        ],
        "token": "<token>",
        "tokenHash": "<tokenhash>",
        "objectType": "users",
        "objectAction": "edit"
      }

      Reply:

      {
        "status": "ok",
        "messages": {
          "generalMessages": [],
          "recordMessages": [
            {
              "status": "ok",
              "ID": 1033457,
              "messageID": "1003",
              "messageCriticality": "info",
              "messageText": "Successfully saved the record."
            }
          ]
        },
        "foundRows": 0,
        "data": []
      }

      But it's still not associated with a contact. 

      It looks like there's something wrong with setting the userContactID value.

      Thanks,

      Louis

    2. Louis Goldstein

      Just noticed another issue; the email that gets sent out is missing the "randomly generated password"

       


      Here is your username and randomly generated password. After you
      login, you'll be able to change the password to anything you want.

      Please either copy and paste the password into the login form, or
      enter it exactly as shown below, and in UPPER CASE.

      Account number: 4853
      User name: rtest5
      Password:



      Louis

    3. Richard Saffell [RG]

      Louis, a User is not associated with a Contact until the person logs in for the first time.  I don't have a way to work around that issue.

    4. Louis Goldstein

      I'm sorry, can you be a little more descriptive of the workflow? After I log in using the new login account, it's still not associated with a Contact. It keeps taking me to the RGO home page (doesn't look like I'm logged in), but the "Last Login" field is updated (I thought this was because the login isn't associated with a user...). After logging in, setting the Contact from the API still "succeeds" with no effect.

      If I "Register a user" from the User Login Accounts for XXX, it creates the user, and does does have a contact associated with it even though the person has never logged in:

      So I'm not sure what you mean by "a User is not associated with a Contact until the person logs in for the first time". Maybe I should be asking a different question... I'm trying to automate the creation of a User Login Account when I detect a new Contact has been added in the one of our foster groups. How can I "Register a user" from the API instead of the User Login Accounts screen?

      Thanks,

      Louis

    5. Richard Saffell [RG]

      Louis,

      If you are creating a Login for an existing contact you should be able to add the User via the API and provide the userContactID.

      Also, if you are adding a User via the API you have to specify userPassword.  You should generate a random password in your app before creating the User.

      Richard

    6. Louis Goldstein

      Hi Richard,

       

      I've added the userPassword but it STILL is not associating the newly created User with the Contact. I was previously specifying the userContactID. Can you try this request and tell me what's wrong?

      {
        "values": [
          {
            "userLogin": "ltest3",
            "userContactID": 4221343,
            "userType": "Volunteer",
            "userEmail": "lrg12345@gmail.com",
            "userFirstname": "Test",
            "userLastname": "Contact",
            "userPassword": "<password>"
          }
        ],
        "token": "<token>",
        "tokenHash": "<hash>",
        "objectType": "users",
        "objectAction": "add"
      }

      The response is successful:

      {
        "status": "ok",
        "messages": {
          "generalMessages": [],
          "recordMessages": [
            {
              "status": "ok",
              "ID": 1043251,
              "messageID": "1003",
              "messageCriticality": "info",
              "messageText": "Successfully saved the record."
            }
          ]
        },
        "foundRows": 0,
        "data": []
      }

      But the User is still being created without being associated to the specified Contact:

      Thanks for your help.

      Louis

    7. Richard Saffell [RG]

      Louis,

      Right now the API does not associate the new Login with the Contact that is specified in the request.  That's certainly not what we intended, and we're looking into resolving that issue.

      Richard

    8. Louis Goldstein

      Great, thank you very much Richard! It's a relief that I'm not doing something stupid. (smile)

    CommentAdd your comment...