I am trying to get a tag containing spaces, such as "Endangered Species Act", into an ArcGIS Online item. I have no problem with this when sharing from ArcGIS Pro or using the AGOL web interface in a browser. But when using arcpy to share the layer to AGOL, it splits them on the spaces as well as the commas, resulting in a tag for each word.
aprx <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN>in_project<SPAN class="punctuation token">)</SPAN>
map_out <SPAN class="operator token">=</SPAN> aprx<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN>map_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># TODO: Error handling if map not found</SPAN>
layers <SPAN class="operator token">=</SPAN> map_out<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> layer <SPAN class="keyword token">in</SPAN> layers<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> layer<SPAN class="punctuation token">.</SPAN>name <SPAN class="operator token">==</SPAN> <SPAN class="string token">'ESA'</SPAN><SPAN class="punctuation token">:</SPAN>
sharing_draft <SPAN class="operator token">=</SPAN> map_out<SPAN class="punctuation token">.</SPAN>getWebLayerSharingDraft<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"HOSTING_SERVER"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FEATURE"</SPAN><SPAN class="punctuation token">,</SPAN>
agol_layer_name<SPAN class="punctuation token">,</SPAN> layer<SPAN class="punctuation token">)</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>overwriteExistingService <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>portalFolder <SPAN class="operator token">=</SPAN> agol_folder_name
sharing_draft<SPAN class="punctuation token">.</SPAN>tags <SPAN class="operator token">=</SPAN> <SPAN class="string token">'salmon, trout, Endangered Species Act, fish'</SPAN>
<SPAN class="comment token"># in summary the rest looks like this: </SPAN>
<SPAN class="comment token"># sharing_draft.exportToSDDraft()</SPAN>
<SPAN class="comment token"># arcpy.StageService_server()</SPAN>
<SPAN class="comment token"># arcpy.UploadServiceDefinition_server() </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>Here are the various things I tried:
| Input | Output |
|---|
'salmon, trout, Endangered Species Act, fish' (in the snippet above) | salmon, trout, Endangered, Species, Act, fish (splits on spaces or commas) |
"salmon, trout, 'Endangered Species Act', fish" (embed single quotes in string) | salmon, trout, 'Endangered, Species, Act', fish (still splitting, plus quote marks included) |
'salmon, trout, "Endangered Species Act", fish' (same as previous, reversing single/double quotes) | salmon, trout, "Endangered, Species, Act", fish (still splitting, plus quote marks included) |
'salmon, trout, Endangered%20Species%20Act, fish' (use HTML encoding) | salmon, trout, Endangered%20Species%20Act, fish |
['salmon', 'trout', 'Endangered Species Act', 'fish'] (as array) | ['salmon', 'trout', 'Endangered, Species, Act', 'fish'] (literally includes brackets and quotes) |
I know how to edit tags with the arcgis API, but since I'm already here using arcpy, I'd really like to solve these issues with just one toolkit.