<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: programatically register an item to the portal in ArcGIS Web AppBuilder Questions</title>
    <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652919#M17369</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alex&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No, you don't need to register them, you only need to push them in to the portal\or AGOL. You can also programmatically share new items with groups, as by default they will be private. The functions for that are &lt;A href="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Share_Items/02r30000008z000000/"&gt;here&lt;/A&gt;. The only time you would really need to register an item would be if it were an application and you were wanting to user AGOL\Portal for authentication, in which case you would to ensure that you had the correct urls for the OAuth redirects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Aug 2016 20:15:26 GMT</pubDate>
    <dc:creator>GrantCarroll1</dc:creator>
    <dc:date>2016-08-29T20:15:26Z</dc:date>
    <item>
      <title>programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652916#M17366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,is it possible to register an item to the portal&amp;nbsp;programatically? I researched&amp;nbsp;both the Javascript portal API and portalpy, and they don't seem to provide ways to do that. Are there any ways to programtically add an item to the portal?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Aug 2016 20:31:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652916#M17366</guid>
      <dc:creator>Alexwang</dc:creator>
      <dc:date>2016-08-26T20:31:23Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652917#M17367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes it is possible. Do you want to add an item and then register it? I have implemented this in C# but the basic flow would be the same using the javascript API.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To add an item&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Add_Item/02r30000008q000000/" title="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Add_Item/02r30000008q000000/"&gt;Add an item&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To register an item&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Register_App/02r30000026q000000/" title="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Register_App/02r30000026q000000/"&gt;Register an Item&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope that helps&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2016 03:31:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652917#M17367</guid>
      <dc:creator>GrantCarroll1</dc:creator>
      <dc:date>2016-08-29T03:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652918#M17368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank Grant for your replies! I want to add items (.json files and images) to the portal so they can be searchable and shared with others in portal. For this purpose, do I have to register them?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2016 13:35:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652918#M17368</guid>
      <dc:creator>Alexwang</dc:creator>
      <dc:date>2016-08-29T13:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652919#M17369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alex&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;No, you don't need to register them, you only need to push them in to the portal\or AGOL. You can also programmatically share new items with groups, as by default they will be private. The functions for that are &lt;A href="http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Share_Items/02r30000008z000000/"&gt;here&lt;/A&gt;. The only time you would really need to register an item would be if it were an application and you were wanting to user AGOL\Portal for authentication, in which case you would to ensure that you had the correct urls for the OAuth redirects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Aug 2016 20:15:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652919#M17369</guid>
      <dc:creator>GrantCarroll1</dc:creator>
      <dc:date>2016-08-29T20:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652920#M17370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Grant. Very useful info. One last question, I have looked at the sample usage from the link you sent, but not sure how to call the addItem via rest? Do I need construct an object for that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE style="color: #4d4d4d; background-color: #eeeeee; border: 1px dashed #c2c4ba; font-size: 11.44px; margin: 0px 0px 0px 15px; padding: 10px 10px 25px;"&gt;&lt;CODE style="border: 0px; font-size: 11.44px;"&gt;http://www.arcgis.com/sharing/rest/content/users/jsmith/addItem URL=http://www.mymappingapplication.com title=My Mapping Application type=Web Mapping Application tags=web, mapping, application&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Aug 2016 13:10:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652920#M17370</guid>
      <dc:creator>Alexwang</dc:creator>
      <dc:date>2016-08-30T13:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652921#M17371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Alex.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to do a post request in order to get this to work. Below is an example of this in javascript (not really a python guy sorry), i've tested this and it worked ok for me. The only thing is that you will probably need a token to add an item. I have added the code for that further down for the sake of completeness.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;//You may need to append a token to the request in order to add it in, see the code further down&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;&lt;SPAN&gt; var url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2Fcontent%2Fusers%2Fgrantcarroll_isovist%2FaddItem%2F" target="_blank"&gt;http://www.arcgis.com/sharing/rest/content/users/grantcarroll_isovist/addItem/&lt;/A&gt;&lt;SPAN&gt;"+'?token=' + token;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;esriRequest(&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url: url,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;//edit the below to add in any properties to the item that you are adding. The properties are those listed in the addItem help link in the original reply&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; content: {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;f: "json",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;&lt;SPAN&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;URL: "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.mymappingapplication.com" target="_blank"&gt;http://www.mymappingapplication.com&lt;/A&gt;&lt;SPAN&gt;",&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;title: "My Mapping Application",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type: "Web Mapping Application",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tags: "web, mapping, application"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; handleAs: "json",&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;usePost: true,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//set this if you are using a proxy &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;useProxy: false&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt;).then(lang.hitch(this, function (response) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;//The response.id is the id of your item in AGOL&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;console.log("success", response.id)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; }), lang.hitch(this, function (error) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;console.log("Error", error);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace; font-size: 13px; color: #000000;"&gt; }));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Generate a token&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-size: 13px;"&gt; var token = ""
 //need to ensure you use https to encrypt the request
&lt;/SPAN&gt;&lt;SPAN style="font-size: 13px;"&gt;&lt;SPAN&gt; var url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2FgenerateToken" target="_blank"&gt;https://www.arcgis.com/sharing/rest/generateToken&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; esriRequest(&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;url: url,&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;content: {&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;f: "json",&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;username: "&amp;lt;username&amp;gt;",&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;password: "&amp;lt;password&amp;gt;",&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;client: "referer",&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;referer: "&amp;lt;the url you are calling from&amp;gt;"&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;handleAs: "json",&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;},&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;{&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;usePost: true,&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//set this if you are using a proxy &lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;useProxy: false&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/SPAN&gt;

&lt;SPAN style="font-size: 13px;"&gt;).then(lang.hitch(this, function (response) {&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;//The response.token is your token&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;token = response.token;
&amp;nbsp;&amp;nbsp;&amp;nbsp; //You can use the token in subsequent request against secured items&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;console.log("success", response.token)&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;}), lang.hitch(this, function (error) {&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;console.log("Error", error);&lt;/SPAN&gt;
&lt;SPAN style="font-size: 13px;"&gt;}));&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;Hope all that helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:44:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652921#M17371</guid>
      <dc:creator>GrantCarroll1</dc:creator>
      <dc:date>2021-12-12T16:44:15Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652922#M17372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Wonderful! Thanks, Grant.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2016 23:16:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652922#M17372</guid>
      <dc:creator>Alexwang</dc:creator>
      <dc:date>2016-08-31T23:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652923#M17373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks, Grant! Is it possible to share your C# version&amp;nbsp;of adding/registering items? I am&amp;nbsp;sucked with one problem in my codes....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jan 2017 22:48:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652923#M17373</guid>
      <dc:creator>springzhang</dc:creator>
      <dc:date>2017-01-12T22:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652924#M17374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi see the code below, this should have everything you need, or at least get you moving in the right direction.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;[HttpPost]&lt;BR /&gt; [ActionName("PostInstall")]&lt;BR /&gt; public HttpResponseMessage PostInstall(PostInstall installDetails)&lt;BR /&gt; {&lt;BR /&gt; &lt;BR /&gt; var token = GetUserToken(installDetails.username, installDetails.password, installDetails.portalUrl);&lt;BR /&gt; var errors = new List&amp;lt;string&amp;gt;();&lt;/P&gt;&lt;P&gt;//Get the details of the current user. Only admins should be allowed to perform the post install.&lt;BR /&gt;&lt;SPAN&gt; var url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com%2Fsharing%2Frest%2Fcommunity%2Fself" rel="nofollow" target="_blank"&gt;http://www.arcgis.com/sharing/rest/community/self&lt;/A&gt;&lt;SPAN&gt;" + "?f=pjson&amp;amp;token=" + token;&lt;/SPAN&gt;&lt;BR /&gt; var portalUser = JsonConvert.DeserializeObject&amp;lt;Model.WebAppBuilder.Self&amp;gt;(AGOLHelper.DoGetRequest(url));&lt;/P&gt;&lt;P&gt;if (portalUser.role != "org_admin")&lt;BR /&gt; {&lt;BR /&gt; return new HttpResponseMessage(HttpStatusCode.Unauthorized) { Content = new StringContent(@"Only ArcGIS Portal\Online administrators can perform the post install task") };&lt;BR /&gt; }&lt;BR /&gt; UpdateSettingValue("Viewer File Location", installDetails.viewerFilePath);&lt;BR /&gt; //Create the user content url&lt;BR /&gt; var userContentUrl = GetSecurePortal(installDetails.portalUrl) + "/sharing/rest/content/users/" + installDetails.username;&lt;/P&gt;&lt;P&gt;//Create Item and add to AGOL\Portal&lt;/P&gt;&lt;P&gt;var itemDetails = new NameValueCollection();&lt;BR /&gt; var itemUrl = Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.LocalPath, "") + @"/" + this.GetApiRoot();&lt;BR /&gt; itemDetails["url"] = itemUrl;&lt;BR /&gt; itemDetails["token"] = token;&lt;BR /&gt; itemDetails["f"] = "pjson";&lt;BR /&gt; itemDetails["title"] = "LocalMaps";&lt;BR /&gt; itemDetails["type"] = "Web Mapping Application";&lt;BR /&gt; itemDetails["description"] = "LocalMaps Web Mapping Application. A colloborative application built by Eagle Technology, Isovist Ltd and GBS";&lt;BR /&gt; itemDetails["tags"] = "LocalMaps";&lt;BR /&gt; itemDetails["snippet"] = "LocalMaps";&lt;/P&gt;&lt;P&gt;var addItemUrl = userContentUrl + "/addItem";&lt;BR /&gt; var addItemResult = JsonConvert.DeserializeObject&amp;lt;AddItemResponse&amp;gt;(AGOLHelper.DoPostRequest(addItemUrl, itemDetails));&lt;/P&gt;&lt;P&gt;if (!addItemResult.success)&lt;BR /&gt; {&lt;BR /&gt; return new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(@"Unable to add LocalMaps to AGOL\Portal") };&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; //Share Item&lt;BR /&gt; var shareDetails = new NameValueCollection();&lt;BR /&gt; shareDetails["token"] = token;&lt;BR /&gt; shareDetails["f"] = "pjson";&lt;BR /&gt; shareDetails["everyone"] = "true";&lt;BR /&gt; shareDetails["items"] = addItemResult.id;&lt;/P&gt;&lt;P&gt;var shareItemUrl = userContentUrl + "/shareItems";&lt;BR /&gt; var shareItemResult = JsonConvert.DeserializeObject&amp;lt;ShareItemResult&amp;gt;(AGOLHelper.DoPostRequest(shareItemUrl, shareDetails));&lt;/P&gt;&lt;P&gt;var shareLocalMapsResult = shareItemResult.results.Where(o =&amp;gt; o.itemId == addItemResult.id).FirstOrDefault();&lt;BR /&gt; if (shareLocalMapsResult == null)&lt;BR /&gt; {&lt;BR /&gt; return new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(@"Sharing LocalMaps Failed") };&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;if (!shareLocalMapsResult.success)&lt;BR /&gt; {&lt;BR /&gt; return new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(@"Sharing LocalMaps Failed") };&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;//Register App&lt;BR /&gt; var uris = new List&amp;lt;string&amp;gt;() { itemUrl };&lt;BR /&gt; var registerAppUrl = &amp;lt;portalUrl&amp;gt; + "/sharing/rest/oauth2/registerApp"; //this needs to be https&lt;BR /&gt; var registerAppDetails = new NameValueCollection();&lt;BR /&gt; registerAppDetails["token"] = token;&lt;BR /&gt; registerAppDetails["f"] = "pjson";&lt;BR /&gt; registerAppDetails["itemId"] = addItemResult.id;&lt;BR /&gt; registerAppDetails["appType"] = "browser";&lt;BR /&gt; registerAppDetails["redirect_uris"] = JsonConvert.SerializeObject(uris);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; var registerAppResult = JsonConvert.DeserializeObject&amp;lt;RegisterAppResult&amp;gt;(AGOLHelper.DoPostRequest(registerAppUrl, registerAppDetails));&lt;BR /&gt; //registerAppResult will have the details you need about client_id etc&lt;BR /&gt; &lt;BR /&gt; return new HttpResponseMessage(HttpStatusCode.OK);&lt;BR /&gt;}&lt;BR /&gt; &lt;BR /&gt; public static class AGOLHelper&lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; public static string DoGetRequest(string url)&lt;BR /&gt; {&lt;BR /&gt; //make the request to the server&lt;/P&gt;&lt;P&gt;HttpWebResponse httpResponse = HttpWebGetRequest(url, "");&lt;/P&gt;&lt;P&gt;//check for errors&lt;BR /&gt; if (httpResponse == null)&lt;BR /&gt; return null;&lt;/P&gt;&lt;P&gt;//get the JSON representation from the response&lt;BR /&gt; return DeserializeResponse(httpResponse.GetResponseStream());&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public static string DoPostRequest(string url,NameValueCollection data)&lt;BR /&gt; {&lt;/P&gt;&lt;P&gt;string responseData;&lt;BR /&gt; var webClient = new WebClient();&lt;BR /&gt; var response = webClient.UploadValues(url, data);&lt;BR /&gt; responseData = System.Text.Encoding.UTF8.GetString(response);&lt;BR /&gt; return responseData;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; public static HttpWebResponse HttpWebGetRequest(string url, string referer)&lt;BR /&gt; {&lt;BR /&gt; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);&lt;BR /&gt; httpWebRequest.Method = "GET";&lt;BR /&gt; if (referer != string.Empty)&lt;BR /&gt; httpWebRequest.Referer = referer;&lt;BR /&gt; try&lt;BR /&gt; {&lt;BR /&gt; return (HttpWebResponse)httpWebRequest.GetResponse();&lt;BR /&gt; }&lt;BR /&gt; catch(Exception ex) {&lt;BR /&gt; return null;&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public static string DeserializeResponse(System.IO.Stream stream)&lt;BR /&gt; {&lt;BR /&gt; string JSON = string.Empty;&lt;/P&gt;&lt;P&gt;using (StreamReader reader = new StreamReader(stream))&lt;BR /&gt; JSON = reader.ReadToEnd();&lt;/P&gt;&lt;P&gt;return JSON;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private static byte[] ObjectToByteArray(object obj)&lt;BR /&gt; {&lt;BR /&gt; if (obj == null)&lt;BR /&gt; return null;&lt;BR /&gt; BinaryFormatter bf = new BinaryFormatter();&lt;BR /&gt; using (MemoryStream ms = new MemoryStream())&lt;BR /&gt; {&lt;BR /&gt; bf.Serialize(ms, obj);&lt;BR /&gt; return ms.ToArray();&lt;BR /&gt; }&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; public class RegisterAppResult&lt;BR /&gt; {&lt;BR /&gt; public string itemId { get; set; }&lt;/P&gt;&lt;P&gt;public string client_id { get; set; }&lt;/P&gt;&lt;P&gt;public string client_secret { get; set; }&lt;/P&gt;&lt;P&gt;public string appType { get; set; }&lt;/P&gt;&lt;P&gt;public List&amp;lt;string&amp;gt; redirect_uris { get; set; }&lt;/P&gt;&lt;P&gt;public string registered { get; set; }&lt;/P&gt;&lt;P&gt;public string modified { get; set; }&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt; &lt;BR /&gt; public class ShareItemResult&lt;BR /&gt; {&lt;BR /&gt; public List&amp;lt;ShareResult&amp;gt; results { get; set; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;public class ShareResult&lt;BR /&gt; {&lt;BR /&gt; public string itemId { get; set; }&lt;/P&gt;&lt;P&gt;public bool success { get; set; }&lt;/P&gt;&lt;P&gt;public string[] notSharedWith { get; set; }&lt;/P&gt;&lt;P&gt;public AgolError error { get; set; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;public class AgolError&lt;BR /&gt; {&lt;BR /&gt; public int code { get; set; }&lt;/P&gt;&lt;P&gt;public string message { get; set; }&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt; &lt;BR /&gt; public class AddItemResponse&lt;BR /&gt; {&lt;BR /&gt; public bool success { get; set; }&lt;BR /&gt; public string id { get; set; }&lt;BR /&gt; public string folder { get; set; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jan 2017 00:20:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652924#M17374</guid>
      <dc:creator>GrantCarroll1</dc:creator>
      <dc:date>2017-01-13T00:20:08Z</dc:date>
    </item>
    <item>
      <title>Re: programatically register an item to the portal</title>
      <link>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652925#M17375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks so much! It is really helpful!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 13 Jan 2017 15:02:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-web-appbuilder-questions/programatically-register-an-item-to-the-portal/m-p/652925#M17375</guid>
      <dc:creator>springzhang</dc:creator>
      <dc:date>2017-01-13T15:02:53Z</dc:date>
    </item>
  </channel>
</rss>

