0
// Search for Company 
 var newRequestBody = {
 "pageSize": 1,
 "companyName": "Costco",
 "streetName": "Lake Dr",
 "streetNumber": "999",
 "town": "Issaquah",
 "postalCode": "98027",
 "countryCode": "US",
 "extendCountrySearch": "true"
 }


 var search_Auth_Headers = {};
 search_Auth_Headers['Content-Type'] = 'application/json';
 search_Auth_Headers['authorization'] = 'Bearer ' + AccessToken;


 var search_for_company = https.request({
     method: https.Method.POST,
     url: 'https://api.eulerhermes.com/search/v2/companies/advancedSearch',
     body: JSON.stringify(newRequestBody),
     headers: search_Auth_Headers
 });

I am making an API call to get AccessToken and that part is working fine. Then I am using that access token to make another API call (see below) - and for some reason, this is the result when I log search for company

{"type":"http.ClientResponse","code":200,"headers":{"Cache-Control":"no-cache, no-store, max-age=0, must-revalidate","cache-control":"no-cache, no-store, max-age=0, must-revalidate","content-length":"0","Content-Length":"0","Content-Type":"application/json","content-type":"application/json","Date":"Fri, 05 Nov 2021 13:18:25 GMT","date":"Fri, 05 Nov 2021 13:18:25 GMT","Expires":"0","expires":"0","Pragma":"no-cache","pragma":"no-cache","Strict-Transport-Security":"max-age=63072000; includeSubdomains;","strict-transport-security":"max-age=63072000; includeSubdomains;","Via":"1.1 249557823ab8e41dec2ed10311f8ff98.cloudfront.net (CloudFront)","via":"1.1 249557823ab8e41dec2ed10311f8ff98.cloudfront.net (CloudFront)","x-amz-apigw-id":"IVRNQE4gFiAFmbw=","X-Amz-Apigw-Id":"IVRNQE4gFiAFmbw=","X-Amz-Cf-Id":"k6SbsDRYs6cUvfY4GoFWpA8dRQzLIhiNvrAWOH_58YfHkcp20wUHzA==","x-amz-cf-id":"k6SbsDRYs6cUvfY4GoFWpA8dRQzLIhiNvrAWOH_58YfHkcp20wUHzA==","X-Amz-Cf-Pop":"EWR53-C1","x-amz-cf-pop":"EWR53-C1","x-amzn-Remapped-Connection":"keep-alive","x-amzn-remapped-connection":"keep-alive","X-Amzn-Remapped-Connection":"keep-alive","x-amzn-Remapped-Date":"Fri, 05 Nov 2021 13:18:25 GMT","x-amzn-remapped-date":"Fri, 05 Nov 2021 13:18:25 GMT","X-Amzn-Remapped-Date":"Fri, 05 Nov 2021 13:18:25 GMT","x-amzn-Remapped-Server":"nginx","x-amzn-remapped-server":"nginx","X-Amzn-Remapped-Server":"nginx","x-amzn-RequestId":"50a5f695-0810-4d0e-9c43-16f1e58a2668","x-amzn-requestid":"50a5f695-0810-4d0e-9c43-16f1e58a2668","X-Amzn-Requestid":"50a5f695-0810-4d0e-9c43-16f1e58a2668","X-Cache":"Miss from cloudfront","x-cache":"Miss from cloudfront","X-Content-Type-Options":"nosniff","x-content-type-options":"nosniff","X-Frame-Options":"DENY","x-frame-options":"DENY","X-XSS-Protection":"1; mode=block","x-xss-protection":"1; mode=block","X-Xss-Protection":"1; mode=block"},"body":""}
dbc
  • 91,441
  • 18
  • 186
  • 284
  • Check the docs again. `http(s).request` doesn't have an option `body`. You need to `write` the body into the request and then `end` it. I think it would be simpler to use a library for this like `node-fetch` or `axios`. See https://nodejs.dev/learn/make-an-http-post-request-using-nodejs – CherryDT Nov 05 '21 at 13:23

0 Answers0