function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
G_G_ 

API Error: size of unauthenticated request is too large ?

Hi I am getting the error:

 

 

EXCEEDED_MAX_SIZE_REQUEST: size of unauthenticated request is too large

 

 

I am calling the salesforce API to attach a file using the .create(sObject[]) to attach my small PDF file (129KB).

 

I am using the Developer environment is there a file size limit on this environment type? 

 

From what I found in these forms this error is the result of a bad endpoint. I have a good login and use the endpoint it provides for my dev environment. I have made other calls from this login so it should work for file attachment as well. My serverurl after a good login.(usr,pass-token):

https://na7-api.salesforce.com/services/Soap/u/21.0/00DA000000092p6

 

Incase I have code errors I have included some of my code (in C#).

 

log4net.Config.XmlConfigurator.Configure();
            ConfigurationSettings.SetDefaultConfig();
            log.Debug("UploadFil....ent_no[" + suppxo.ToString() + "])");

            try
            {
                //Login
                SFPartnerAPI.SforceService SFService = new SforceService();
                SFPartnerAPI.LoginResult lr = new LoginResult();
                lr = SFService.login(ConfigurationSettings.SF_Login_Name, ConfigurationSettings.SF_Password_And_Token);
                if (lr.passwordExpired)
                {
                    error = "Sales Force API user has an expired password. (Status Update Failed)";
                    log.Fatal(error);
                    throw new Exception(error);
                }

                log.Debug("X1:serverUrl[" + lr.serverUrl + "]");
                log.Debug("X1");
                //Setup
                SFPartnerAPI.SforceService sfs = new SFPartnerAPI.SforceService();
                ExternalSalesForceIntegration.SFPartnerAPI.SessionHeader sh = new ExternalSalesForceIntegration.SFPartnerAPI.SessionHeader();
                sh.sessionId = lr.sessionId;
                sfs.SessionHeaderValue = sh;
                XmlElement[] attachment = new XmlElement[5];
                SFPartnerAPI.sObject[] atms = new SFPartnerAPI.sObject[1];

                log.Debug("X2");

                //Get and Convert the file to an XML string for processing
                byte[] PrintedFileData = UpAPICaller.GeneratePrintedContract(pxct_id, suppxno, fileExtensionType);
                string b64str = Convert.ToBase64String(PrintedFileData); ;

                log.Debug("X3");
                //Add the converted file to an XML format for import
                for (int i = 0; i <= atms.GetUpperBound(0); i++)
                {
                    //Minimum data to create an attachment
                    attachment[0] = GetNewXmlElement("Name", fileName + "." + fileExtensionType);
                    attachment[1] = GetNewXmlElement("IsPrivate", IsPrivate.ToString());
                    attachment[2] = GetNewXmlElement("OwnerId", OwnerID);
                    attachment[3] = GetNewXmlElement("ParentId", ObjectID);
                    attachment[4] = GetNewXmlElement("Body", b64str);
                    SFPartnerAPI.sObject atm = new SFPartnerAPI.sObject();
                    atm.type = "Attachment";
                    atm.Any = attachment;
                    atms[i] = atm;
                }
                log.Debug("X4");
                log.Debug(b64str);

                //API CALL (It fails here)
                SaveResult[] sr = sfs.create(atms);

                log.Debug("X5");
                //ADD SaveResult[] Error Check
            }
            catch (Exception ex)
            {
                log.Fatal(ex);
                error = ex.Message;
            }

 

 

I would be vary happy with any help! 

 

-G_

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You don't appear to have updated the client stub with the serverUrl returned from the login call, so your create call is actually going to the login server, where the request is too large to be handled. You need to update your code so that the request goes to the correct Url.

All Answers

SuperfellSuperfell

You don't appear to have updated the client stub with the serverUrl returned from the login call, so your create call is actually going to the login server, where the request is too large to be handled. You need to update your code so that the request goes to the correct Url.

This was selected as the best answer
G_G_

Thank you so much Simon, looks like I have been using the login endpoint for all my other calls but they were small enough to process.

 

One more question then... Should I be changing my other api calls to go to the correct url? Does it preform better if I pass the url in? Why do the other calls not fail when using the login url? (I lied thats three questions.)

G_G_

 

A quick note to anyone who needs to know this was the change that worked as per Simon's instructions.

 

 

                log.Debug("X1:serverUrl[" + lr.serverUrl + "]");
                log.Debug("X1");
                //Setup
                SFPartnerAPI.SforceService sfs = new SFPartnerAPI.SforceService();
                log.Debug("BeforeUpdate:" + sfs.Url);

                //THIS IS THE CHANGE HERE
                sfs.Url = lr.serverUrl;

                log.Debug("AfterUpdate:" + sfs.Url);
                ExternalSalesForceIntegration.SFPartnerAPI.SessionHeader sh = new ExternalSalesForceIntegration.SFPartnerAPI.SessionHeader();
                sh.sessionId = lr.sessionId;
                sfs.SessionHeaderValue = sh;
                XmlElement[] attachment = new XmlElement[5];
                SFPartnerAPI.sObject[] atms = new SFPartnerAPI.sObject[1];

                log.Debug("X2");

 

Hope this helps the other "Newbies" like myself.

 

 

-G_