Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

How do I fetch the current/active stage of an opportunity with OData API?

Posted on by

I am able to fetch an opportunity name and opportunityid by doing something like:

SELECT opportunityid, name FROM opportunity WHERE name LIKE '%search term%'.

However, now that I have the opoortunityid in the format '1d527eac-3f61-48cb-809a-12b0e7acb112', I would like to fetch the active stage of the opportunity in the Opportunity Sales Process.

If I also try to fetch stageid, salesstage in the query, they both return null. I also tried selecting

FROM opportunitysalesprocess WHERE opportunityid = '1d527eac-3f61-48cb-809a-12b0e7acb112'

but it returns: Resource not found for the segment "'opportunity sales process'".

How can I select the current/active stage of an opportunity by using the opportunityid?

  • btc_dynamics Profile Picture
    btc_dynamics on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

    I used stagename instead of activeStage but this worked, thank you.

  • Verified answer
    Manoj Mane Profile Picture
    Manoj Mane 1,012 on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

    Hi btc_dynamics,


    Yes after getting the "_activestageid_value " in first request you can retrieve the name of the activeStage name using the GUID of the "_activestageid_value "

    Thanks,

    Manoj Mane.

    Please mark this as VERIFIED if it helps. image

  • Suggested answer
    XM-22040801-0 Profile Picture
    XM-22040801-0 11 on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

    Hi,

    SELECT stagename FROM processstage WHERE _activestageid_value = 'xyz';

  • btc_dynamics Profile Picture
    btc_dynamics on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

    Hi Manoj Mane

    Is there a way to do this without using the $expand keyword? (I'm using a middle-man service that doesn't support expanding the record).

    For example, could I do something like:

    SELECT salesstage FROM {some table} WHERE _activestageid_value = 'xyz';

    Thanks

  • Manoj Mane Profile Picture
    Manoj Mane 1,012 on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

    Hi btc_dynamics

    You need to expand the activestageid record in the expand you will get the stagename. 

    As shown in below query:- 

    $select=_activestageid_value,name&$expand=activestageid($select=processstageid,stagename)&$filter=_opportunityid_value eq 'opportunnityGUID'


    Thanks,

    Manoj Mane.

    Please mark this as VERIFIED if it helps. image



  • btc_dynamics Profile Picture
    btc_dynamics on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

     Manoj Mane 

    An update on the above. I get some results when I use the plural name opportunitysalesprocesses.

    I am now a step further by using the query:

    SELECT name, _activestageid_value FROM opportunitysalesprocesses WHERE _opportunityid_value = '{opportunity_id}'

    This query gives me a result like:

    Screenshot-2023_2D00_04_2D00_07-at-14.19.19.png

    Now that i have the businessprocessflowinstanceid and _activestage_value, do you know how I can obtain the active stage name?

  • btc_dynamics Profile Picture
    btc_dynamics on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

    Hi Manoj Mane 

    When I go to the following URLs:

    my_crm_url/api/data/v9.0/process_name

    my_crm_url/api/data/v9.0/opportunitysalesprocess

    I still get the following response:

    {"error":{"code":"0x8006088a","message":"Resource not found for the segment 'process_name'."}}

    {"error":{"code":"0x8006088a","message":"Resource not found for the segment 'opportunitysalesprocess'."}}

    I've also tried selecting activestageid and _activestageid_value from opportunity but get the following response:

    {"error":{"code":"0x0","message":"Could not find a property named 'activestageid' on type 'Microsoft.Dynamics.CRM.opportunity'."}}

    I'm using DQL queries with Kloudless so might need to make multiple calls to one table at a time to get the right data.

    This is the process i'm trying to select:

    Screenshot-2023_2D00_04_2D00_07-at-09.12.38.png

  • Suggested answer
    Manoj Mane Profile Picture
    Manoj Mane 1,012 on at
    RE: How do I fetch the current/active stage of an opportunity with OData API?

    Hi btc_dynamics,

    You can refer the below query & attached ss of Opportunity:- 


    your_crm_url/api/data/v9.0/process_name ?$select=_activestageid_value,name&$expand=activestageid($select=processstageid,stagename)&$filter=_opportunityid_value eq 'opportunnityGUID'

    You need to modify the above query with your CRM URL and process name.


    pastedimage1680816529676v1.png

    pastedimage1680816815421v2.png

    Thanks,

    Manoj Mane.

    Please mark this as VERIFIED if it helps. image

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans