Select to view content in your preferred language

Saving a Portal Item Back to ArcGIS Online

1334
6
11-12-2013 11:37 AM
BillGrow
Deactivated User
Is there a method in the javascript api to save a portal item back to ArcGIS Online after making changes in a custom application? For example adjusting a webmap's initial extent.

Thanks,
~Bill
0 Kudos
6 Replies
KellyHutchins
Esri Notable Contributor
This functionality isn't available in the javascript api. In order to update ArcGIS Online content you'll need to use the ArcGIS Portal Rest API:

http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Item/02r30000007w000000/
0 Kudos
JasonZou
Frequent Contributor
Hi Kelly,

I don't see a REST operation that can be used to update the item data. Can you point out which operation is for editing and updating the item data?

Thanks,

Jason
0 Kudos
BillGrow
Deactivated User
Thanks Kelly,

I'm just getting back to this issue, so I'll give it a try. Jason, I'm assuming by looking at the page provided, updates can be made using a PUT request http://livedocs.dojotoolkit.org/dojo/request/xhr

~Bill
0 Kudos
KellyHutchins
Esri Notable Contributor
Instead of using dojo/request/xhr take a look at esri.request. It is a utility method that simplifies the process. More info on using esri.request can be found here:

https://developers.arcgis.com/en/javascript/jshelp/inside_esri_request.html
0 Kudos
JianHuang
Deactivated User
Jason,

Please take a look at the code snippet.

function updateWebMap() {
        var portal = new esri.arcgis.Portal("http://www.arcgis.com/sharing/rest");
        portal.signIn().then(getItem);
      };
function getItem(user) {
        var itemUrl = user.portal.url + "/content/items/" + webMapId;
        var request = esri.request({
          url: itemUrl,
          content: {
            "f": "json"
          }
        });
        request.then(dojo.partial(getWebMapText, user, itemUrl));
      };
function getWebMapText(user, itemUrl, item) {
        if (item.type === "Web Map") {
          //get current webmap text
          var request = esri.request({
            url: itemUrl + "/data",
            content: {
              "f": "json"
            }
          });
          request.then(dojo.partial(updateWebMapText, item, user));
        } else {
          alert("Not a Webmap item!");
        }
      };
function updateWebMapText(item, user) {
        var folder = (item.ownerFolder) ? "/" + item.ownerFolder : "";
        var userItemUrl = user.userContentUrl + folder + "/items/" + item.id;
        var webMapText = dojo.toJson(webMapJson);//your updated web map

        var contentUpdate = {
          "text": webMapText,
          "f": "json"
        };
        var request = esri.request({
          url: userItemUrl + "/update",
          content: contentUpdate
        }, {
          usePost: true
        });
        request.then(requestSucceeded);
        //console.log(userItemUrl);
      };


Hi Kelly,

I don't see a REST operation that can be used to update the item data. Can you point out which operation is for editing and updating the item data?

Thanks,

Jason
0 Kudos
JasonZou
Frequent Contributor
Cool. Thanks Jian. You always have an answer for my questions:) Happy Thanksgiving!
0 Kudos