I stumbed across the group.notify method in the ArcGIS API for Python documentation and thought it would be useful for sending custom notifications to users when content is marked as deprecated or a group owner leaves the company and we need to notify the remaining group admins so that we can identify a new group owner. I gave it a go to test it out and got a 403 response back.
<SPAN class="comment token"># Sign in to Portal</SPAN>
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'https://myportal.domain.com/arcgis'</SPAN><SPAN class="punctuation token">,</SPAN> getpass<SPAN class="punctuation token">.</SPAN>getuser<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> getpass<SPAN class="punctuation token">.</SPAN>getpass<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Password: "</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
gis<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>me
my <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>me
<SPAN class="keyword token">for</SPAN> group <SPAN class="keyword token">in</SPAN> my<SPAN class="punctuation token">.</SPAN>groups<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> group<SPAN class="punctuation token">.</SPAN>title <SPAN class="operator token">==</SPAN> <SPAN class="string token">'testing'</SPAN><SPAN class="punctuation token">:</SPAN>
keys <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'admins'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'users'</SPAN><SPAN class="punctuation token">]</SPAN>
members <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> key <SPAN class="keyword token">in</SPAN> keys<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> user <SPAN class="keyword token">in</SPAN> group<SPAN class="punctuation token">.</SPAN>get_members<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN>key<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN>
members<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>user<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>group<SPAN class="punctuation token">.</SPAN>notify<SPAN class="punctuation token">(</SPAN>members<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Test Notification"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"This is a test notification"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"builtin"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Specifically, here's the response I'm getting:
You do <SPAN class="operator token">not</SPAN> have permissions to access this resource <SPAN class="operator token">or</SPAN> perform this operation<SPAN class="punctuation token">.</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN>
RuntimeError Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token"><</SPAN>ipython<SPAN class="operator token">-</SPAN>input<SPAN class="number token">-41</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">271dd187a943</SPAN><SPAN class="operator token">></SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
<SPAN class="number token">8</SPAN> members<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>user<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">9</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>members<SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">10</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>group<SPAN class="punctuation token">.</SPAN>notify<SPAN class="punctuation token">(</SPAN>members<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Test Notification"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"This is a test notification"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"builtin"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Miniconda\envs\gis\lib\site<SPAN class="operator token">-</SPAN>packages\arcgis\gis\__init__<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> notify<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> users<SPAN class="punctuation token">,</SPAN> subject<SPAN class="punctuation token">,</SPAN> message<SPAN class="punctuation token">,</SPAN> method<SPAN class="punctuation token">,</SPAN> client_id<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">5566</SPAN> <SPAN class="string token">"f"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"json"</SPAN>
<SPAN class="number token">5567</SPAN> <SPAN class="punctuation token">}</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">5568</SPAN> <SPAN class="keyword token">return</SPAN> self<SPAN class="punctuation token">.</SPAN>_gis<SPAN class="punctuation token">.</SPAN>_con<SPAN class="punctuation token">.</SPAN>post<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN> params<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">5569</SPAN>
<SPAN class="number token">5570</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">get_members</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Miniconda\envs\gis\lib\site<SPAN class="operator token">-</SPAN>packages\arcgis\_impl\connection<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> post<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> path<SPAN class="punctuation token">,</SPAN> postdata<SPAN class="punctuation token">,</SPAN> files<SPAN class="punctuation token">,</SPAN> ssl<SPAN class="punctuation token">,</SPAN> compress<SPAN class="punctuation token">,</SPAN> is_retry<SPAN class="punctuation token">,</SPAN> use_ordered_dict<SPAN class="punctuation token">,</SPAN> add_token<SPAN class="punctuation token">,</SPAN> verify_cert<SPAN class="punctuation token">,</SPAN> token<SPAN class="punctuation token">,</SPAN> try_json<SPAN class="punctuation token">,</SPAN> out_folder<SPAN class="punctuation token">,</SPAN> file_name<SPAN class="punctuation token">,</SPAN> force_bytes<SPAN class="punctuation token">,</SPAN> add_headers<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1181</SPAN> verify_cert<SPAN class="operator token">=</SPAN>verify_cert<SPAN class="punctuation token">,</SPAN> is_retry<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1182</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1183</SPAN> self<SPAN class="punctuation token">.</SPAN>_handle_json_error<SPAN class="punctuation token">(</SPAN>resp_json<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'error'</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> errorcode<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1184</SPAN> <SPAN class="keyword token">return</SPAN> None
<SPAN class="number token">1185</SPAN>
C<SPAN class="punctuation token">:</SPAN>\Miniconda\envs\gis\lib\site<SPAN class="operator token">-</SPAN>packages\arcgis\_impl\connection<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> _handle_json_error<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> error<SPAN class="punctuation token">,</SPAN> errorcode<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1202</SPAN>
<SPAN class="number token">1203</SPAN> errormessage <SPAN class="operator token">=</SPAN> errormessage <SPAN class="operator token">+</SPAN> <SPAN class="string token">"\n(Error Code: "</SPAN> <SPAN class="operator token">+</SPAN> str<SPAN class="punctuation token">(</SPAN>errorcode<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN><SPAN class="string token">")"</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1204</SPAN> <SPAN class="keyword token">raise</SPAN> RuntimeError<SPAN class="punctuation token">(</SPAN>errormessage<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1205</SPAN>
<SPAN class="number token">1206</SPAN> <SPAN class="keyword token">class</SPAN> <SPAN class="token class-name">_StrictURLopener</SPAN><SPAN class="punctuation token">(</SPAN>request<SPAN class="punctuation token">.</SPAN>FancyURLopener<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
RuntimeError<SPAN class="punctuation token">:</SPAN> You do <SPAN class="operator token">not</SPAN> have permissions to access this resource <SPAN class="operator token">or</SPAN> perform this operation<SPAN class="punctuation token">.</SPAN>
<SPAN class="punctuation token">(</SPAN>Error Code<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">403</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>I'm an Administrator of the Organization and Owner of this group. It seems this might be a private method available onl to Esri. If so, not cool. Share the wealth. What is the point of group.notify method if no one can use it?