Why do I receive a 402 for export report request from Salesforce?

Options
sniemz
sniemz Expensify Customer Posts: 5 Expensify Newcomer

Hi together,

I am building an integration from Expensify to Salesforce for my company and I manage to successfully request data from the integration service. However I had now to use a different class in Salesforce to send the requests and suddenly I receive an error message "Authentication error; 402". Switching back to my old code the request works still fine. Can you help me what the issue is here? Would it help to paste the apex code?

Answers

  • Sonia Liapounova
    Sonia Liapounova Expensify Success Coach - Admin, Expensify Team Posts: 210 Expensify Team
    Options

    @sniemz it's hard to guess why you're running into this error without seeing your code. If you could share the code that's throwing the error, that would be very helpful!

  • sniemz
    sniemz Expensify Customer Posts: 5 Expensify Newcomer
    Options

    The code is run in salesforce apex:

    public Object exportReport(){
    
            // create continuation with timeout
            Continuation con = new Continuation(60);
            // set callback method
            con.ContinuationMethod = 'processExportResponse';
    
            // create request
            Http http = new Http();
            HttpRequest request = new HttpRequest();
            request.setMethod('POST');
            request.setEndpoint('callout:Expensify_API');    
            request.setHeader('Content-Type', 'application/x-www-form-urlencoded'); 
            request.setBody('requestJobDescription={"type":"file","credentials":{"partnerUserID":"{!$Credential.Username}","partnerUserSecret":"{!$Credential.Password}"},"onReceive":{"immediateResponse":["returnRandomFileName"]},"inputSettings":{"type":"combinedReportData", "employeeEmail":"'+employeeEmail+'","filters":{"reportIDList":"'+expensifyReportID+'"}},"outputSettings":{"fileExtension":"csv"}}');
    
            System.debug(request.getBody());
            // add callout request to continuation
            this.exportR_requestLabel = con.addHttpRequest(request);
    
            // return continuation object
            return con;
        }
    
        // callback method from export report
        public Object processExportResponse (){
            // get response from unique continuation label
            HttpResponse response = Continuation.getResponse(this.exportR_requestLabel);
            // set output to be displayed on Visualforce page
            this.exportR_result = response.getBody();
    
            // return null to re-render original Visualforce page
            return null;
        }
    
    ```
    
  • Francois Laithier
    Francois Laithier Expensify Team Posts: 33 Expensify Team
    edited April 2020
    Options

    Hi @sniemz ,

    I see a System.debug(request.getBody()); in your code. Can you please double-check your debug logs to make sure that the requestJobDescription parameter contains a properly formatted "credentials":{"partnerUserID":"aa_something", "partnerUserSecret":"actual value"}, and ensure that the partner user ID and secret are the same as with your old code?

  • sniemz
    sniemz Expensify Customer Posts: 5 Expensify Newcomer
    Options

    Hi @Francois Laithier ,

    yes, I check again by creating one string that both the new and the old method refer to. The old method returns the file name the new one (the code is posted above) returns the Authentication error with a 402.

    Can you see anything in your logs?