I am having issues properly sending headers to a SOAP endpoint

Viewed 14

I have a SOAP endpoint I need to gather data from and I have a working prototype using python3 however I would like this to be a node JS project to diversify my portfolio however when sending Headers to the endpoint I have noticed an error (Media Type not supported) so I looked to the headers and noticed something odd with them, some of the keys are in quotes and other not and i believe this may be the source of the Issue, any help would be appreciated,

Headers when request is made

{
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36',
  'Content-Type': 'text/xml; charset=utf-8',
  SOAPAction: 'http://api.neatoscan.com/RequestOrdersReport',
  Host: 'desktopbridge.neatoscan.com',
  'Content-Length': '486',
  Expect: '100-continue',
  Connection: 'Keep-Alive'
}

Request Code (All vars in header are pulled from a config file to keep authentication separate from main file)

import {Client_User_Name, Token,start_date_time,end_date_time, SOAP_Header_CONTENT_TYPE,SOAP_Header_Host_Config,USER_AGENT,SOAP_actions,
    SOAP_Content_len,SOAP_urls} from './config.js';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const axios = require('axios');
const soapRequest = require('easy-soap-request');
var fs = require('fs'),parseString = require("xml2js").parseString,xml2js = require("xml2js");

var Request_Book_Order_report_XML = '/home/malachi/Desktop/Projects/Daily_Reports_Goodwill/NeatoScan/xml_files/Request_Book_Order_Report.xml'
var Report_Status_Books_XML = '/home/malachi/Desktop/Projects/Daily_Reports_Goodwill/NeatoScan/xml_files/Request_Report_Status.xml'

const url = SOAP_urls['Books_Url'];

function req(xml, headers) {
    axios.post(url,xml, headers
        ).then(response => {console.log(response.data)}
        ).catch(err => {console.log(err)});
 }

var SA = 'Book_Report_Request'
var CL = 'Book_Report_Request_Content_Len'
var url_Headers = {
  "User-Agent": USER_AGENT,'Content-Type': SOAP_Header_CONTENT_TYPE['Books_Content_Type'],'SOAPAction': SOAP_actions[SA] ,
  'Host': SOAP_Header_Host_Config['Books_Host'], 'Content-Length':SOAP_Content_len[CL], 'Expect':'100-continue', 'Connection': 'Keep-Alive'};
// 
fs.readFile(Request_Book_Order_report_XML, "utf-8", function(err, data) {
    parseString(data, function(err, result) {
      var json = result;
      var auth_filter = json['soap:Envelope']['soap:Body'][0]['RequestOrdersReport'][0];
      var auth_Client_User = auth_filter['username'] = Client_User_Name;
      var auth_token = auth_filter['token'] = Token;
      var date_start_filter = auth_filter['startDate'] = start_date_time;
      var date_end_filter = auth_filter['endDate'] = end_date_time;
      var builder = new xml2js.Builder();
      var xml = builder.buildObject(json);
      console.log(xml);
      console.log(url_Headers);
    //   req(xml, url_Headers)
        
    });
  });
0 Answers
Related