https://github.com/nicheinc/sfdcclient
Salesforce HTTP client using OAuth 2.0 JWT bearer token flow
https://github.com/nicheinc/sfdcclient
backend hacktoberfest hacktoberfest2020 library salesforce salesforce-api
Last synced: 3 months ago
JSON representation
Salesforce HTTP client using OAuth 2.0 JWT bearer token flow
- Host: GitHub
- URL: https://github.com/nicheinc/sfdcclient
- Owner: nicheinc
- License: gpl-3.0
- Created: 2020-02-20T14:15:44.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-10-23T19:49:42.000Z (8 months ago)
- Last Synced: 2025-12-26T17:50:51.675Z (6 months ago)
- Topics: backend, hacktoberfest, hacktoberfest2020, library, salesforce, salesforce-api
- Language: Go
- Homepage:
- Size: 192 KB
- Stars: 1
- Watchers: 17
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sfdcclient


[](https://goreportcard.com/report/github.com/nicheinc/sfdcclient)

sfdcclient is a golang package implementing a pseudo-wrapper of an HTTP client,
for making requests to salesforce's REST API through a connected app,
making use of the [Salesforce OAuth 2.0 JWT Bearer Flow for Server-to-Server](https://help.salesforce.com/articleView?id=remoteaccess_oauth_jwt_flow.htm&type=5)
authorization flow.
## Installation
`go get https://github.com/nicheinc/sfdcclient`
## Example usage
```go
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"time"
"github.com/nicheinc/sfdcclient"
)
func main() {
// Read your private key into memory
privateKeyBytes, err := os.ReadFile(os.ExpandEnv("/path/to/your/private/key/file.key"))
if err != nil {
log.Fatalf("Error creating logger: %s", err)
}
client, err := sfdcclient.NewClientWithJWTBearer(
true, // whether the instance the client connects to, is a sandbox or not
"https://xx123.salesforce.com",
"your_connected_app_consumer_key",
"username_using_the_connected_app@email_provider.com",
privateKeyBytes,
3*time.Second, // request timeout for the OAuth new token HTTP request (3 minute max)
http.Client{ // underlying HTTP client making all HTTP calls
Timeout: 5 * time.Second,
},
)
if err != nil {
log.Fatalf("Error initializing connected app salesforce client: %s", err)
}
url := "/services/data/v47.0/sobjects/MySObjectName/describe" // note that this is a relative URL to the salesforce instance server URL
statusCode, resBody, err := client.SendRequest(context.Background(), http.MethodGet, url, nil, nil)
if err != nil {
log.Fatalf("Error sending salesforce request: %s", err)
}
fmt.Printf("\nResponse status code: %d", statusCode) // -1 if an error is returned by the SendRequest call
fmt.Printf("\nResponse body: %s", string(resBody))
}
```