Hey guys I am getting this error when I try to run...
# suitetalkapi
f
Hey guys I am getting this error when I try to run the code bellow: {"The HTTP request was forbidden with client authentication scheme 'Anonymous'."}
Copy code
static void Main(string[] args)
        {
            JournalEntry newJournalEntry = new JournalEntry();

            RecordRef subsidiaryRef = new RecordRef();
            subsidiaryRef.name = "Optiver Holding Group : Optiver Holding BV : APAC : Optiver Asia Trading BV : Optiver Taiwan Futures Co. Limited";
            newJournalEntry.subsidiary = subsidiaryRef;

            RecordRef currencyRef = new RecordRef();
            currencyRef.name = "TWD";
            newJournalEntry.currency = currencyRef;

            newJournalEntry.tranDate = new DateTime(2021, 7, 06);
            newJournalEntry.memo = "FOPA_TaiwanMM_07_2021";

            newJournalEntry.lineList = new JournalEntryLineList();
            newJournalEntry.lineList.line = new JournalEntryLine[2];

            RecordRef debitAccountRef = new RecordRef();
            debitAccountRef.externalId = "40134601";

            RecordRef creditAccountRef = new RecordRef();
            creditAccountRef.externalId = "20614602";

            RecordRef costCenterRef = new RecordRef();
            costCenterRef.name = "Trading";

            RecordRef profitCenterRef = new RecordRef();
            profitCenterRef.name = "Option Taiwan";

            RecordRef locationRef = new RecordRef();
            locationRef.name = "Taiwan";

            SelectCustomFieldRef categoryRef = new SelectCustomFieldRef();
            categoryRef.scriptId = "cseg_category";
            categoryRef.value = new ListOrRecordRef();
            categoryRef.value.name = "TWD";

            SelectCustomFieldRef taxStatusRef = new SelectCustomFieldRef();
            taxStatusRef.scriptId = "cseg_apac_taxstatus";
            taxStatusRef.value = new ListOrRecordRef();
            taxStatusRef.value.name = "GENERAL";

            newJournalEntry.lineList.line[0] = new JournalEntryLine();
            newJournalEntry.lineList.line[0].account = debitAccountRef;
            newJournalEntry.lineList.line[0].memo = "Memo Test";
            newJournalEntry.lineList.line[0].department = costCenterRef;
            newJournalEntry.lineList.line[0].location = locationRef;
            newJournalEntry.lineList.line[0].@class = profitCenterRef;
            newJournalEntry.lineList.line[0].debit = 1000;
            newJournalEntry.lineList.line[0].debitSpecified = true;
            newJournalEntry.lineList.line[0].customFieldList = new CustomFieldRef[2];
            newJournalEntry.lineList.line[0].customFieldList[0] = categoryRef;
            newJournalEntry.lineList.line[0].customFieldList[1] = taxStatusRef;

            newJournalEntry.lineList.line[1] = new JournalEntryLine();
            newJournalEntry.lineList.line[1].account = creditAccountRef;
            newJournalEntry.lineList.line[1].memo = "Memo Test";
            newJournalEntry.lineList.line[1].department = costCenterRef;
            newJournalEntry.lineList.line[1].location = locationRef;
            newJournalEntry.lineList.line[1].@class = profitCenterRef;
            newJournalEntry.lineList.line[1].credit = 1000;
            newJournalEntry.lineList.line[1].creditSpecified = true;
            newJournalEntry.lineList.line[1].customFieldList = new CustomFieldRef[2];
            newJournalEntry.lineList.line[1].customFieldList[0] = categoryRef;
            newJournalEntry.lineList.line[1].customFieldList[1] = taxStatusRef;

            TokenPassport passport = new TokenPassport();
            passport.account = AccountID;
            passport.consumerKey = ConsumerKey;
            passport.token = Token;

            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] data = new byte[20];
            rng.GetBytes(data);
            int value = Math.Abs(BitConverter.ToInt32(data, 0));
            string nonce = value.ToString();
            Console.WriteLine("Nonce is " + nonce);
            passport.nonce = nonce;

            Int32 unixTimestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            string timestamp = unixTimestamp.ToString();
            Console.WriteLine("Timestamp is " + timestamp);
            passport.timestamp = Convert.ToInt64(timestamp);

            string baseString = AccountID + "&" + ConsumerKey + "&" + Token + "&" + nonce + "&" + timestamp;
            string key = ConsumerSecret + "&" + TokenSecret;
            Console.WriteLine("Base String is " + baseString);
            Console.WriteLine("Signing Key is " + key);
            string signature = "";
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] keyByte = encoding.GetBytes(key);
            byte[] messageBytes = encoding.GetBytes(baseString);
            using (HMACSHA1 myhmacsha1 = new HMACSHA1(keyByte))
            {
                byte[] hashmessage = myhmacsha1.ComputeHash(messageBytes);
                signature = Convert.ToBase64String(hashmessage);
            }
            Console.WriteLine("Computed Signature is " + signature);
            TokenPassportSignature sign = new TokenPassportSignature();
            sign.algorithm = "HMAC-SHA256";
            sign.Value = signature;
            passport.signature = sign;

            NetSuitePortTypeClient service = new NetSuitePortTypeClient(NetSuitePortTypeClient.EndpointConfiguration.NetSuitePort, ServiceURL);
            WriteResponse response;
            service.add(passport, new ApplicationInfo(), new PartnerInfo(), new Preferences(), newJournalEntry, out response);            
            Console.WriteLine(response.ToString());


            Console.WriteLine("Done");

        }
Does anyone have any idea on why? do I need to do something else besides providing a token to the service? Edit: This is C#
b
although thats not the error i would expect, it doesnt look like you implemented Token-Based Authentication
f
the snippet is wrong, let me fix it, but same error anyway =(
b
signature still looks wrong, doing hmac-sha1 while specifying the algorithm as hmac-sha256
what does your raw request look like
f
yes, fixed that encrypt as well, still same error. let me get the request
Where can I get the raw? I am a bit lost
b
i usually just post to an echo service like httpbin.org
though im not sure how well that response would work with your client
im not sure which one you are using
f
Found it
Copy code
{<?xml version="1.0" encoding="utf-16"?>
<s:Envelope xmlns:s="<http://schemas.xmlsoap.org/soap/envelope/>">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="<http://schemas.microsoft.com/ws/2005/05/addressing/none>">add</Action>
    <h:applicationInfo xmlns="urn:<http://messages_2021_1.platform.webservices.netsuite.com|messages_2021_1.platform.webservices.netsuite.com>" xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>" xmlns:xsd="<http://www.w3.org/2001/XMLSchema>" xmlns:h="urn:<http://messages_2021_1.platform.webservices.netsuite.com|messages_2021_1.platform.webservices.netsuite.com>" />
    <h:partnerInfo xmlns="urn:messages_2021_1.platform.webservices.netsuite.com" xmlns:h="urn:messages_2021_1.platform.webservices.netsuite.com" />
    <h:preferences xmlns="urn:messages_2021_1.platform.webservices.netsuite.com" xmlns:h="urn:messages_2021_1.platform.webservices.netsuite.com" />
    <h:tokenPassport xmlns="urn:messages_2021_1.platform.webservices.netsuite.com" xmlns:h="urn:messages_2021_1.platform.webservices.netsuite.com">
      <account xmlns="urn:core_2021_1.platform.webservices.netsuite.com"></account>
      <consumerKey xmlns="urn:core_2021_1.platform.webservices.netsuite.com"></consumerKey>
      <token xmlns="urn:core_2021_1.platform.webservices.netsuite.com"></token>
      <nonce xmlns="urn:core_2021_1.platform.webservices.netsuite.com">1231775382</nonce>
      <timestamp xmlns="urn:core_2021_1.platform.webservices.netsuite.com">1631699535</timestamp>
      <signature algorithm="HMAC-SHA256" xmlns="urn:core_2021_1.platform.webservices.netsuite.com"></signature>
    </h:tokenPassport>
  </s:Header>
  <s:Body xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>" xmlns:xsd="<http://www.w3.org/2001/XMLSchema>">
    <add xmlns="urn:messages_2021_1.platform.webservices.netsuite.com">
      <record xmlns:q1="urn:general_2021_1.transactions.webservices.netsuite.com" xsi:type="q1:JournalEntry">
        <q1:currency>
          <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">TWD</name>
        </q1:currency>
        <q1:subsidiary>
          <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">Optiver Holding Group : Optiver Holding BV : APAC : Optiver Asia Trading BV : Optiver Taiwan Futures Co. Limited</name>
        </q1:subsidiary>
        <q1:memo>FOPA_TaiwanMM_07_2021</q1:memo>
        <q1:lineList>
          <q1:line>
            <q1:account externalId="40134601" />
            <q1:debit>1000</q1:debit>
            <q1:memo>Memo Test</q1:memo>
            <q1:department>
              <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">Trading</name>
            </q1:department>
            <q1:class>
              <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">Option Taiwan</name>
            </q1:class>
            <q1:location>
              <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">Taiwan</name>
            </q1:location>
            <q1:customFieldList>
              <customField xsi:type="SelectCustomFieldRef" scriptId="cseg_category" xmlns="urn:core_2021_1.platform.webservices.netsuite.com">
                <value>
                  <name>TWD</name>
                </value>
              </customField>
              <customField xsi:type="SelectCustomFieldRef" scriptId="cseg_apac_taxstatus" xmlns="urn:core_2021_1.platform.webservices.netsuite.com">
                <value>
                  <name>GENERAL</name>
                </value>
              </customField>
            </q1:customFieldList>
          </q1:line>
          <q1:line>
            <q1:account externalId="20614602" />
            <q1:credit>1000</q1:credit>
            <q1:memo>Memo Test</q1:memo>
            <q1:department>
              <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">Trading</name>
            </q1:department>
            <q1:class>
              <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">Option Taiwan</name>
            </q1:class>
            <q1:location>
              <name xmlns="urn:core_2021_1.platform.webservices.netsuite.com">Taiwan</name>
            </q1:location>
            <q1:customFieldList>
              <customField xsi:type="SelectCustomFieldRef" scriptId="cseg_category" xmlns="urn:core_2021_1.platform.webservices.netsuite.com">
                <value>
                  <name>TWD</name>
                </value>
              </customField>
              <customField xsi:type="SelectCustomFieldRef" scriptId="cseg_apac_taxstatus" xmlns="urn:core_2021_1.platform.webservices.netsuite.com">
                <value>
                  <name>GENERAL</name>
                </value>
              </customField>
            </q1:customFieldList>
          </q1:line>
        </q1:lineList>
      </record>
    </add>
  </s:Body>
</s:Envelope>}
b
that doesnt quite look good, though i still dont really see how it generates the error messages you are seeing
your prolog looks wrong, it should be utf-8
and that Action header looks old, it should go in content-type http header
you should probably log the http headers too
f
do you have a sample code of the authentication plus add method?
b
authentication is probably similar to what you have
your problem is more related to the client that you are using
I dont know what you are using to generate the client you are using, but its not up to the job or not configured correctly
t
Am I reading this right that you are using HMAC 1 but saying it is using HMAC 256?
I see battk already pointed that out. what is your client code at function new NetSuitePortTypeClient ? In C# that error normally means you are setting the client to use a certificate to connect but there's no cert involved here.