Managing user lookups

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsManaging user lookups
Line 1: Line 1:
 
You can use the API to manage user [[DreamFactory/Features/Lookups|lookups]].
 
You can use the API to manage user [[DreamFactory/Features/Lookups|lookups]].
  
To add a user lookup you update the user record and include the relationship 'user_lookup_by_user_id'.
+
To add a user lookup update the user record and include the relationship 'user_lookup_by_user_id'. In these examples the id of the user is 100.
 
<br/><br/>
 
<br/><br/>
 
<pre>
 
<pre>
PATCH /api/v2/system/user?related=user_lookup_by_user_id   
+
PUT /api/v2/system/user?related=user_lookup_by_user_id   
 
</pre>
 
</pre>
 
<pre>
 
<pre>
Line 10: Line 10:
 
   "resource": [
 
   "resource": [
 
     {
 
     {
       "id": 2,
+
       "id": 100,
 
       "user_lookup_by_user_id": [
 
       "user_lookup_by_user_id": [
 
         {
 
         {
Line 24: Line 24:
 
</pre>
 
</pre>
  
To retrieve user lookups you include the relationship 'user_lookup_by_user_id'.
+
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.
 
<br/><br/>
 
<br/><br/>
 
<pre>
 
<pre>
Line 33: Line 33:
 
   "resource": [
 
   "resource": [
 
     {
 
     {
       "id": 2,
+
       "id": 100,
 
       "name": "Test User",
 
       "name": "Test User",
 
       "username": null,
 
       "username": null,
Line 53: Line 53:
 
         {
 
         {
 
           "id": 1,
 
           "id": 1,
           "user_id": 2,
+
           "user_id": 100,
 
           "name": "favorite_food",
 
           "name": "favorite_food",
 
           "value": "pizza",
 
           "value": "pizza",
Line 62: Line 62:
 
           "created_by_id": null,
 
           "created_by_id": null,
 
           "last_modified_by_id": null
 
           "last_modified_by_id": null
 +
        }
 +
      ]
 +
    }
 +
  ]
 +
}
 +
</pre>
 +
 +
To delete a user lookup update the user and set the user_id for the lookups to delete to null.
 +
<br/><br/>
 +
<pre>
 +
PUT /api/v2/system/user?related=user_lookup_by_user_id 
 +
</pre>
 +
<pre>
 +
{
 +
  "resource": [
 +
    {
 +
      "id": 100,
 +
      "user_lookup_by_user_id": [
 +
        {
 +
          "id": 1
 +
          "user_id": null
 
         }
 
         }
 
       ]
 
       ]

Revision as of 18:31, 20 September 2016

You can use the API to manage user lookups.

To add a user lookup update the user record and include the relationship 'user_lookup_by_user_id'. In these examples the id of the user is 100.

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?related=user_lookup_by_user_id  
{
  "resource": [
    {
      "id": 100,
      "name": "Test User",
      "username": null,
      "first_name": "Test",
      "last_name": "User",
      "last_login_date": null,
      "email": "[email protected]",
      "is_active": true,
      "phone": "[email protected]",
      "security_question": null,
      "confirm_code": null,
      "default_app_id": null,
      "oauth_provider": null,
      "created_date": "2016-09-16 16:39:54",
      "last_modified_date": "2016-09-16 16:39:54",
      "created_by_id": 1,
      "last_modified_by_id": 1,
      "user_lookup_by_user_id": [
        {
          "id": 1,
          "user_id": 100,
          "name": "favorite_food",
          "value": "pizza",
          "private": false,
          "description": null,
          "created_date": "2016-09-16 16:39:54",
          "last_modified_date": "2016-09-16 16:39:54",
          "created_by_id": null,
          "last_modified_by_id": null
        }
      ]
    }
  ]
}

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

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