How can I query custom fields with the Fogbugz API? - fogbugz

I'm using the Python fogbugz module to access the XML API:
from fogbugz import FogBugz
fb = FogBugz(url=S_FOGBUGZ_URL, token=TOKEN)
respBug = fb.search(
q=str(ixBug),
cols="sTitle,sPersonAssignedTo,sProject,sArea,sCategory,sPriority,sStatus,events",
)
How can I add a custom field to the list of columns?

Use customFields as column name. The XML in the response is pretty messed up though, with weird tag names.
I found the answer by looking at the correspondence of the Firefox web client with the server.

Related

How i cant iterate a json object in power apps without use power automate

I have a custom connector with microsoft graph api in my power apps and i have a request and a response with graph explorer, now my problem is they i can't iterate the object in my power apps table.
OnSelect code:
UpdateContext({getrols:graph_demo.GetRols()})
Issue shown in PowerApps
View of API Response
You may try adding .value to the end of your formula. You'd likely then add .appRoles to .value to get into the nested JSON.
When in doubt, add a . to your formula and leverage the IntelliSense to explore your response schema.
Something like: ClearCollect(coRols, graph_demo.GetRols().value.appRoles)
Also, try using a Gallery to show the response instead of a ListBox. Set the Gallery Items property to colRols.

Provide the 'allowthrottleablequeries' preference to allow this

I have developed an API using Microsoft Graph API. I am encountering below issue.
URL that I am calling :
/v1.0/sites/root/lists/cb32cc85-5351-423d-b2ec-bb418c1d9c64/items?
$filter=fields/Created gt '2018-1-1T00:00:00'
&expand=fields
&$orderby=createdDateTime
&$top=10
Error returned from the API :
Field 'Created' cannot be referenced in filter or orderby as it is not indexed. Provide the 'allowthrottleablequeries' preference to allow this, but be warned that such queries may fail on large lists.
How to enable allowthrottleablequeries as it says and how should I achieve this?
I'm afraid this isn't a very clear or useful error message. As far as I know, there isn't actually a way to enable allowthrottleablequeries.
This happens when a SharePoint list grows too large to handle filtering or sorting non-indexed columns. The fix is to add an index to the created column in your List Settings. You can find instructions on how to accomplish this in Add an index to a SharePoint column.
Try to send your request with following Request Header
Prefer: allowthrottleablequeries
If it does not work then try the following Request Header
Prefer: HonorNonIndexedQueriesWarningMayFailRandomly

Not able to filter messages based on header properties in Azure Stream analytics

I have created an Azure Stream Analytics (ASA) job to filter data based on a custom header property i send from a client app.
How would i read/filter message header properties in Azure stream analytics?
The portal return no results when i try to test out my query. Below is my query in azure portal.
So far this is my query as simple as this:
SELECT
*
INTO
[mystorage]
FROM
[iothubin]
WHERE Properties.type = "type1"
I also tried to call out the key without its parent (such as: where type = "") with no results as well.
I am sure that i am sending messages with this custom property in the header since i can view it using device explorer tool.
any idea how to get this working?
I haven't tried this yet myself, but supposedly you can access custom properties via GetMetadataPropertyValue(). Give this a try:
https://msdn.microsoft.com/en-us/library/azure/mt793845.aspx
You can use the query described here as an example to query complex schemas.
If you share your schema, we can look at the query for you.
Let me know if it works for you.
Thanks,
JS

Ask QB to make a check, get check info back later

I am a python developer, not a QB user, so please forgive me for using poor terminology.
We have an internal web application that is used by finance staff to identify small sets of payment requests for a particular payee. They then use QB to generate a check to pay that payee. Then they manually enter the check number and date back into the web app. I am modifying the web application so that the finance staff can use the app to bundle the payment requests together and - I hope - send a request to QB for the checks, one per payee. The data to send would be the payee information, the check amount, and whatever else is required. The data to get back from QB (later) would be the check number and check date and some identifier that I can use to match it up with the requests sent earlier.
What is the best way to implement this communication with QB?
I use python3, to construct qbXML queries, and Elementree to parse the responses.
I use a non-Windows machine for developement, too. I found that I really needed QB and Python together in a Windows VM to make progress. Both QB and COM require it.
Here are a couple snippets in Python 3.1 to show how I do it:
First, use COM to connect to QuickBooks and disconnect from QuickBooks.
import win32com.client
def start(external_application_name):
"""Connect a QuickBooks instance using COM. Start QB if needed"""
SessionManager = win32com.client.Dispatch("QBXMLRP2.RequestProcessor")
# Example only - insecure!
SessionManager.OpenConnection('', external_application_name)
return SessionManager
def stop(SessionManager):
"""Disconnect from the existing Quickbooks instance."""
SessionManager.CloseConnection()
return
Next, I use python to do the logic, construct the qbXML queries, and parse the responses into an ElementTree.
import xml.etree.ElementTree as etree
def xml_query(QB_SessionManager, company_file_path, qbXML_query_string):
"""
Do a QuickBooks QBXML query.
The query must be valid - this function doesn't do error checking.
Return an ElementTree of the XML response.
"""
ticket = QB_SessionManager.BeginSession(company_file_path, 0)
response_string = QB_SessionManager.ProcessRequest(ticket, qbXML_query_string)
#print(response_string) # Debug tool
SessionManager.EndSession(ticket)
QBXML = etree.fromstring(response_string)
response_tree = QBXML.find('QBXMLMsgsRs')
#etree.dump(QBXML) # Debug tool
return response_tree
The actual qbXML query string and response string for a check query are on the qbXML reference at https://member.developer.intuit.com/qbSDK-current/Common/newOSR/index.html
There, you will see that you can download the check data filtered by payee, date range, check number range, etc.
You can chain multiple XML queries or transactions into a single large XML file. Assign each a unique request number (Example: <CustomerQueryRq requestID="1"> ), so you can locate the proper response.
Use the <IncludeRetElement> tag to limit the reply size, and speed the search tremendously.
As your app is not a SaaS app, so you can use qbsdk for this use case.
sdk download link - https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits
IIF files are no longer supported. IIF files can be imported directly into QB, but it would bypass all the business logic.

How can I format a Google Sheets spreadsheet cell with the API?

My application generates a table of data and creates a new spreadsheet document in a user's Google Drive. How can I add formatting (color, font-weight, width, etc.) to individual cells? I can't seem to find any documentation, much less how I could implement this through the google-api-ruby-client.
Most of my findings date back to Google API mailing lists that state it isn't supported.
However, I found that another application accomplishes my desired result. An example of "Smartsheet" exporting a document to Google Drive:
From Smartsheet.com:
And the resulting sheet in my Google Drive:
(Feb 2017) As of Google I/O 2016, developers no longer need to export to Excel nor create a new Sheet w/the desired formatting, so the other answers are now dated. You can now format cells using the Google Sheets API. Here's a short Python example that bolds the 1st row (assuming the file ID is SHEET_ID and SHEETS is the API service endpoint):
DATA = {'requests': [
{'repeatCell': {
'range': {'endRowIndex': 1},
'cell': {'userEnteredFormat': {'textFormat': {'bold': True}}},
'fields': 'userEnteredFormat.textFormat.bold',
}}
]}
SHEETS.spreadsheets().batchUpdate(
spreadsheetId=SHEET_ID, body=DATA).execute()
I also made a developer video on this subject if that helps (see below). BTW, you can do the same in Ruby (see its API quickstart sample) or any other language supported by the Google APIs Client Libraries.
The Sheets API provides features not available in older releases, namely giving developers programmatic access to a Sheet as if you were using the user interface (frozen rows, cell formatting[!], resizing rows/columns, adding pivot tables, creating charts, etc.). If you're new to the API, I've created a few videos with somewhat more "real-world" examples:
Migrating SQL data to a Sheet plus code deep dive post
Formatting text using the Sheets API plus code deep dive post
Generating slides from spreadsheet data plus code deep dive post
To see what else you can do with Google Sheets via its REST API or Google Apps Script, check out my other videos. As you can tell, the Sheets API is primarily for document-oriented functionality as described above, but to perform file-level access such as import/export, copy, move, rename, etc., use the Google Drive API instead.
Smartsheet utilizes the ability of the Google API to import an Excel file. The code is roughly along these lines:
DocsService client = new DocsService(<YOUR APP NAME>);
client.setOAuthCredentials(<OAUTH PARAMETERS>);
DocumentListEntry newEntry = new SpreadsheetEntry();
newEntry.setMediaSource(new MediaByteArraySource(<EXCEL FILE BYTE ARRAY OUTPUT STREAM>, DocumentListEntry.MediaType.XLS.getMimeType()));
newEntry.setTitle(new PlainTextConstruct(<FILE NAME>));
DocumentListEntry insertedEntry = client.insert(new URL("https://docs.google.com/feeds/default/private/full/"), newEntry);
// This is your URL to the new doc
String docUrl = insertedEntry.getDocumentLink().getHref();
We already had the ability to export a Smartsheet to an Excel file with formatting via Apache POI. Adding export to a Google Spreadsheet was quite simple for us to implement and it provided some additional functionality beyond what you could do via the API.
Sorry for the delayed response - just happened across this question.
The APIs only provide access to the data and do not expose any methods to add formatting.
Another option (and the one that ended up using) is to manually create a Google Sheet file, with all of the formatting pre-configured, as a template. Then, instead of creating a new spreadsheet document in the user's Google Drive, copy the template, like so:
var config = require('./config');
var google = require('googleapis');
function createSheetFromTemplate(user, templateFileId, done) {
var oauth2Client = new google.auth.OAuth2(config.google.clientId, config.google.clientSecret);
oauth2Client.setCredentials({
access_token: user.google.token,
refresh_token: user.google.refreshToken,
});
var drive = google.drive({
version: 'v2',
auth: oauth2Client
});
drive.files.copy({
fileId: templateFileId,
resource: {
title: 'New Google Sheet',
parents: [{
id: 'root'
}]
}
}, function(err, response) {
if (err) done(err)
initializeSpreadsheet(response.id, user, done);
});
}
In that code, templateFileId is the file id of your shared template. You can get this fileId from your shared template file in any number of ways, but the quick-and-dirty way is just to copy-and-paste it out of the URL when you share it.
For instance, if the sharing URL is:
https://docs.google.com/spreadsheets/d/1234567890abcdefghijklmnop/edit?usp=sharing
Then the file id is 1234567890abcdefghijklmnop
In my case there is nothing private in the template itself, so I just shared it with 'anyone with the link' configured for 'can view', as described here:
https://support.google.com/drive/answer/2494886
If you need to keep the contents of the template file private, then you'll need to find some way to ensure that the account specified by config.google.clientId has access to it.
Hope that helps!
If, like me, uploading a pre-formatted Excel sheet isn't sufficient, then Google Apps Script looks like it might be the way to go. The Range class specifically lets you manipulate at least some of the formatting you were asking about.
https://developers.google.com/apps-script/reference/spreadsheet/range
setFontColor() and setFontWeight() are there, but I don't know of anything for cell width yet.
Importantly, I have also not yet figured out how to bind a Google Apps Script to the sheet that I'm creating using the Google Drive API SDK (Node/Javascript in my case, Ruby in yours).
https://developers.google.com/apps-script/guides/bound
It's been a while since your question, so I'm betting you've already solved it some other way. I'm also not necessarily suggesting porting everything in your app over to Google Apps Script (although I'm seriously considering it myself...), but if you or some other reader figures out how to bind a Google App Script to a spreadsheet with the google-api-ruby-client, you might be good-to-go.

Resources