I am working on a small side project at work and need to pull some account data from Salesforce to merge into a database. This has to be done with some regularity so instead of continuing to do this manually, I decided to create a Powershell script to get the data, convert it into a form that can be imported, and add that to the existing job that that runs to do other data merge tasks.
To save others some time, I am showing the basic Powershell / Salesforce script here:
# Salesforce web service access
$getUserID = Read-Host -Prompt 'Enter Salesforce user ID' # prompt for the Salesforce user
$getPassword = Read-Host -Prompt 'Enter Salesforce password' -AsSecureString # prompt for the Salesforce user password
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR( $getPassword ) # convert into form that supports decrypting
$plaintextpassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto( $BSTR ) # descrypt string so that we can sent as part of request
# issue the actual OAuth request
$url = "https://login.salesforce.com/services/oauth2/token" # OAuth URL
$params = @{ # OAuth parameters
grant_type="password";
client_id="{replace with your actual Salesforce client_id}";
client_secret="{replace with your actual Salesforce client_secret}";
username="$getUserID";
password="$plaintextpassword"
}
# invoke OAuth call to get security token
$token = Invoke-RestMethod -Uri $url -Method Post -Body $params -ContentType "application/x-www-form-urlencoded"
#"here it is: $token"
# show that it works by getting list of available reports...
$WorkingURI = $Token.instance_url+"/services/data/v35.0/analytics/reports"
Invoke-RestMethod -URI $WorkingURI -Method GET -Headers @{ "Authorization" = "OAuth " + $Token.access_token };
# and then run a query...
$sql="select parent.name, name from account"
$WorkingURI = $Token.instance_url+"/services/data/v20.0/query/?q=$sql"
Invoke-RestMethod -URI $WorkingURI -Method GET -Headers @{ "Authorization" = "OAuth " + $Token.access_token } | ConvertTo-Json
# eof
As an added bonus, it prompts the user for their Salesforce user ID and password. This can/will have other uses. The script its self should be self-explanatory. After successful authorization, the script runs a couple of simple calls, one to retrieve a list of reports and the other to run a simple query.
It makes use of the "password" form of OAuth. You will need to configure Salesforce to allow this to work. Part of that is setting up Salesforce for REST web service access. Doing this will cause the system to generate the client_id and client_secret values that you need to pass in order to generate the token. This link will walk you through that. This script will work with a "chatter" user account as long as you set the permissions. You will need something better than a chatter account to get Salesforce configured.
Have fun...
Showing posts with label internet. Show all posts
Showing posts with label internet. Show all posts
Tuesday, February 14, 2017
Thursday, November 29, 2007
Unbelievable!
Read this Times story, I hope you find it as hard to believe and understand as I did.
In summary, a 47 year old woman pretended to be a 16 year old boy to first befriend and then verbally attack a 13 year old girl who had once been a friend of her daughter's. The verbal attack resulted in the young girl hanging her self.
What kind of sick, twisted woman pulls such a cruel and tragic hoax on a 13 year old girl? A girl she knew was on anti-depressants and claim to not have any idea that suicide could not be a probable outcome?
To add insult to injury, the only reason this became public is because when the girl's parents found out about what transpired, they took out their anger and frustration on a foosball table they were actually storing in their house for the other family as it was a surprise Christmas present. The broken pieces were thrown in the other family's drive way and they called the police. This caused the store to come to light. What a screwed up woman! The local prosecuting attorney was still reviewing the case to see of the woman could be prosecuted. I am not a lawyer but I would think of a few possibilities like: child abuse, manslaughter or how about negligent homicide?
I would hope that we don't need a new set of laws to cover this sort of occurrence but could use existing laws. In most (not all) cases, reactionary laws are written too quickly and too poorly and result in too many unintended consequences.
In summary, a 47 year old woman pretended to be a 16 year old boy to first befriend and then verbally attack a 13 year old girl who had once been a friend of her daughter's. The verbal attack resulted in the young girl hanging her self.
What kind of sick, twisted woman pulls such a cruel and tragic hoax on a 13 year old girl? A girl she knew was on anti-depressants and claim to not have any idea that suicide could not be a probable outcome?
To add insult to injury, the only reason this became public is because when the girl's parents found out about what transpired, they took out their anger and frustration on a foosball table they were actually storing in their house for the other family as it was a surprise Christmas present. The broken pieces were thrown in the other family's drive way and they called the police. This caused the store to come to light. What a screwed up woman! The local prosecuting attorney was still reviewing the case to see of the woman could be prosecuted. I am not a lawyer but I would think of a few possibilities like: child abuse, manslaughter or how about negligent homicide?
I would hope that we don't need a new set of laws to cover this sort of occurrence but could use existing laws. In most (not all) cases, reactionary laws are written too quickly and too poorly and result in too many unintended consequences.
Friday, November 16, 2007
Interent safe for another day!
It seems that the U.N. committee on the Internet was unable to come to an agreement as to how to manage the U.S. created Internet. Well in my mind that can be seen as nothing but good news. The U.N. wants to take control of the Internet from the U.S. The same U.N. that managed the "Oil for Food" program with such great success. The same U.N. that manages to avoid stopping any conflict their peace keepers are sent to but do manage to engage in massive under age and/or coerced sex-capades. The same U.N. that continues to allow member countries with atrocious human rights records to serve on the human rights council. That U.N. wants to manage and control what is currently a mostly open and mostly uncensored Internet.
This is a funny comment: ''As we approach the end we're going to have to see what the world wants and perhaps it will be necessary to take more concrete decisions, or if not decisions, recommendations,'' That is easy. What the world wants is what it currently has. The only reason this is an issue is this is not what governments want. Governments want to be able to limit, control and filter the Internet. This is not an issue about access it is an issue about controlling access.
Update: 2:45PM
Apparently Fred Thompson agrees with me on this one.
This is a funny comment: ''As we approach the end we're going to have to see what the world wants and perhaps it will be necessary to take more concrete decisions, or if not decisions, recommendations,'' That is easy. What the world wants is what it currently has. The only reason this is an issue is this is not what governments want. Governments want to be able to limit, control and filter the Internet. This is not an issue about access it is an issue about controlling access.
Update: 2:45PM
Apparently Fred Thompson agrees with me on this one.
Thursday, April 27, 2006
If you care about the Internet...
If you care about the Internet, unrestricted speech and browsing, you will go to this site, read it and follow along, before it is too late...
Subscribe to:
Posts (Atom)