REST API

Hi,

I am trying to bulk reassign contacts assigned from one user to another one using REST API

First I am trying to filter all records assigned to one user but once I run this filter, only first record is assigned to that user and all the rest seems random and assigned to other users like the filter only worked for the first record.

Am I using filter incorrectly?

Secondly, how to use the filter to pull only specific fields? E.g. Only return a list of all contact names ("name") assigned to user "abcd" from Contacts module

Parents
  • Hi 

    The filter endpoint can be used both with a GET or a POST request. 

    From your print screen, it seems you are using a GET request, for that to work you would need to add the filter criteria in the URL instead of the body. Something like this: 

    https://<yourSugarURL>/rest/v11_16/Contacts?filter%5B0%5D%5Bassigned_user_id%5D%5B%24in%5D%5B%5D=<AssignedUserID>

    However, to avoid issues due to long URL the best is to use POST requests. 

    For that you need to add the /filter/ endpoint to the end of the URL, something like this



    https://<yourSugarURL>/rest/v11_16/Contacts/filter

    And add the filter in the body. As the Assigned user is a relationship the best is to filter for the user ID.
    You can add the information of the fields to retrieve in the filter body, on this example it will only retrieve the name (the id and date modified are retrieved by default)


    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    {
    "filter":[
    {
    "assigned_user_id":"<theUserID>"
    }
    ],
    "fields":"name"
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



    You can check more information on how to filter records on this document: 


    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.3/Cookbook/Web_Services/REST_API/Bash/How_to_Filter_a_List_of_Records/index.html


    I hope this helps, 

    André

Reply
  • Hi 

    The filter endpoint can be used both with a GET or a POST request. 

    From your print screen, it seems you are using a GET request, for that to work you would need to add the filter criteria in the URL instead of the body. Something like this: 

    https://<yourSugarURL>/rest/v11_16/Contacts?filter%5B0%5D%5Bassigned_user_id%5D%5B%24in%5D%5B%5D=<AssignedUserID>

    However, to avoid issues due to long URL the best is to use POST requests. 

    For that you need to add the /filter/ endpoint to the end of the URL, something like this



    https://<yourSugarURL>/rest/v11_16/Contacts/filter

    And add the filter in the body. As the Assigned user is a relationship the best is to filter for the user ID.
    You can add the information of the fields to retrieve in the filter body, on this example it will only retrieve the name (the id and date modified are retrieved by default)


    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    {
    "filter":[
    {
    "assigned_user_id":"<theUserID>"
    }
    ],
    "fields":"name"
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX



    You can check more information on how to filter records on this document: 


    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_12.3/Cookbook/Web_Services/REST_API/Bash/How_to_Filter_a_List_of_Records/index.html


    I hope this helps, 

    André

Children