Hey @BDataimport,
Since making a twurl request seems to work as expected, then it must be that you are missing something in your code.
Have you tried using twurl's -t to get all header information? Have you checked if there are any differences compared to the requests you are making from your code? Do you do any encoding/decoding? What does the actual request look like when being sent out from your code?
If you consider the above questions and dig around a little, I am sure you will figure it out in no time!