Select to view content in your preferred language

@esri/arcgis-rest-request: How to adjust Fetch options?

949
1
10-27-2021 12:27 PM
RYANCARL
Regular Contributor

Hi all,

I am looking to adjust the Fetch request option when making a request with @esri/arcgis-rest-request, but unfortunately I cannot find any documentation related to this.

 

import fetch from "node-fetch";
import FormData from "isomorphic-form-data";
import arcgisRestRequest from "@esri/arcgis-rest-request";
arcgisRestRequest.setDefaultRequestOptions({ fetch, FormData });

arcgisRestRequest.request("https://www.arcgis.com/sharing/rest/info")
  .then(response => console.log(response));

 

 

When using the request method I am getting errors regarding the certificate of the NodeJS server:

 

FetchError: request to https://xxx/server/rest/self?token=xxx=json failed, reason: unable to get local issuer certificate

 


I would like to pass something like:

 

const fetchOptions = {
  ...
  agent:new https.Agent({rejectUnauthorized: false}),
  ...
};

 

to avoid the certificate error.

How can I accomplish this?

Tags (2)
0 Kudos
1 Reply
Raul_Jimenez
Esri Regular Contributor

I'm sorry @RYANCARL I didn't see this message. I hope the saying "better later than never applies here", at least if this isn't helpful for you anymore maybe it would be for someone else in the future:

I think setDefaultRequestOptions have to be used like this:

setDefaultRequestOptions({
  // only accepts iRequestOptions params 
  // authentication: ...,
  // credentials: ...
  // ...
  params: {
    // for additonal parameters use IParams
    agent: new https.Agent({rejectUnauthorized: false}),
  }
});

I also recommend to use the repo issues to contact the maintainers if you don't help a response soon enough in here.

I hope this helps,
Raul

0 Kudos