How to use @esri/arcgis-rest-portal - 10 common examples

To help you get started, we’ve selected a few @esri/arcgis-rest-portal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Esri / arcgis-rest-js / demos / ago-node-cli / lib / item-search-command.js View on Github external
execute: function (query) {
    // construct the search call..
    return searchItems({
      searchForm: {
        q: query,
        start: 1,
        num: 10
      }
    })
    .then((response) => {
      // if we got results
      if (Array.isArray(response.results) && response.results.length)  {
        console.info(`${response.total} items found for "${query}".`);
        response.results.forEach((entry) => {
          console.info(`${entry.id} | ${entry.title}`);
        })
      } else {
        console.info(`No results found for "${query}".`);
      }
github Esri / arcgis-rest-js / demos / node-cli-item-management / index.js View on Github external
query.match(tag).in("tags");
          if (index !== tags.length - 1) {
            query.or();
          }
        });
        query.endGroup();
      }

      // format the search query for the search text
      if (searchText.length) {
        query.and().match(searchText);
      }

      console.log(chalk.blue(`Searching ArcGIS Online: ${query.toParam()}`));

      return searchItems({
        authentication: session,
        q: query,
        num: number
      })
      .then(response => {
        return { response, session };
      })
      .catch(err => {
        console.warn(err);
      })
    }
  );
github Esri / arcgis-rest-js / demos / ago-node-cli / lib / item-export-command.js View on Github external
execute: function (id, fileName) {
    console.info(`Exporting item ${id} to file ${fileName}`);
    // construct the search call..
    let model = {};
    return getItem(id)
    .then((item) => {
      model.item = item;
      if (this.shouldFetchData(item.type)){
        console.info(`...Fetching ./data for item of type ${item.type}`);
        return getItemData(id);
      } else {
        console.info(`...Items of type ${item.type} do not have json ./data - skipping`);
        return Promise.resolve();
      }
    })
    .then((maybeData) => {
      if (maybeData) {
        model.data = maybeData;
      }
      // now write out the file...
      jsonfile.writeFileSync(fileName, model,  {spaces: 2});
github Esri / solution.js / packages / common / src / restHelpers.ts View on Github external
id: createResponse.id,
                    resource: file,
                    name: file.name,
                    authentication: authentication,
                    params: {}
                  };

                  // Check for folder in resource filename
                  const filenameParts = file.name.split("/");
                  if (filenameParts.length > 1) {
                    addResourceOptions.name = filenameParts[1];
                    addResourceOptions.params = {
                      resourcesPrefix: filenameParts[0]
                    };
                  }
                  updateDefs.push(portal.addItemResource(addResourceOptions));
                });
              }
github Esri / solution.js / packages / common / src / restHelpers.ts View on Github external
return new Promise((resolve, reject) => {
    const updateOptions: portal.IUpdateItemOptions = {
      item: itemInfo,
      params: {
        text: data
      },
      authentication: authentication
    };
    portal.updateItem(updateOptions).then(
      () => {
        if (access && access !== "private") {
          // Set access if it is not AGOL default
          // Set the access manually since the access value in createItem appears to be ignored
          const accessOptions: portal.ISetAccessOptions = {
            id: serviceItemId,
            access: access === "public" ? "public" : "org", // need to use constants rather than string
            authentication: authentication
          };
          portal.setItemAccess(accessOptions).then(
            () => {
              progressTickCallback && progressTickCallback();
              resolve();
            },
            e => reject(generalHelpers.fail(e))
          );
github Esri / solution.js / packages / common / src / restHelpers.ts View on Github external
return new Promise((resolve, reject) => {
    const addMetadataOptions: portal.IUpdateItemOptions = {
      item: {
        id: itemId
      },
      params: {
        // Pass metadata in via params because item property is serialized, which discards a blob
        metadata: metadataFile
      },
      authentication: authentication
    };

    portal.updateItem(addMetadataOptions).then(resolve, reject);
  });
}
github Esri / solution.js / packages / common / src / resourceHelpers.ts View on Github external
isGroup: boolean = false
): Promise {
  const updateOptions: any = {
    params: {
      // Pass image in directly because item object is serialized, which discards a blob
      thumbnail: blob
    },
    authentication: authentication
  };
  updateOptions[isGroup ? "group" : "item"] = {
    id: itemId
  };

  return isGroup
    ? portal.updateGroup(updateOptions)
    : portal.updateItem(updateOptions);
}
github Esri / solution.js / packages / common / src / resourceHelpers.ts View on Github external
export function addMetadataFromBlob(
  blob: Blob,
  itemId: string,
  authentication: UserSession
): Promise {
  const updateOptions: any = {
    item: {
      id: itemId
    },
    params: {
      // Pass metadata in via params because item property is serialized, which discards a blob
      metadata: blob
    },
    authentication: authentication
  };
  return portal.updateItem(updateOptions);
}
github Esri / solution.js / packages / common / src / restHelpers.ts View on Github external
return new Promise((resolve, reject) => {
    // Update its URL
    const options = {
      item: {
        id,
        url
      },
      authentication: authentication
    };

    portal.updateItem(options).then(
      () => {
        resolve(id);
      },
      e => reject(generalHelpers.fail(e))
    );
  });
}
github Esri / arcgis-rest-js / demos / tree-shaking-rollup / src / index.js View on Github external
import { searchItems } from "@esri/arcgis-rest-portal";

let element = document.createElement("div");
document.body.appendChild(element);

searchItems("water").then(response => {
  element.innerHTML = JSON.stringify(response); // false
});