Ethan Crabb
Ethan Crabb

Reputation: 373

Bing Ads SOAP request yeilds Error: read ECONNRESET using NodeJS strong-soap

I'm using strong-soap to make requests to the Microsoft Bing Ads API (specifically this endpoint). Here's my code:

const wsdlURI = "https://clientcenter.api.bingads.microsoft.com/Api/CustomerManagement/v13/CustomerManagementService.svc?singleWsdl";

const options = {
    envelopeKey: 's',
};

soap.createClient(wsdlURI, {
    ...options
}, (err: any, client: any) => {
    if (err) {
        throw err
    }

    client.addSoapHeader(`<h:AuthenticationToken i:nil="false">${access_token}</h:AuthenticationToken>`)
    client.addSoapHeader(`<h:DeveloperToken i:nil="false">${process.env.MICROSOFT_ADS_DEVELOPER_TOKEN}</h:DeveloperToken>`)
    client.GetUser(null, (err: any, res: any, env: any, soapHeader: any) => {
        if (err) {
            throw err
        }
        console.log("Res:", res)
        console.log("Env:", env)
    }, null)
})

The client gets created successfully, but when I call client.GetUser(), the following error is thrown:

Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
  errno: -54,
  code: 'ECONNRESET',
  syscall: 'read'
}

It's worth noting that if I remove the soap headers (AuthenticationToken & DeveloperToken), the socket does not hang up, and returns:

Authentication failed. Either supplied credentials are invalid or the account is inactive

strong-soap generates the following XML for the request:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:AuthenticationToken i:nil="false">...</h:AuthenticationToken>
    <h:DeveloperToken i:nil="false">...</h:DeveloperToken>
  </s:Header>
  <s:Body/>
</s:Envelope>

Any help would be appreciated. Many thanks.

Upvotes: 0

Views: 139

Answers (0)

Related Questions