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  I have a couple of questions about the filtering feature:

    • Is it completely safe to go from GET to the POST request to do all the filtering or are there any restrictions to be considered?
    • The "fields" parameter is optional.:
    1. What happens to the ResultSet in case I do not send this parameter? Only the "required fields" will be returned or all of the fields?
    2. There are some cases in which when querying the endpoint with the list of all fields returned by the metadata throws an error.(500 Internal Server Error). It'd be helpful to see on the documentation the restrictions that may be present. Ie. Module: Opportunities. These are the fields that throw an error when added to the fields list on the URL: (What is the logic behind this? How can I distinguish which field not to include in fields filter?)

    Relationships:

    1- Does this endpoint return the EXACT same results as filtering the Contact module with account_id IN(....) so that I can filter with more than 1 relation id? https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_11.0/Integration/Web_Services/REST_API/Endpoints/modulerecordlinklink_name_GET/

    2- Do we have a way to perform a "join" where for instance: I have a relation "contacts" linking between ContactModule and Accounts module with type many-to-may? I'd like to get in 1 single Json all the fields from module Contacts and module Accounts just like inner joining them in Database

  • Hi

    Let me see if I can answer all your questions: 

    1 - Yes, the POST works better if you want to add a lot of conditions as you'll be adding them in the request body. 

    More information here: 

    https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_11.0/Integration/Web_Services/REST_API/Endpoints/modulefilter_POST/

    2 - I you don't specify the fields, all fields with be returned. 

    3 - If you get a 500 error, try checking the sugarcrm.log and the PHP error log for more information on the specific error. 



    Relationships

    1 - Not sure if I understand the question, this endpoint will allow you to,for example, retrieve all the Opportunities of a specific account like this 

    https://<yoursugarurl>/rest/v11/Accounts/<accountID>/link/opportunities

    2 - I don't believe this is an out-of-the-box feature of our API, if you want all the fields I believe you need to call for Contacts and then Accounts for the record id that you desire. My colleague Harald has a good post on that here. 

    You could create a custom endpoint to return whatever you need, but can you clarify what is the business scenario for this requirement and maybe we can find a different approach?

Reply Children
  • Hi

    Thanks for the detailed answers!!

    For the Relationships issue, What I'd like to achieve is to get the data of both the Accounts and Opportunities, using one single endpoint.

    The closest I've come to this is by adding the name of the related module on the list of fields in the /filter endpoint.

    Let me explain it in examples.

    Parent Module: Cases,

    Child Module: Documents,

    Relationship: documents_cases (Many to Many)

    What I've done:

    POST https://{{INSTANCE_NAME}}/rest/v11/Cases/filter

    {
    "max_num":"10",
    "fields":"id,name,date_entered,description,deleted,case_number,type,status,priority,resolution,work_log......,documents"
    }

    By adding the "documents" in the list of fields, now I can get an array of documents for each Case record, and similarly vice versa if I query the /Documents/filter endpoint with the "cases" added in the fields list.

    The problem here is that I get only the Id of the document, but not all the fields that the Document module has.

    Tried something like: https://sugarclub.sugarcrm.com/dev-club/f/questions-answers/1397/how-can-i-retrieve-fields-from-related-records-in-a-rest-filter-post-request

    {
    "max_num":"10",
    "fields":"id,name,date_entered,description,deleted,case_number,type,status,priority,resolution,work_log,{'name':'documents','fields':['id','name','doc_url','filename']}"
    }

    but the API completely ignores the documents part.

    Any idea what we can do to force the API to return those fields?