composite

package
v2.0.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2019 License: MIT Imports: 7 Imported by: 0

README

Composite API

back

The composite package is an implementation of Salesforce APIs centered on Composite operations. These operations include:

  • SObject Resources
  • Query Resource
  • Query All Resource
  • SObject Collections Resource

As a reference, see Salesforce API documentation

Examples

The following are examples to access the APIs. It is assumed that a sfdc session has been created.

Subrequest
type compositeSubRequest struct {
	url         string
	body        map[string]interface{}
	method      string
	httpHeaders http.Header
	referenceID string
}

func (c *compositeSubRequest) URL() string {
	return c.url
}
func (c *compositeSubRequest) ReferenceID() string {
	return c.referenceID
}
func (c *compositeSubRequest) Method() string {
	return c.method
}
func (c *compositeSubRequest) HTTPHeaders() http.Header {
	return c.httpHeaders
}
func (c *compositeSubRequest) Body() map[string]interface{} {
	return c.body
}
Composite
	subRequests := []composite.Subrequester{
		&compositeSubRequest{
			url:         "/services/data/v44.0/sobjects/Account",
			method:      http.MethodPost,
			referenceID: "NewAccount",
			body: map[string]interface{}{
				"Name":          "Salesforce",
				"BillingStreet": "Landmark @ 1 Market Street",
				"BillingCity":   "San Francisco",
				"BillingState":  "California",
				"Industry":      "Technology",
			},
		},
		&compositeSubRequest{
			url:         "/services/data/v44.0/sobjects/Account/@{NewAccount.id}",
			method:      http.MethodGet,
			referenceID: "NewAccountInfo",
		},
		&compositeSubRequest{
			url:         "/services/data/v44.0/sobjects/Contact",
			method:      http.MethodPost,
			referenceID: "NewContact",
			body: map[string]interface{}{
				"lastname":      "John Doe",
				"Title":         "CTO of @{NewAccountInfo.Name}",
				"MailingStreet": "@{NewAccountInfo.BillingStreet}",
				"MailingCity":   "@{NewAccountInfo.BillingAddress.city}",
				"MailingState":  "@{NewAccountInfo.BillingState}",
				"AccountId":     "@{NewAccountInfo.Id}",
				"Email":         "jdoe@salesforce.com",
				"Phone":         "1234567890",
			},
		},
		&compositeSubRequest{
			url:         "/services/data/v44.0/sobjects/Contact/@{NewContact.id}",
			method:      http.MethodGet,
			referenceID: "NewContactInfo",
		},
	}

	resource, err := composite.NewResource(session)
	if err != nil {
		fmt.Printf("Composite Error %s\n", err.Error())
		return
	}
	value, err := resource.Retrieve(false, subRequests)
	if err != nil {
		fmt.Printf("Composite Error %s\n", err.Error())
		return
	}

	fmt.Printf("%+v\n", value)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resource

type Resource struct {
	// contains filtered or unexported fields
}

Resource is the structure that can be just to call composite APIs.

func NewResource

func NewResource(session session.ServiceFormatter) (*Resource, error)

NewResource creates a new resourse with the session. If the session is nil an error will be returned.

func (*Resource) Retrieve

func (r *Resource) Retrieve(allOrNone bool, requesters []Subrequester) (Value, error)

Retrieve will retrieve the responses to a composite requests.

type Subrequester

type Subrequester interface {
	URL() string
	ReferenceID() string
	Method() string
	HTTPHeaders() http.Header
	Body() map[string]interface{}
}

Subrequester provides the composite API requests. The order of the array is the order in which the subrequests are placed in the composite body.

type Subvalue

type Subvalue struct {
	Body           interface{}       `json:"body"`
	HTTPHeaders    map[string]string `json:"httpHeaders"`
	HTTPStatusCode int               `json:"httpStatusCode"`
	ReferenceID    string            `json:"referenceId"`
}

Subvalue is the subresponses to the composite API. Using the referende id, one will be able to match the response with the request.

type Value

type Value struct {
	Response []Subvalue `json:"compositeResponse"`
}

Value is the returned structure from the composite API response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL