{"id":17614716,"url":"https://github.com/joefitzgerald/sfdc","last_synced_at":"2025-04-30T18:06:43.634Z","repository":{"id":52419664,"uuid":"56011571","full_name":"joefitzgerald/sfdc","owner":"joefitzgerald","description":"Go client for the Salesforce / SFDC REST API","archived":false,"fork":false,"pushed_at":"2025-04-15T15:33:04.000Z","size":133,"stargazers_count":0,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-30T18:06:35.707Z","etag":null,"topics":["api","client","go","golang","library","rest","salesforce"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joefitzgerald.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-11T22:11:47.000Z","updated_at":"2025-04-15T15:32:01.000Z","dependencies_parsed_at":"2023-11-28T21:47:59.275Z","dependency_job_id":"0c9599da-332c-4d20-97ba-dc575bbb226f","html_url":"https://github.com/joefitzgerald/sfdc","commit_stats":{"total_commits":44,"total_committers":6,"mean_commits":7.333333333333333,"dds":0.6818181818181819,"last_synced_commit":"f20647b66520ce437ed23956dfb03babeca4ccd9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joefitzgerald%2Fsfdc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joefitzgerald%2Fsfdc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joefitzgerald%2Fsfdc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joefitzgerald%2Fsfdc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joefitzgerald","download_url":"https://codeload.github.com/joefitzgerald/sfdc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758163,"owners_count":21638989,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","client","go","golang","library","rest","salesforce"],"created_at":"2024-10-22T18:44:29.250Z","updated_at":"2025-04-30T18:06:43.605Z","avatar_url":"https://github.com/joefitzgerald.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `sfdc` [![Build and Test](https://github.com/joefitzgerald/sfdc/actions/workflows/go.yml/badge.svg)](https://github.com/joefitzgerald/sfdc/actions/workflows/go.yml)\n\nA `go` client library for the Salesforce REST API.\n\n## Usage\n\n### Get the Package\n\n```shell\ngo get -u github.com/joefitzgerald/sfdc\n```\n\n**Note:** this package requires `go` `1.18` or later.\n\n### Connect to the Salesforce API\n\n⚠️ You should make sure you have completed the steps outlined in the [Getting Started with the Salesforce API](#getting-started-with-the-salesforce-api) section, below.\n\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\t\"time\"\n\n\t\"github.com/joefitzgerald/sfdc\"\n\t\"github.com/joefitzgerald/sfdc/auth/devicecode\"\n)\n\nfunc main() {\n\t// First: Fetch a Token\n\t// Note: if you request the `refresh_token` scope, this token includes a \n\t// refresh token, which can be used to fetch new tokens in the future without\n\t// re-authenticating the user.\n\t// https://help.salesforce.com/s/articleView?id=sf.remoteaccess_oauth_refresh_token_flow.htm\n\tclientID := \"your-client-id\"\n\tclientSecret := \"your-client-secret\"\n\tdomain := \"your-domain\"\n\tscopes := []string{\"api\", \"openid\", \"id\", \"profile\", \"email\", \"refresh_token\"}\n\tconfig := devicecode.NewWithDomain(domain, clientID, clientSecret, scopes)\n\tctx, cancel := context.WithTimeout(context.Background(), time.Duration(5)*time.Minute)\n\tdefer cancel()\n\ttoken, err := config.Token(ctx, http.DefaultClient)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// Next: Use the token to construct a sfdc.Instance and then an sfdc.Entity\n\t// for each SObject you wish to query or interact with.\n\tinstance, err := sfdc.New(sfdc.WithToken(context.Background(), config.Config, token))\n\ttype Opportunity struct {\n\t\tID          string `json:\"Id,omitempty\"`\n\t\tName        string `json:\"Name,omitempty\"`\n\t\tDescription string `json:\"Description,omitempty\"`\n\t}\n\topportunityEntity := sfdc.NewEntity[Opportunity](instance)\n\n\t// Finally: Make requests to the Salesforce API\n\topportunities, err := opportunityEntity.Query(context.Background(), \"SELECT Id, Name, Description FROM Opportunity where CloseDate = 2019-01-01\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\tfor i := range opportunities {\n\t\tfmt.Printf(\"%s: %s\\n\", opportunities[i].ID, opportunities[i].Name)\n\t}\n}\n```\n\n## Getting Started with the Salesforce API\n\nAccessing the Salesforce REST API is straightforward, but requires some one-time preparation:\n\n1. Sign up for Salesforce `Developer Edition`\n2. Create a `Connected App`\n3. [Access the Salesforce REST API](#usage)\n\n### Step 1: Sign up for Salesforce `Developer Edition`\n\nYou will need a developer edition organization so that you can register a connected app. If your company already has organization(s) that they use for development, just validate the `API Enabled` permission, below.\n\n1. Go to https://developer.salesforce.com/signup\n2. Follow the instructions to create an organization\n3. Verify that your user profile has the `API Enabled` permission set (this is enabled by default, but an administrator can modify it)\n\n### Step 2: Create a `Connected App`\n\nYou need a `Connected App` so that you can get an OAuth 2.0 `Client ID` and `Client Secret`, and configure the `scopes` that your API client will be able to request and make use of.\n\n1. In your Developer Edition organization, select “Setup”, and then go to `Platform Tools` \u003e `Apps` \u003e `Apps Manager`.\n1. Select `New Connected App`.\n1. Fill in the required fields, and then check the `Enable OAuth Settings` option. In the resulting section:\n    * Check the `Enable for Device Flow` option\n    * Add the following scopes:\n      * Access the identity URL service (id, profile, email, address, phone): optional, if you want to be able to identify the user by name\n      * Access unique user identifiers (openid): required for an OpenID connect payload in your token\n      * Manage user data via APIs (api): required for all API access\n      * Perform requests at any time (refresh_token, offline_access): required for you to receive a refresh token\n    * Check the `Configure ID Token` option:\n      * Set the `Token Valid for` option to the desired number of minutes\n      * Set the `Include Standard Claims` option\n1. Select `Save` and then `Continue`\n1. Note the Client ID and Client Secret that you will make use of with this API client:\n    * Client ID: Copy the `Consumer Key` field and use it as your `ClientID`\n    * Client Secret: Copy the `Consumer Secret` field and make use of it as your `ClientSecret`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoefitzgerald%2Fsfdc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoefitzgerald%2Fsfdc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoefitzgerald%2Fsfdc/lists"}