Welcome to Office 365 APIs | Microsoft Docs
Skip to main content

Office 365 APIs

This site contains the documentation for Office 365 REST APIs exposed on the OneNote and Outlook endpoints. The documentation is no longer actively updated. It is here for your reference, in case you have already included any of the API in your project.

Office 365 services, such as OneNote, Outlook, Excel, OneDrive, Microsoft Teams, Planner, and SharePoint, are now exposed in Microsoft Graph. Microsoft Graph is a unified API endpoint for accessing data across Microsoft 365, which includes Office 365, Enterprise Mobility, and Security and Windows services. It provides a simplified developer experience, with one endpoint and a single authentication token that gives your app access to data across all these services.

Our recommendation:

  • If you are starting a new app, please use Microsoft Graph.
  • If you are maintaining an existing project, use this documentation set for reference. In addition, plan your move to the latest APIs in Microsoft Graph to take advantage of all the new functionality and innovation there.
  • If you are adding new functionality to an existing project, integrate that new functionality by using Microsoft Graph.

With Microsoft Graph, you can access Office 365 data and more, from solutions across mobile, web, and desktop platforms. So whether you're building web applications by using .NET, PHP, Java, Python, or Ruby on Rails, or creating apps for the Universal Windows Platform (UWP), iOS, Android, or on another device platform, it's your choice.

In this section

 none
difference between appointment and meetingitem RRS feed

  • Question

  • Hi,

    I want to insert some links to appointment body and meetingbody(in the case they are different), so I write to functions to handle with them, both function excutes well(I mean the functions return TRUE), but the excution are different, appointment is managed to add links but meetingitem failed.

    I don't know why, is there some key difference between them and I don't know?

    Here is the two funcitons.

    BOOL CConnect::PutHyperlinkForEmcee(CComQIPtr<Outlook::_AppointmentItem> &pItem, LPCTSTR lpctReplace, LPCTSTR lpctLink, LPCTSTR lpctShow)
    {
    	if(pItem == NULL)
    	{
    		return FALSE;
    	}
    	BSTR bstrBody = NULL;
    
    	// 获取当前的inspector
    	CComQIPtr<Outlook::_Inspector> spInspector;
    	HRESULT hr = pItem->get_GetInspector(&spInspector);
    	if(SUCCEEDED(hr) && spInspector)
    	{
    		// 获取当前的WordEditor
    		IDispatch* pDispWordEditor = NULL;
    		hr = spInspector->get_WordEditor(&pDispWordEditor);
    		if(SUCCEEDED(hr) && pDispWordEditor)
    		{
    			CComPtr<Word::_Document> spDocument;
    			hr = pDispWordEditor->QueryInterface(__uuidof(_Document), (LPVOID*)&spDocument);
    			if(SUCCEEDED(hr) && spDocument)
    			{   
    				VARIANT_BOOL varIsFound = VARIANT_FALSE;
    				do
    				{
    					// 获取当前document的content属性,得到当前的Range
    					CComQIPtr<Word::Range> spLinkRange;
    					spDocument->get_Content(&spLinkRange);
    					ATLASSERT(NULL != spLinkRange);
    
    					// 根据当前Range,获取Find句柄
    					CComQIPtr<Word::Find> spFind;
    					spLinkRange->get_Find(&spFind);
    
    					// 设置find的相关属性及查找条件
    					BSTR bstrFind = (_bstr_t)lpctReplace;
    					VARIANT varFindText;
    					VARIANT_BOOL varFoward = VARIANT_TRUE;
    					VARIANT_BOOL varFomat = VARIANT_FALSE;
    					VARIANT_BOOL varMatchCase = VARIANT_FALSE;
    					VARIANT_BOOL varMatchWholeWord = VARIANT_FALSE;
    					VARIANT_BOOL varMatchWildcards = VARIANT_FALSE;
    					VARIANT_BOOL varMatchSoundsLike = VARIANT_FALSE;
    					VARIANT_BOOL varMatchAllWordForms = VARIANT_FALSE;
    
    					spFind->put_Text(bstrFind);
    					spFind->ClearFormatting();
    					HRESULT Hresrult = spFind->Replacement->ClearFormatting();
    					spFind->put_Forward(varFoward);
    					spFind->put_Wrap(wdFindContinue);
    					spFind->put_MatchCase(varMatchCase);
    					spFind->put_MatchWholeWord(varMatchWholeWord);
    					spFind->put_MatchWildcards(varMatchWildcards);
    					spFind->put_MatchSoundsLike(varMatchSoundsLike);
    					spFind->put_MatchAllWordForms(varMatchAllWordForms);
    
    					varIsFound = spFind->Execute();
    
    					if (varIsFound)
    					{
    						VARIANT content;
    						content.vt = VT_BSTR;
    						content.bstrVal = (_bstr_t)lpctLink;
    						VARIANT display;
    						display.vt = VT_BSTR;
    					    display.bstrVal = (_bstr_t)lpctShow;
    
    						CComPtr<Word::Hyperlinks> spHyperlnks;
    						spDocument->get_Hyperlinks(&spHyperlnks);
    						HRESULT hr = spHyperlnks->Add(spLinkRange, &content, NULL
    							,NULL, &display, &content);
    						//pItem->get_Body(&bstrBody);
    						if (FAILED(hr))
    						{
    							return FALSE;
    						}
    					}
    				}
    				while(varIsFound);	
    			}
    		}
    
    		if (NULL != pDispWordEditor)
    		{
    			pDispWordEditor->Release();
    			pDispWordEditor = NULL;
    		}
    	}
    	else
    	{
    		return FALSE;
    	}
    
    	return TRUE;
    }
    
    
    BOOL CConnect::PutHyperlinkForAttend(CComQIPtr<Outlook::_MeetingItem> &spMeetingItem, LPCTSTR lpctReplace, LPCTSTR lpctLink, LPCTSTR lpctShow)
    {
    	if(spMeetingItem == NULL)
    	{
    		return FALSE;
    	}
    	BSTR bstrBody = NULL;
    	spMeetingItem->get_Body(&bstrBody);
    
    	// 获取当前的inspector
    	CComQIPtr<Outlook::_Inspector> spInspector;
    	HRESULT hr = spMeetingItem->get_GetInspector(&spInspector);
    	if(SUCCEEDED(hr) && spInspector)
    	{
    		// 获取当前的WordEditor
    		IDispatch* pDispWordEditor = NULL;
    		hr = spInspector->get_WordEditor(&pDispWordEditor);
    		
    		if(SUCCEEDED(hr) && pDispWordEditor)
    		{
    			CComQIPtr<Word::_Document> spDocument;
    			hr = pDispWordEditor->QueryInterface(__uuidof(_Document), (LPVOID*)&spDocument);
    			if(SUCCEEDED(hr) && spDocument)
    			{   
    				VARIANT_BOOL varIsFound = VARIANT_FALSE;
    				do
    				{
    					// 获取当前document的content属性,得到当前的Range
    					CComQIPtr<Word::Range> spLinkRange;
    					spDocument->get_Content(&spLinkRange);
    					ATLASSERT(NULL != spLinkRange);
    
    					// 根据当前Range,获取Find句柄
    					CComQIPtr<Word::Find> spFind;
    					spLinkRange->get_Find(&spFind);
    
    					// 设置find的相关属性及查找条件
    					BSTR bstrFind = (_bstr_t)lpctReplace;
    					VARIANT varFindText;
    					VARIANT_BOOL varFoward = VARIANT_TRUE;
    					VARIANT_BOOL varFomat = VARIANT_FALSE;
    					VARIANT_BOOL varMatchCase = VARIANT_FALSE;
    					VARIANT_BOOL varMatchWholeWord = VARIANT_FALSE;
    					VARIANT_BOOL varMatchWildcards = VARIANT_FALSE;
    					VARIANT_BOOL varMatchSoundsLike = VARIANT_FALSE;
    					VARIANT_BOOL varMatchAllWordForms = VARIANT_FALSE;
    
    					spFind->put_Text(bstrFind);
    					spFind->ClearFormatting();
    					HRESULT Hresrult = spFind->Replacement->ClearFormatting();
    					
    					spFind->put_Forward(varFoward);
    					spFind->put_Wrap(wdFindContinue);
    					spFind->put_MatchCase(varMatchCase);
    					spFind->put_MatchWholeWord(varMatchWholeWord);
    					spFind->put_MatchWildcards(varMatchWildcards);
    					spFind->put_MatchSoundsLike(varMatchSoundsLike);
    					spFind->put_MatchAllWordForms(varMatchAllWordForms);
    
    					varIsFound = spFind->Execute();
    
    					if (varIsFound)
    					{
    						VARIANT content;
    						content.vt = VT_BSTR;
    						content.bstrVal = (_bstr_t)lpctLink;
    
    						VARIANT display;
    						display.vt = VT_BSTR;
    						display.bstrVal = (_bstr_t)lpctShow;
    						CComQIPtr<Word::Hyperlinks> spHyperlnks;
    						spDocument->get_Hyperlinks(&spHyperlnks);
    						HRESULT hr = spHyperlnks->Add(spLinkRange, &content, NULL
    							,NULL, &display, &content);
    						
    						if (FAILED(hr))
    						{
    							return FALSE;
    						}
    					}
    				}
    				while(varIsFound);	
    			}
    		}
    
    		if (NULL != pDispWordEditor)
    		{
    			pDispWordEditor->Release();
    			pDispWordEditor = NULL;
    		}
    	}
    	else
    	{
    		return FALSE;
    	}
    
    	return TRUE;
    }

    Monday, March 18, 2013 10:19 AM

Answers

  • ok, then i propose that you ditch wordAPI approach for meeting request (or in general) and try to add that link via rtfbody or body property. is that viable solution for you?
    • Marked as answer by SaraZC Thursday, April 11, 2013 11:23 AM
    Thursday, April 11, 2013 10:13 AM
  • Dear DamianD,
    The problem has been fixed.
    If I call Active() function of the current inpector of meetingitem, the hyperlink would be added well, although I don't know why.
    Thanks for your always help.
    Thanks a log.
    • Marked as answer by SaraZC Thursday, April 11, 2013 11:23 AM
    Thursday, April 11, 2013 11:23 AM

All replies

  • When do you call PutHyperlinkForAttend?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Monday, March 18, 2013 2:23 PM
  • After I call put_Body to meetingitem.

    Is there anything wrong?

    Thanks.

    Tuesday, March 19, 2013 3:21 AM
  • But at what point? Application.EventSend event? Items.ItemAdd event on the Sent Items folder?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Tuesday, March 19, 2013 3:57 AM
  • I put it in itemsend event;

    This is the code snippet below:

    // set body of attendee BSTR bstrTmplt = m_strAttendeeTemplt.AllocSysString(); spMeetingItem->put_Body(bstrTmplt); SysFreeString(bstrTmplt);

    PutHyperlinkForAttend(spMeetingItem,TEMPLATE_REPLACE_LINK,m_request.m_strAttendeeURL,L"click here"); // send meeting item

    spMeetingItem->Send();



    • Edited by SaraZC Tuesday, March 19, 2013 6:13 AM
    Tuesday, March 19, 2013 6:13 AM
  • Application.EventSend event.

    Thanks and hoping your answer.

    Tuesday, March 19, 2013 9:16 AM
  • Why do you need to call Send again? Can you call Save instead?

    Do you see the change in the Sent Items folder?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, March 20, 2013 1:11 PM
  • Dear Dmitry,

    I tried call Save instead, but the result is the same, the meeting in the sentItem folder is not changed too.

    So weird, because every function goes well including the function for adding hyperlinks.

    Tuesday, March 26, 2013 4:33 AM
  • Anyone can give suggestion about this question?

    Thanks.

    Tuesday, March 26, 2013 8:36 AM
  • Are those hyperlinks the same? Could you try rewriting your app to actually put hyperlink into Appointment before ItemSend event? for example on some button click in ribbon or inspector_activate event? this way Outlook will take care that meetingrequest contains your hyperlink.

    Tuesday, March 26, 2013 8:49 AM
  • Thanks Damian first.

    Those hyperlinks are not same, so I need  handle them sepretely.

    I can't put the function before ItemSend event because my data is got after the event.

    I just can't get it through, clearly the body can be changed and different after appsend event for appointment and meeting item. Why the hyperlinks failed and mean time the function of add hyperlink return a normal value. 

    Tuesday, March 26, 2013 10:28 AM
  • ok, make something simple - just replace Body of meeting request completly with hello World or something similiar - does it Work? (idea is not to touch Word api here)
    Tuesday, March 26, 2013 12:14 PM
  • " just replace Body of meeting request completly with hello World or something similiar - does it Work".

    It is ok.

    Thursday, March 28, 2013 6:34 AM
  • ok, after you add your hyperlink via wordapi in itemsend event - dump both RtfBody and Body properties to some file, log, whatever and inspect it with notepad - do they contain your added hyperlink?

    Thursday, March 28, 2013 7:20 AM
  • after I add the hyperlink to the meetingitem, I see  the sent items and use outlookspy to see the recevied meeting item, there is no hyperlink.

    About the file you talk about, sorry I can't find it in outlook  setup file, could you please tell me the dump file name?

    Thanks.

    Thursday, March 28, 2013 10:47 AM
  • file i was talking about is a text file that you will create - just dump somewhere contents of Body and RtfBody right after you  finished modifications using Word API - we need to determine when your changes are lost or if there are any changes at all.
    • Marked as answer by Quist ZhangModerator Tuesday, April 9, 2013 7:20 AM
    • Unmarked as answer by SaraZC Tuesday, April 9, 2013 8:43 AM
    Thursday, March 28, 2013 11:25 AM
  • Dear Damian,

    I serached google and cannot find a  proper way to dump RtfBody with a appointment item.....

    If it is a property of appointment, it is easy, but now it is not, it is been harder....

    Monday, April 8, 2013 2:11 AM
    • Marked as answer by Quist ZhangModerator Tuesday, April 9, 2013 7:20 AM
    • Unmarked as answer by SaraZC Tuesday, April 9, 2013 8:39 AM
    Monday, April 8, 2013 6:26 AM
  • ok, I got your idear, I will try it first in outlook 2010 to see if I can find the reason.

    Thanks.

    Monday, April 8, 2013 8:11 AM
  • Hi,DamianD,

    I found the property but I cannot find a propery function to retrieve the value.

    I used outlookspy to see the value, it is an arry of byte.

    Could you please tell me what can I get from  arry of byte?

    Thanks.

    Wednesday, April 10, 2013 8:17 AM
  • And what make confused is that code "HRESULT hr = spHyperlnks->Add(spLinkRange, &content, NULL
             ,NULL, &display, &content);" does return a S_OK, and  I think it indicates the link is added successfully, but in fact it is failed.
    Wednesday, April 10, 2013 8:19 AM
  • ok, let's just stick with simple Body property - does it get updated on meeting request after your code has run?
    Wednesday, April 10, 2013 11:45 AM
  • ok, let's just stick with simple Body property - does it get updated on meeting request after your code has run?

    Dear DamianD,

    The body of Appointment get updated after my code and the body of meetingitem don't get any change after my code.

    Thursday, April 11, 2013 2:31 AM
  • try calling save on mailitem after this modification on meeting request and see if it makes your hyperlink appear.
    Thursday, April 11, 2013 4:29 AM
  • Thanks first.

    I tried call Save after inserting hyperlink but nothing changes.

    Thursday, April 11, 2013 6:11 AM
  • I tried again and found the code "HRESULT hr = spHyperlnks->Add(spLinkRange, &content, NULL
             ,NULL, &display, &content)" returns S_FALSE, not S_OK.

    I am trying to get the reason of S_FALSE.

    Thursday, April 11, 2013 6:17 AM
  • Dear DamainD,

    I am confused, I looked about the code ""HRESULT hr = spHyperlnks->Add(spLinkRange, &content, NULL
             ,NULL, &display, &content)" for appointment and found it also returns S_FALSE and the hyperlink added successfully for appointment, the same operation failed for meetingitem.


    Thursday, April 11, 2013 6:22 AM
  • ok, try manual modifications of .Body property - just append Hello World at the end and call Save - does this change appear in both appointment and meeting request?
    Thursday, April 11, 2013 7:37 AM
  • If I just put_Body with string content, it is successfully and the content of meetingitem has been change.

    Thanks DaminaD.

    Thursday, April 11, 2013 9:10 AM
  • ok, then i propose that you ditch wordAPI approach for meeting request (or in general) and try to add that link via rtfbody or body property. is that viable solution for you?
    • Marked as answer by SaraZC Thursday, April 11, 2013 11:23 AM
    Thursday, April 11, 2013 10:13 AM
  • Dear DamianD,
    The problem has been fixed.
    If I call Active() function of the current inpector of meetingitem, the hyperlink would be added well, although I don't know why.
    Thanks for your always help.
    Thanks a log.
    • Marked as answer by SaraZC Thursday, April 11, 2013 11:23 AM
    Thursday, April 11, 2013 11:23 AM
Welcome to Office 365 APIs | Microsoft Docs
Skip to main content

Office 365 APIs

This site contains the documentation for Office 365 REST APIs exposed on the OneNote and Outlook endpoints. The documentation is no longer actively updated. It is here for your reference, in case you have already included any of the API in your project.

Office 365 services, such as OneNote, Outlook, Excel, OneDrive, Microsoft Teams, Planner, and SharePoint, are now exposed in Microsoft Graph. Microsoft Graph is a unified API endpoint for accessing data across Microsoft 365, which includes Office 365, Enterprise Mobility, and Security and Windows services. It provides a simplified developer experience, with one endpoint and a single authentication token that gives your app access to data across all these services.

Our recommendation:

  • If you are starting a new app, please use Microsoft Graph.
  • If you are maintaining an existing project, use this documentation set for reference. In addition, plan your move to the latest APIs in Microsoft Graph to take advantage of all the new functionality and innovation there.
  • If you are adding new functionality to an existing project, integrate that new functionality by using Microsoft Graph.

With Microsoft Graph, you can access Office 365 data and more, from solutions across mobile, web, and desktop platforms. So whether you're building web applications by using .NET, PHP, Java, Python, or Ruby on Rails, or creating apps for the Universal Windows Platform (UWP), iOS, Android, or on another device platform, it's your choice.

In this section