I am trying to find code examples on how G Suite is dealing with api calls in python. For example there is a method called insert: https://developers.google.com/admin-sdk/directory/v1/reference/users/insert#try-it which permits you to create new users under your enterprise.
The point is that they dont have an example on how you can do that and i find a bit difficult to figure it out through their documentation. Are there any know examples that i could consult?
This worked for me, also using the QuickStart guide.
First, build your user object with the minimum required fields.
Note, this is just a dictionary containing a basic representation of a user object.
The minimum fields to use look like this:
user = {"name": {"familyName": "Burton", "givenName": "Haniel",}, "password": "some_pass", "primaryEmail": "haniel#yourgsuitedomain.com",}
You can add or update additional fields like any other dictionary:
user["orgUnitPath"] = "/Imported"
Then, call the insert method like this in your main() program:
result = service.users().insert(body=user).execute()
Result should be a JSON representation returned by the Directory API with additional attributes that are automatically added by Google.
Some additional links in case anyone else finds it useful:
https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/python/latest/admin_directory_v1.users.html
I'm working on building a small script/app to handle user creation, updates, and password resets to automate provisioning from our student information system. Depending on how it goes I might post to GitHub and add links here to save others time.
Related
As MS Support recently told me that using a "GET" is much more efficient in RUs usage than a sql query. I'm wondering if I can (within the azure.cosmos python package or a custom HTTP request to the REST API) get a document by its unique 'id' field (for which I generated a GUIDs) without an SQL Query.
Every example shown are using the link/path of the doc which is built with the '_rid' metadata of the document and not the 'id' field set when creating the doc.
I use a bulk upsert stored procedure I wrote to create my new documents and never retrieve the metadata for each one of them (I have ~ 100 millions docs) so retrieving the _rid would be equivalent to retrieving the doc itself.
The reason that the ReadDocument method is so much more efficient than a SQL query is because it uses _rid instead of a user generated field, even the required id field. This is because the _rid isn't just a unique value, it also encodes information about where that document is physically stored.
To give an example of how this works, let's say you are explaining to someone where a party is this weekend. You could use the name that you use for the house "my friend Ryan's house" or you could use the address "123 ThatOne Street Somewhere, WA 11111". They both are unique identifiers, but for someone trying to get there one is way more efficient than the other.
Telling someone to go to your friend's house is like using your own id. It does map to a specific house, but the person will still need to find out where that physically is to get there. Using the address is like working with the _rid field. Based on that information alone they can get to the party location. Of course, in the real world the person would probably need directions, but the data storage in a database is a lot more organized than most city streets so an address is sufficient to go retrieve the document.
If you want to take advantage of this method you will need to find a way to work with the _rid field.
I have a fairly simple use case but can't figure out how to stitch it together.
Basically I want to use user-restricted access for regular users, i.e. they can upload files via an API and other users cannot touch those files via the API.
At the same time I want a special user (admin/super-user) to be able to use the API to GET e.g. all files for a specific user.
Does anybody have any pointers to examples of this or can help point me in the right direction to do this?
One idea I thought of was to pass an additional (optional) parameter to check_auth containing the _id of the user that the admin wants to look at, so if the admin passes in that parameter it will override the admins own _id. Would this work or does check_auth have a set parameter list? any security issues with this approach?
Or is there a better approach - a separate API instance perhaps that uses the same mongoDB collections (is that even possible?).
Regards,
Anton
I'm pretty new to the salesforce api. I've been employing the python module simple-salesforce in order to create leads. It works great, but it's really unclear to me how to do non-CRUDlike actions. For example, I want to programatically convert a lead into an account.
The salesforce GUI makes this easy. One would simply open the lead, then click the convert button. Does anyone out there know how to do this with simple-salesforce?
UPDATE
I found this describing the creation of an APEX resource Is there any REST service available in Saleforce to Convert Leads into Accounts?
I'm hoping there is a more elegant way to achieve this but I'll post what I do with simple salesforce's apex support if that's what ends up happening.
It looks like the best way to deal with this problem is to create an APEX class as detailed in the linked post. After creating that class, you can use simple salesforce to query it like this:
conversion_result = sf.apexecute('Lead/{id}'.format(id=lead_result['id']), method='GET')
A tip to anyone trying this: please make sure you create the class in a sandbox account. I tried for a good 20 minutes to create the apex class in our production environment without realizing that salesforce doesn't let you do that.
After making the changes in your sandbox you need to upload them to production. Of course, the environments are not connected by default! Here is an explanation on how to allow uploads to your production environment.
UPDATE:
Here is the test class I created for the linked APEX class. Salesforce requires test classes with 75% coverage. This doesn't actually test any functionality, it just passes Salesforce's arbitrary requirements.
#isTest
class RestLeadConvertTest{
#isTest static void testIt(){
Lead lead = new Lead();
lead.LastName = 'salesforce';
lead.Company = 'unittest';
insert lead;
RestRequest req = new RestRequest();
RestResponse res = new RestResponse();
req.requestURI = '/services/apexrest/Lead/' + lead.Id; //Request URL
req.httpMethod = 'GET';//HTTP Request Type
RestContext.request = req;
RestContext.response= res;
RestLeadConvert.doGet();
}
}
I am having problem with doing simple things using Steams 64 bit id.
How can i use SteamAPI to get the general information? like displaying name, username, location.
I used SteamAuth to make my social authentication on website, which only has the function, that gets the id.
Example:
steamid = GetSteamID64()
username = GetUsername()
displayname = GetDisplay()
...
Does SteamAPI on have features related to this? is there any library in python that could support such thing?
There are a whole lot of WebAPI methods to get details about a Steam user. You seem to be looking for GetPlayerSummaries.
You'll need an API key to use it.
I am new to python and pyramid and I am trying to figure out a way to print out some object values that I am using in a view callable to get a better idea of how things are working. More specifically, I am wanting to see what is coming out of a sqlalchemy query.
DBSession.query(User).filter(User.name.like('%'+request.matchdict['search']+'%'))
I need to take that query and then look up what Office a user belongs to by the office_id attribute that is part of the User object. I was thinking of looping through the users that come up from that query and doing another query to look up the office information (in the offices table). I need to build a dictionary that includes some User information and some Office information then return it to the browser as json.
Is there a way that I can experiment with different attempts at this while viewing my output without having to rely on the browser. I am more of a front end developer so when I am writing javascript I just view my outputs using console.log(output).
console.log(output) is to JavaScript
as
????? is to Python (specifically pyramid view callable)
Hope the question is not dumb. Just trying to learn. Appreciate anyones help.
This is a good reason to experiment with pshell, Pyramid's interactive python interpreter. From within pshell you can tinker with things on the command-line and see what they will do before adding them to your application.
http://docs.pylonsproject.org/projects/pyramid/en/1.4-branch/narr/commandline.html#the-interactive-shell
Of course, you can always use "print" and things will show up in the console. SQLAlchemy also has the sqlalchemy.echo ini option that you can turn on to see all queries. And finally, it sounds like you just need to do a join but maybe aren't familiar with how to write complex database queries, so I'd suggest you look into that before resorting to writing separate queries. Likely a single query can return you what you need.