Failed to upload csv file to update Materials in Simpro from Excel VBA

Posts about the simPRO API. Help/support/how-to etc.
Forum rules
  • Check the documentation first. Before posting questions, please check the documentation to ensure it doesn't already cover what you need.
  • No spam. All automated messages, advertisements, and links to competitor websites will be deleted immediately.
  • Post in relevant sub-forums only. Messages posted in the wrong topic area will be removed and placed in the correct sub-forum by moderators.
  • Respect other users. No flaming or abusing fellow forum members. Users who continue to post inflammatory, abusive comments will be deleted from the forum after two warnings are issued by moderators.
  • Harassment. No threats or harassment of other users will be tolerated. Any instance of threatening or harassing behavior is grounds for deletion from the forums.
  • Adult content. No profanity or pornography is allowed. Posts containing adult material will be deleted.
  • Bandwidth. All images and signatures must be 500 x 500 pixels or smaller. Posts containing over-sized images and signatures will be removed.
  • Illegal content. No re-posting of copyrighted materials or other illegal content is allowed. Any posts containing illegal content or copyrighted materials will be deleted.
Post Reply
SamD
Posts: 11
Joined: Thu Mar 14, 2019 11:48 pm

Failed to upload csv file to update Materials in Simpro from Excel VBA

Post by SamD » Wed Mar 27, 2019 2:48 am

Hello ,

Is anyone come across to upload csv file to update Materials using Excel VBA?
This script was created by my predecessor and was working till last year. But Since december 2018 , it stopped working. When I tried to troubleshoot I get the validation error "Cannot DEtermine Supplier Type. Unknown error" .
When I checked the return message from the object , I could see the msg as '

<span class="left title">Session expired</span>
<div style="margin: 5px 10px;">
Your current session in this tab has expired, most likely because you have logged in to simPRO in another window or tab. Your session has been refreshed, but your most recent action has not been completed. </div>
<div class="hCenter">
<button class='btnSec btnBlue dialogClose'>OK</button> </div>


-------------------------

Here's the script for checking. I have a doubt that Simpro URL might have changed. Truly appreciate if someone can help on this to resolve.

With CreateObject("MSXML2.XMLHTTP")
'log in
.Open "POST", "https://CompanyName.simprosuite.com/", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send "loginUsername=" & username & "&loginPassword=" & password & "&login_x="

.Open "POST", "https://mettler.simprosuite.com/staff/i ... xCall=true", False
.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & Boundary
.Send SendData

.Open "POST", "https://CompanyName.simprosuite.com/sta ... ge=Generic", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send "columns%5B%5D=Group&columns%5B%5D=Part_Number&columns%5B%5D=Desription&columns%5B%5D=Cost_Price&columns%5B%5D=Trade_Price&submitForm="

.Open "POST", "https://CompanyName.simprosuite.com/sta ... ge=Generic", False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send "supplierType=0"
end with

Thank you.

Regards,
Sam
vaughan
Posts: 43
Joined: Wed May 30, 2018 6:14 am

Re: Failed to upload csv file to update Materials in Simpro from Excel VBA

Post by vaughan » Thu Mar 28, 2019 11:07 pm

Hi Sam,

simPRO implemented a security patch to prevent forged data being posted into a customers simPRO build. You can read more about it at https://en.wikipedia.org/wiki/Cross-sit ... st_forgery.

POST requests will not work without the unique CSRF token which changes frequently to avoid forged requests. You may find changing your POST requests to GET requests solves the issue for you however if any of the requests you are making needs to be a POST then you will not be able to get this to work.
SamD
Posts: 11
Joined: Thu Mar 14, 2019 11:48 pm

Re: Failed to upload csv file to update Materials in Simpro from Excel VBA

Post by SamD » Fri Mar 29, 2019 12:50 am

HI Vaugan,

Thank you so much for your reply. Whom should I contact to get the CSRF key in Simpro?

So do you mean , without CSRF key , we can't do scheduled task of updating Material Master in Simpro? Is there any other way we could do this task. B'cause everyday maually updating Material Master is a tedious task as we want to synch our ERP with Simpro. Please kindly advise is there any other method I could do this task. Appreciate your reply.

Thank you.
Sam
vaughan
Posts: 43
Joined: Wed May 30, 2018 6:14 am

Re: Failed to upload csv file to update Materials in Simpro from Excel VBA

Post by vaughan » Fri Mar 29, 2019 12:58 am

The CSRF key changes constantly to avoid forgery so there is no way to give you the CSRF key.

You should be able to replicate what you are doing using the simPRO API rather than what you are doing now which is attempting to replicate the behaviour of a user logged into simPRO via a web browser.
SamD
Posts: 11
Joined: Thu Mar 14, 2019 11:48 pm

Re: Failed to upload csv file to update Materials in Simpro from Excel VBA

Post by SamD » Fri Mar 29, 2019 5:50 am

Hi Vaugan,

Thanks for your suggestion. Appreciate it. I was struggling for the past 3 weeks why the code is not working. Atleast I got the answer. Now I need to study how to make Simpro API calls from VBA. Hope your documentation would help. If you already have any sample code , pls kindly post it.

Regards,
Sam
Post Reply