web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

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

(0) ShareShare
ReportReport
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?

I have the same question (0)
  • Suggested answer
    Manoj Mane Profile Picture
    1,020 on at

    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

  • btc_dynamics Profile Picture
    on at

    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

  • btc_dynamics Profile Picture
    on at

     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?

  • Manoj Mane Profile Picture
    1,020 on at

    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
    on at

    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

  • Suggested answer
    XM-22040801-0 Profile Picture
    11 on at

    Hi,

    SELECT stagename FROM processstage WHERE _activestageid_value = 'xyz';

  • Verified answer
    Manoj Mane Profile Picture
    1,020 on at

    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

  • btc_dynamics Profile Picture
    on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 81 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans