locked
REST API: Get a attachment for a custom entity (Javascript) RRS feed

  • Question

  • Hi,

    I want to get the documentbody from an attachment on a custom entity ("boat").
    This is the URL that I send:

    "http://xxxxxx/api/data/v8.0/annotations?$select=documentbody,filename, mimetype&$filter=objectid_boat eq 7F92C012-7CE1-E611-80D7-005056A6638B"

    ...and I get this exception back from the CRM server:

    A binary operator with incompatible types was detected. Found operand types 'Microsoft.Dynamics.CRM.boat' and 'Edm.Guid' for operator kind 'Equal'.

    I know that in the CRM database there is this attribute "objectid" that have the Guid for the boat-instance.
    But I understand that in the CRM REST API, the "objectid" doesnt exists(?) and that you must use the "objectid_<entityname>"

    What am I doing wrong?

    regards,

    Marius H. Enerud

    Monday, January 23, 2017 11:13 PM

Answers

  • Try this:

    http://xxxxxx/api/data/v8.0/annotations?$select=documentbody,filename, mimetype&$filter=objectid_value eq 7F92C012-7CE1-E611-80D7-005056A6638B

    I believe the GUID you have given here is the Guid of the boat record.


    Sachith Chandrasiri

    • Proposed as answer by Sachith Vidanage Tuesday, January 24, 2017 10:41 PM
    • Marked as answer by morris80 Tuesday, January 31, 2017 5:41 AM
    Tuesday, January 24, 2017 10:40 PM
  • Hi again, '_objectid_value' did the trick! It is working now, thanks for all help! Regards, Marius
    • Marked as answer by morris80 Tuesday, January 31, 2017 5:41 AM
    Tuesday, January 31, 2017 5:41 AM

All replies

  • Try this:

    http://xxxxxx/api/data/v8.0/annotations?$select=documentbody,filename, mimetype&$filter=objectid_value eq 7F92C012-7CE1-E611-80D7-005056A6638B

    I believe the GUID you have given here is the Guid of the boat record.


    Sachith Chandrasiri

    • Proposed as answer by Sachith Vidanage Tuesday, January 24, 2017 10:41 PM
    • Marked as answer by morris80 Tuesday, January 31, 2017 5:41 AM
    Tuesday, January 24, 2017 10:40 PM
  • Hi again,

    Thanks for you help!
    It doesn't seems to help. Now I got this error:

    "Could not find a property named 'objectid_value' on type 'Microsoft.Dynamics.CRM.annotation

    regards,

    Marius

    Wednesday, January 25, 2017 7:57 AM
  • I built this query using the REST builder developed by Jason Lattimer. Try using that and build and test your query.

    Sachith Chandrasiri

    Friday, January 27, 2017 2:45 AM
  • It seems you are using your query wrongly.

    Refer below url to get account entities attachment:

    /api/data/v8.0/accounts(1D0C2761-59CB-E611-811A-C4346BDCBF81)?$expand=Account_Annotation($select=documentbody,filename,mimetype)

    Your new query will be like this:

    http://xxxxxx/api/data/v8.0/Boats(7F92C012-7CE1-E611-80D7-005056A6638B)?$expand=Boat_Annotation($select=documentbody,filename, mimetype) 

    Download this tool to form your api queries:

    https://github.com/jlattimer/CRMRESTBuilder/releases/tag/2.5.0.0


    Regards, Saad



    • Proposed as answer by Mohd Saad Friday, January 27, 2017 7:41 AM
    • Edited by Mohd Saad Friday, January 27, 2017 7:42 AM
    Friday, January 27, 2017 7:39 AM
  • Hi,

    It may be that the retrieval of attachments (in general) are not supported on the rest API. (I remember reading something about that)

    You may need to go through the normal Soap calls to get that right.

    regards,

    Don

    Tuesday, January 31, 2017 3:30 AM
  • Hi again, '_objectid_value' did the trick! It is working now, thanks for all help! Regards, Marius
    • Marked as answer by morris80 Tuesday, January 31, 2017 5:41 AM
    Tuesday, January 31, 2017 5:41 AM