Method Community

 

'Object reference not set to an instance of an object.' error with MethodAPIInsertV2 endpoint

Last post 09-12-2018 1:52 PM by Method_Hossein. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 09-12-2018 9:13 AM

    'Object reference not set to an instance of an object.' error with MethodAPIInsertV2 endpoint

    Hi, 

    I'm getting this very vague error when trying to create a contact through the API. I think it might have something to do with how I'm sending in the field and value arrays, but I've tried everything and can't figure out what the issue might be. 

    What's the correct way to send those arrays in Node.js? Is there some sort of other issue going on? 

  • 09-12-2018 10:33 AM In reply to

    Re: 'Object reference not set to an instance of an object.' error with MethodAPIInsertV2 endpoint

    How are you calling the method? Are you using any SOAP package in node?

    If you share snippet of your code, we might be able to troubleshoot that for you.


  • 09-12-2018 10:37 AM In reply to

    Re: 'Object reference not set to an instance of an object.' error with MethodAPIInsertV2 endpoint

    I'm using an HTTP post. Not using a SOAP package, just a standard request library (https://www.npmjs.com/package/request). 

    Here's the request code: 

    request.post({
    url: `https://www.methodintegration.com/MethodAPI/service.asmx/MethodAPIInsertV2`,
    form: {
    strCompanyAccount: process.env.METHOD_ACCOUNT,
    strLogin: process.env.METHOD_USERNAME,
    strPassword: process.env.METHOD_PASS,
    strSessionID: '',
    strTable: 'Contacts',
    arrInsertFieldsArray: ['FirstName', 'LastName'],
    arrInsertValuesArray: ['TestFirst', 'TestLast']
    },
    headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
    }
    }

  • 09-12-2018 12:29 PM In reply to

    Re: 'Object reference not set to an instance of an object.' error with MethodAPIInsertV2 endpoint

    This endpoint is not a RESTful endpoint. You need to wrap your request in a SOAP envelope, which can be done via a post request, but it is better to use a battle tested SOAP library.

    This article will give you more context and introduces three different SOAP package for node.js:

    https://medium.com/@caleblemoine/how-to-perform-soap-requests-with-node-js-4a9627070eb6

    Hope that helps.

    Regards,

    Hossein

  • 09-12-2018 1:25 PM In reply to

    Re: 'Object reference not set to an instance of an object.' error with MethodAPIInsertV2 endpoint

    Okay, I'll definitely try that. I was initally confused because on the info page for this method (https://www.methodintegration.com/MethodAPI/service.asmx?op=MethodAPIInsertV2), you have the SOAP examples first, and then what seems to be a regular HTTP GET/POST. 

  • 09-12-2018 1:52 PM In reply to

    Re: 'Object reference not set to an instance of an object.' error with MethodAPIInsertV2 endpoint

    I see where the confusion comes from. This page is automcally generated by the tech stack that we are using, but on our servers, the direct GET and POST feature is disabled. We will investigate ways to either change the generated sample page or enable the POST request, but for now you best aproach is to use SOAP.

    Good luck with your integration!

    Hossein



      

Page 1 of 1 (6 items)