Managing user lookups

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsManaging user lookups
Line 27: Line 27:
 
<br/><br/>
 
<br/><br/>
 
<pre>
 
<pre>
GET /api/v2/system/user?related=user_lookup_by_user_id   
+
GET /api/v2/system/user/100?related=user_lookup_by_user_id   
 
</pre>
 
</pre>
 
<pre>
 
<pre>
 
{
 
{
  "resource": [
+
"id": 100,
    {
+
"name": "Test User",
      "id": 100,
+
"username": null,
      "name": "Test User",
+
"first_name": "Test",
      "username": null,
+
"last_name": "User",
      "first_name": "Test",
+
"last_login_date": "2016-09-13 16:28:08",
      "last_name": "User",
+
"email": "testuser1@dreamfactory.com",
      "last_login_date": null,
+
"is_active": true,
      "email": "t@t.com",
+
"phone": null,
      "is_active": true,
+
"security_question": null,
      "phone": "[email protected]",
+
"confirm_code": "y",
      "security_question": null,
+
"default_app_id": null,
      "confirm_code": null,
+
"oauth_provider": null,
      "default_app_id": null,
+
"created_date": "2016-09-20 14:12:59",
      "oauth_provider": null,
+
"last_modified_date": "2016-09-20 18:12:59",
      "created_date": "2016-09-16 16:39:54",
+
"created_by_id": 1,
      "last_modified_date": "2016-09-16 16:39:54",
+
"last_modified_by_id": 10,
      "created_by_id": 1,
+
"user_lookup_by_user_id": [
      "last_modified_by_id": 1,
+
{
      "user_lookup_by_user_id": [
+
"id": 1,
        {
+
"user_id": 100,
          "id": 1,
+
"name": "favorite_food",
          "user_id": 100,
+
"value": "pizza",
          "name": "favorite_food",
+
"private": false,
          "value": "pizza",
+
"description": null,
          "private": false,
+
"created_date": "2016-09-20 18:25:04",
          "description": null,
+
"last_modified_date": "2016-09-20 18:25:04",
          "created_date": "2016-09-16 16:39:54",
+
"created_by_id": null,
          "last_modified_date": "2016-09-16 16:39:54",
+
"last_modified_by_id": null
          "created_by_id": null,
+
}
          "last_modified_by_id": null
+
]
        }
+
      ]
+
    }
+
  ]
+
 
}
 
}
 
</pre>
 
</pre>
Line 72: Line 68:
 
<br/><br/>
 
<br/><br/>
 
<pre>
 
<pre>
PUT /api/v2/system/user?related=user_lookup_by_user_id   
+
PUT /api/v2/system/user/100?related=user_lookup_by_user_id   
 
</pre>
 
</pre>
 
<pre>
 
<pre>
 
{
 
{
  "resource": [
+
"user_lookup_by_user_id": [{
    {
+
"id": 17,
      "id": 100,
+
"user_id": null
      "user_lookup_by_user_id": [
+
}]
        {
+
          "id": 1
+
          "user_id": null
+
        }
+
      ]
+
    }
+
  ]
+
 
}
 
}
 
</pre>
 
</pre>

Revision as of 18:50, 20 September 2016

You can use the API to manage user lookups.

To add user lookups update the user record and include the relationship 'user_lookup_by_user_id'. In these examples the id of the user is 100 and we are adding a single lookup named 'favorite_food'.

PUT /api/v2/system/user?related=user_lookup_by_user_id  
{
  "resource": [
    {
      "id": 100,
      "user_lookup_by_user_id": [
        {
          "name": "favorite_food",
          "value": "pizza",
          "private": false,
          "description": null
        }
      ]
    }
  ]
}

To retrieve user lookups include the relationship 'user_lookup_by_user_id'. The 'user_id' field for the lookup will be set to 100. This is what links the lookup record to the user record. Since this is the first user lookup in the system its id is set to 1.

GET /api/v2/system/user/100?related=user_lookup_by_user_id  
{
	"id": 100,
	"name": "Test User",
	"username": null,
	"first_name": "Test",
	"last_name": "User",
	"last_login_date": "2016-09-13 16:28:08",
	"email": "[email protected]",
	"is_active": true,
	"phone": null,
	"security_question": null,
	"confirm_code": "y",
	"default_app_id": null,
	"oauth_provider": null,
	"created_date": "2016-09-20 14:12:59",
	"last_modified_date": "2016-09-20 18:12:59",
	"created_by_id": 1,
	"last_modified_by_id": 10,
	"user_lookup_by_user_id": [
		{
			"id": 1,
			"user_id": 100,
			"name": "favorite_food",
			"value": "pizza",
			"private": false,
			"description": null,
			"created_date": "2016-09-20 18:25:04",
			"last_modified_date": "2016-09-20 18:25:04",
			"created_by_id": null,
			"last_modified_by_id": null
		}
	]
}

To delete user lookups update the user and set the user_id for the lookups to delete to null.

PUT /api/v2/system/user/100?related=user_lookup_by_user_id  
{
	"user_lookup_by_user_id": [{
		"id": 17,
		"user_id": null
	}]
}