Export from Online Feature Service Problem

1895
5
Jump to solution
03-25-2021 12:10 PM
JeffreyWilkerson
Occasional Contributor III

I'm trying to use the Export function off of an ArcGIS Online feature service, but I keep getting an error:

Export Excel Error: [request:server]: Unexpected token < in JSON at position 0

When I try to send the URL directly, I get this error:

The requested layer (layerId: export) was not found.

This is the code I'm trying to use:

// Export to excel
btnExport = document.getElementById("btnExport");
btnExport.onclick = function () {
    let exportURL = "https://services2.arcgis.com/2t1927381mhTgWNC/arcgis/rest/services/Regional_Bus_Stops/FeatureServer/export";

    exportURL += "?itemId=9feab4597b8d435e9c9ba41a4931d09f"; 
    exportURL += "&title='Regional_Bus_Stops'";
    exportURL += "&exportFormat='Excel'";
    exportURL += "&exportParameters=" + "%7b'layers'%3a%5b%7b'id'%3a0%7d%5d%7d";
    console.log(exportURL);
    esriRequest(exportURL, {
        method: "post",
        responseType: "json"
    }).then(function (response) {
        console.log(response);
    })
    .catch(function (error) {
        console.error("Export Excel Error: " + error);
    });
}

 

I think it has something to do with how I'm passing the Export parameters.  I've cleaned up the 'layer:0' text using URL encoded values, but that still doesn't seem to work.  Any help would be greatly appreciated.

Thanks, Jeff.

0 Kudos
1 Solution

Accepted Solutions
Tim_McGinnes
Occasional Contributor III

It's not the export parameters, the problem is that your URL is to the feature service, which does not have a REST export capability. If you paste just your URL string into the browser, you get the same error: The requested layer (layerId: export) was not found. 

If you have a look at the example at the bottom of the following page, it looks like the export item REST functionality needs to work from a URL pointing to the content of the owner (user) of the item:

https://developers.arcgis.com/rest/users-groups-and-items/export-item.htm 

Also note the limitation at the top of that page: Exports a service item (POST only) to the specified output format. Available only to users with an organizational subscription. Invokable only by the service item owner or an administrator.

View solution in original post

5 Replies
Tim_McGinnes
Occasional Contributor III

It's not the export parameters, the problem is that your URL is to the feature service, which does not have a REST export capability. If you paste just your URL string into the browser, you get the same error: The requested layer (layerId: export) was not found. 

If you have a look at the example at the bottom of the following page, it looks like the export item REST functionality needs to work from a URL pointing to the content of the owner (user) of the item:

https://developers.arcgis.com/rest/users-groups-and-items/export-item.htm 

Also note the limitation at the top of that page: Exports a service item (POST only) to the specified output format. Available only to users with an organizational subscription. Invokable only by the service item owner or an administrator.

JeffreyWilkerson
Occasional Contributor III

Tim,

Thanks for getting back to me.  I just thought that was an example URL so I disregarded it.  I had an Esri tech on the phone tell me that the URL provided in my sample was correct.  I didn't have the completed function at that time so I couldn't test it in front of him.  I did try to connect using a URL pointing to the the user, with Export on the end to follow up on your suggestion, but that didn't work either.  It actually gave me the same error:

Export Excel Error: [request:server]: Unexpected token < in JSON at position 0

0 Kudos
JeffreyWilkerson
Occasional Contributor III

But...

When I post the resulting URL directly , it doesn't give me an error.  Not sure where any downloaded Excel file went to, but it must be working.  

Thanks Tim, I'll accept this as the solution to how to get the ArcGIS REST API Export to work against an ArcGIS Online feature service, now I just have to figure out why my code keeps coming up with the 'unexpected token < in JSON at postion 0' error.

 

0 Kudos
Tim_McGinnes
Occasional Contributor III

That's interesting - some undocumented functionality?

The JSON response should give you the item id of the saved excel file:

{
    "type":<type of the exported  item>, 
    "size":<size of the exported item>,
    "jobId":<jobId for the export job>
    "exportItemId":<id of the exported item that is created>,
    "serviceItemId": <id  of the hosted feature service item that was exported>,
    "exportFormat": <exportFormat>
}

 I think it gets saved into the same user folder?

0 Kudos
JeffreyWilkerson
Occasional Contributor III

I'm seeing nothing new on the ArcGIS  Online side for this user.  The result of the page only shows the default "Arcgis Portal Directory" and 'Api Reference' link.

Truly not sure if it worked or not.  But now that I think about the result, I was hoping more for a file to download from the site, not be added to the content on ArcGIS Online.  I am thinking it might be better to go with a geoprocessing service on my Portal.  That way I can handle the content easier.

Thanks again for helping me out.

 

0 Kudos