I used Google docs to tried to delete some rows in table by use DeleteTableRowRequest but I met exception with specify TableStartLocation property. My code is below:
public static void DeleteRequestGDocs(List<Request> requestsList, int? index2Del)
{
Request request = new Request();
Location tableLocation = new Location();
tableLocation.SegmentId = string.Empty;
tableLocation.Index = 11;
TableCellLocation tableCellLocationDel = new TableCellLocation();
tableCellLocationDel.RowIndex = index2Del;
tableCellLocationDel.ColumnIndex = 0;
tableCellLocationDel.TableStartLocation = tableLocation;
DeleteTableRowRequest delRequest = new DeleteTableRowRequest();
delRequest.TableCellLocation = tableCellLocationDel;
request.DeleteTableRow = delRequest;
requestsList.Add(request);
}
Please help me
Update 1: When program exetute to delete. I met error "Invalid requests[0].deleteTableRow: Invalid table start location. Must specify the start index of the table." with code below
var bodyDelete = new BatchUpdateDocumentRequest();
bodyDelete.Requests = requestsDeleteList;
var batchDeleteRequest = docsService.Documents.BatchUpdate(bodyDelete, mergedFile.Id);
var resultDelete = await batchDeleteRequest.ExecuteAsync();
You should make sure that tableStartLocation in your request matches the value of startIndex for the table you are trying to access in the document you are editing.
The corresponding part of the document JSON with the startIndex should look like the following:
{
"startIndex": 12,
"endIndex": 23,
"table": {...}
},
See related issue in google tracker here: https://issuetracker.google.com/issues/158124540
Related
This question is related to Google Sheets API (C#).
I have to write more than 1000 rows into a Google sheet, therefore I need to increase the number of rows (I got the Google.Apis.Requests.RequestError when I attempted to write 4640 rows).
Searching the Stack Overflow website resulted in information telling me that I needed to use UpdateSheetPropertiesRequest or InsertDimensionRequest and create a new request that could be in the same Spreadsheets.BatchUpdate call.
In line with this Python example, I set the properties of the InsertDimensionRequest instance and included them in my existing code (= publicly available C# code by Ian Preston).
The code then looks like this:
public void AddCells(GoogleSheetParameters googleSheetParameters, List<GoogleSheetRow> rows)
{
var requests = new BatchUpdateSpreadsheetRequest { Requests = new List<Request>() }; //Existing code
int sheetId = GetSheetId(_sheetsService, _spreadsheetId, googleSheetParameters.SheetName); //Existing code
InsertDimensionRequest insertDimensionRequest = new InsertDimensionRequest(); //Added code
insertDimensionRequest.Range.SheetId = sheetId; //Added code
insertDimensionRequest.Range.Dimension = "ROWS"; //Added code
insertDimensionRequest.Range.StartIndex = 999; //Added code
insertDimensionRequest.Range.EndIndex = 6999; //Added code
insertDimensionRequest.InheritFromBefore = false; //Added code
var request = new Request { UpdateCells = new UpdateCellsRequest { Start = gc, Fields = "*" } }; //Existing code
//some code here
var request1 = new Request { ???????? }; //code to be added - how should the request look like?
requests.Requests.Add(request); //Existing code
requests.Requests.Add(request1); //Added code
}
But I do not know how a new request can be created in C#.
My question is: How to create such an request (named as request1 in my code)?
Meanwhile, I have managed to figure out an answer.
DimensionRange dr = new DimensionRange
{
SheetId = sheetId,
Dimension = "ROWS",
StartIndex = 999,
EndIndex = 6999 // adding extra 6000 rows
};
var request1 = new Request { InsertDimension = new InsertDimensionRequest { Range = dr, InheritFromBefore = false } };
And then (the order of the requests matters):
requests.Requests.Add(request1);
requests.Requests.Add(request);
EDIT 01-06-2022: The entire code using the aforementioned snippet can be downloaded from GitHub - see the GoogleSheets project there.
It is also possible to use userEnteredValue. This clears the sheet and, for me inexplicably, sets the number of rows to an unknow value, but my 4640 rows were accepted.
EDIT 31-05-2022: If you know more about the usage of userEnteredValue, feel free to elaborate on this matter.
GridRange dr2 = new GridRange
{
SheetId = sheetId
};
var request2 = new Request { UpdateCells = new UpdateCellsRequest { Range = dr2, Fields = "userEnteredValue" } };
And then (the order of the requests probably also matters):
requests.Requests.Add(request2);
requests.Requests.Add(request);
I'm trying to get response from FedEx Tracking API by using developer account credentials (UserCredentials) and I do not own ParentCredentials because I'm not Compatible User.
The code looks like this:
TrackRequest request = new TrackRequest();
request.WebAuthenticationDetail = new WebAuthenticationDetail();
request.WebAuthenticationDetail.UserCredential = new WebAuthenticationCredential();
request.WebAuthenticationDetail.UserCredential.Key = "XXX"; // Replace "XXX" with the Key
request.WebAuthenticationDetail.UserCredential.Password = "XXX"; // Replace "XXX" with the Password
request.WebAuthenticationDetail.ParentCredential = null;
request.ClientDetail = new ClientDetail();
request.ClientDetail.AccountNumber = "XXX"; // Replace "XXX" with the client's account number
request.ClientDetail.MeterNumber = "XXX"; // Replace "XXX" with the client's meter number
request.TransactionDetail = new TransactionDetail();
request.TransactionDetail.CustomerTransactionId = "***Track Request using VC#***"; //This is a reference field for the customer. Any value can be used and will be provided in the response.
request.Version = new VersionId();
// Tracking information
request.SelectionDetails = new TrackSelectionDetail[1] { new TrackSelectionDetail() };
request.SelectionDetails[0].PackageIdentifier = new TrackPackageIdentifier();
request.SelectionDetails[0].PackageIdentifier.Value = "123456789012"; // Replace "XXX" with tracking number or door tag
//if (usePropertyFile()) //Set values from a file for testing purposes
//{
// request.SelectionDetails[0].PackageIdentifier.Value = getProperty("trackingnumber");
//}
request.SelectionDetails[0].PackageIdentifier.Type = TrackIdentifierType.TRACKING_NUMBER_OR_DOORTAG;
// Date range is optional.
// If omitted, set to false
//request.SelectionDetails[0].ShipDateRangeBegin = DateTime.Parse("06/18/2012"); //MM/DD/YYYY
request.SelectionDetails[0].ShipDateRangeEnd = request.SelectionDetails[0].ShipDateRangeBegin.AddDays(0);
request.SelectionDetails[0].ShipDateRangeBeginSpecified = false;
request.SelectionDetails[0].ShipDateRangeEndSpecified = false;
// Include detailed scans is optional.
// If omitted, set to false
request.ProcessingOptions = new TrackRequestProcessingOptionType[1];
request.ProcessingOptions[0] = TrackRequestProcessingOptionType.INCLUDE_DETAILED_SCANS;
So, this is just a regular example that every developer user can access and main difference is that I do not use ParentCredentials.
The endpoint for accessing API is: https://ws.fedex.com/web-services/track
UserCredentials that I use are valid.
The response that I get contains the error message and the error code from the title of this question. How can I avoid it?
I have an invoice with multiple lines that I want to consolidate into one line. It takes the and iterates through each . It sums each to a variable. After the loop, it should create a new line on the invoice and delete the others.
I keep getting a "TxnLineID: required field is missing" even though I am providing it as "-1" for a new line:
private static void Main(string[] args)
{
// creates the session manager object using QBFC
var querySessionManager = new QBSessionManager();
// want to know if a session has begun so it can be ended it if an error happens
var booSessionBegun = false;
try
{
// open the connection and begin the session with QB
querySessionManager.OpenConnection("", "Test Connection");
querySessionManager.BeginSession("", ENOpenMode.omDontCare);
// if successful then booSessionBegin = True
booSessionBegun = true;
// Get the RequestMsgSet based on the correct QB Version
var queryRequestSet = GetLatestMsgSetRequest(querySessionManager);
// Initialize the message set request object
queryRequestSet.Attributes.OnError = ENRqOnError.roeStop;
// QUERY RECORDS **********************
// appendInvoiceQuery to request set
// only invoices that start with the consulting invoice prefix
// include all of the line items
// only unpaid invoices
var invoiceQ = queryRequestSet.AppendInvoiceQueryRq();
invoiceQ.ORInvoiceQuery.InvoiceFilter.ORRefNumberFilter.RefNumberFilter.MatchCriterion.SetValue(ENMatchCriterion.mcStartsWith);
invoiceQ.ORInvoiceQuery.InvoiceFilter.ORRefNumberFilter.RefNumberFilter.RefNumber.SetValue("ML-11");
invoiceQ.ORInvoiceQuery.InvoiceFilter.PaidStatus.SetValue(ENPaidStatus.psNotPaidOnly);
invoiceQ.IncludeLineItems.SetValue(true);
// DELETE INVOICE ***********************************
// var deleteI = queryRequestSet.AppendTxnDelRq();
// deleteI.TxnDelType.SetValue(ENTxnDelType.tdtInvoice);
// deleteI.TxnID.SetValue("3B57C-1539729221");
// Do the request and get the response message set object
var queryResponseSet = querySessionManager.DoRequests(queryRequestSet);
// Uncomment the following to view and save the request and response XML
var requestXml = queryRequestSet.ToXMLString();
// Console.WriteLine(requestXml);
SaveXML(requestXml, 1);
var responseXml = queryResponseSet.ToXMLString();
// Console.WriteLine(responseXml);
SaveXML(responseXml, 2);
// Get the statuscode of the response to proceed with
var respList = queryResponseSet.ResponseList;
var ourResp = respList.GetAt(0);
var statusCode = ourResp.StatusCode;
// Test what the status code
if (statusCode == 0)
{
// Parse the string into an XDocument object
var xmlDoc = XDocument.Parse(responseXml);
// Set the xmlDoc root
var xmlDocRoot = xmlDoc.Root.Element("QBXMLMsgsRs")
.Element("InvoiceQueryRs")
.Elements("InvoiceRet");
var i = 1;
// Iterate through the elements to get values and do some logic
foreach (var invoiceElement in xmlDocRoot)
{
// Create connection to update
var updateSessionManager = new QBSessionManager();
updateSessionManager.OpenConnection("", "Test Connection");
updateSessionManager.BeginSession("", ENOpenMode.omDontCare);
// Make the request set for updates
var updateRequestSet = GetLatestMsgSetRequest(updateSessionManager);
updateRequestSet.Attributes.OnError = ENRqOnError.roeStop;
// Set the variables required to edit a file
var txnId = (string) invoiceElement.Element("TxnID");
var editSequence = (string) invoiceElement.Element("EditSequence");
var xmlLineItemRoot = invoiceElement.Elements("InvoiceLineRet");
var feeAmount = 0.0f;
foreach (var invoiceLineItemElement in xmlLineItemRoot)
{
if (invoiceLineItemElement.Element("ItemRef").Element("FullName").Value == "Consulting Fees:Consulting")
{
feeAmount = float.Parse(invoiceLineItemElement.Element("Amount").Value) + (float) feeAmount;
}
}
//// UPDATING RECORDS ******************************
//// TxnID and EditSequence required
var invoiceM = updateRequestSet.AppendInvoiceModRq();
invoiceM.TxnID.SetValue(txnId);
invoiceM.EditSequence.SetValue(editSequence);
invoiceM.ORInvoiceLineModList.Append().InvoiceLineMod.TxnLineID.SetValue("-1");
invoiceM.ORInvoiceLineModList.Append().InvoiceLineMod.ItemRef.FullName.SetValue("Consulting Fees:Consulting");
invoiceM.ORInvoiceLineModList.Append().InvoiceLineMod.Amount.SetValue((double)feeAmount);
updateSessionManager.DoRequests(updateRequestSet);
i++;
updateSessionManager.EndSession();
updateSessionManager.CloseConnection();
}
}
// end and disconnect after done
querySessionManager.EndSession();
booSessionBegun = false;
querySessionManager.CloseConnection();
}
catch (Exception e)
{
// if it couldn't connect then display a message saying so and make sure to EndSession/CloseConnection
Console.WriteLine(e.Message.ToString() + "\nStack Trace: \n" + e.StackTrace + "\nExiting the application");
if (booSessionBegun)
{
querySessionManager.EndSession();
querySessionManager.CloseConnection();
}
}
}
Furthermore, I want it to remove the lines from the invoice that were used in the sum. I've read conflicting information on how to do this.
One camp says, don't specify those lines and it will erase them when the updateRequestSet is executed. Another contradicts by saying that not specifying them, it will retain them. Can someone please clear this up. I haven't gotten far enough to test, however.
Oh and here is the entirety of the error:
InvoiceMod
ORInvoiceLineModList:
element(2) - InvoiceLineMod:
TxnLineID: required field is missing
End of InvoiceLineMod
End of ORInvoiceLineModList
End of InvoiceMod
Stack Trace:
at Interop.QBFC13.IQBSessionManager.DoRequests(IMsgSetRequest request)
at ConsolidateInvoiceLineItems.Program.Main(String[] args) in C:\qb\QuickBooks\ConsolidateInvoiceLineItems\ConsolidateInvoiceLineItems\Program.cs:line 226
Exiting the application
Wish I could take credit for this, but actually got help from the Intuit Developers forum.
Need to change the multiple Append() to the following:
var invoiceModLineItems = invoiceM.ORInvoiceLineModList.Append().InvoiceLineMod;
invoiceModLineItems.TxnLineID.SetValue("-1");
invoiceModLineItems.ItemRef.FullName.SetValue("Consulting Fees:Consulting");
invoiceModLineItems.Amount.SetValue((double)feeAmount);
I am trying to get the total count of api keys in my API gateway via SDK.
However I am unsure on the proper implementation of the parameters that the GetApiKeysRequest takes in. My main objective is to get the count of all API keys that are already existing for my account.
The code I have so far looks like this :
class Program
{
public static void Main(string[] args)
{
var awsUserAccessKey = "xxxxx";
var awsUserSecretKey = "yyyyyyyyyyy";
var regionEndpoint = "us-west-2";
var keysInRepository = new GetApiKeysRequest
{
CustomerId = "",
IncludeValues = true||false,
Limit=0,
NameQuery = "",
Position = ""
};
var client = new AmazonAPIGatewayClient(awsUserAccessKey, awsUserSecretKey, regionEndpoint);
var apiKeys =client.GetApiKeys(keysInRepository);
Console.Read();
}
}
This code throws an error saying that The security token included in the request is invalid (Amazon.APIGateway exception).I am unsure on how to set the parameters for this request.
Because the AmazonAPIGatewayClient you are using as described here takes three string arguments and the last one is awsSessionToken i think you are confusing with this one which takes as third argument RegionEndpoint
Do something like that instead :
var client = new AmazonAPIGatewayClient(awsUserAccessKey, awsUserSecretKey, RegionEndpoint.USWest2);
For someone looking for a solution to similar problems, this worked :
var awsUserAccessKey = "xxxx";
var awsUserSecretKey = "yyyyy";
var regionEndpointName = "us-west-2";
var regionEndpoint = RegionEndpoint.GetBySystemName(regionEndpointName);
var keysInRepository = new GetApiKeysRequest
{
Limit = 500
};
//define the key and its fields
var client = new AmazonAPIGatewayClient(awsUserAccessKey, awsUserSecretKey, regionEndpoint);
var apiKeys = client.GetApiKeys(keysInRepository);
Console.WriteLine("Current number of api keys:{0}", apiKeys.Items.Count);
In ServiceNow, I am able to get only a maximum of 250 records in a SOAP request. How to get all the records?
Web Reference Url = https://*****.service-now.com/rm_story.do?WSDL
Code:
var url = "https://*****.service-now.com/rm_story.do?SOAP";
var userName = *****;
var password = *****;
var proxy = new ServiceNow_rm_story
{
Url = url,
Credentials = new NetworkCredential(userName, password)
};
try
{
var objRecord = new Namespace.WebReference.getRecords
{
// filters..
};
var recordResults = proxy.getRecords(objRecord);
}
catch (Exception ex)
{
}
In recordResults, I am getting only 250 records. How to get all the records ?
Also see this stack overflow answer which provides info.
Get ServiceNow Records Powershell - More than 250
Note that returning a large number of records can affect performance of the response and it may be more efficient to process your query in batches using offsets (i.e., get 1-100, then 101-200, ...). This can be achieved by using a sort order and offset. The ServiceNow REST Table API actually returns link headers from Get requests providing you links for the first, next and last set of records making it easy to know the url to query the next batch of records.
See: http://wiki.servicenow.com/index.php?title=Table_API#Methods
and look under 'Response Header'.
Have u tried to pass/override __limit parameter?
Google / wiki / Users manual / Release notes are always helpful
In your code snippet in line where it says //filter you should define __limit (and potentially __first_row and __last_row as explained in the example bellow)
int Skip = 0;
int Take = 250;
while (true)
{
using (var soapClient = new ServiceNowLocations.ServiceNow_cmn_location())
{
var cred = new System.Net.NetworkCredential(_user, _pass);
soapClient.Credentials = cred;
soapClient.Url = _apiUrl + "cmn_location.do?SOAP";
var getParams = new ServiceNowLocations.getRecords()
{
__first_row = Skip.ToString(),
__last_row = (Skip + Take).ToString(),
__limit = Take.ToString()
};
var records = soapClient.getRecords(getParams);
if (records != null)
{
if (records.Count() == 0)
{
break;
}
Skip += records.Count();
if (records.Count() != Take)
{
// last batch or everything in first batch
break;
}
}
else
{
// service now web service endpoint not configured correctly
break;
}
}
}
I made an library that handles interacting with ServiceNow Rest API much easier
https://emersonbottero.github.io/ServiceNow.Core/