github.com/schmorrison/Zoho@v1.1.4/crm/blueprints.go (about) 1 package crm 2 3 import ( 4 "fmt" 5 6 zoho "github.com/schmorrison/Zoho" 7 ) 8 9 // GetBlueprint retrieves a blueprint record specified by the ID parameter from the module specified 10 // https://www.zoho.com/crm/help/api/v2/#blueprint-api 11 func (c *API) GetBlueprint(module Module, id string) (data BlueprintResponse, err error) { 12 endpoint := zoho.Endpoint{ 13 Name: "blueprints", 14 URL: fmt.Sprintf( 15 "https://www.zohoapis.%s/crm/v2/%s/%s/actions/blueprint", 16 c.ZohoTLD, 17 module, 18 id, 19 ), 20 Method: zoho.HTTPGet, 21 ResponseData: &BlueprintResponse{}, 22 } 23 24 err = c.Zoho.HTTPRequest(&endpoint) 25 if err != nil { 26 return BlueprintResponse{}, fmt.Errorf("Failed to retrieve blueprint: %s", err) 27 } 28 29 if v, ok := endpoint.ResponseData.(*BlueprintResponse); ok { 30 return *v, nil 31 } 32 33 return BlueprintResponse{}, fmt.Errorf("Data returned was not 'BlueprintResponse'") 34 } 35 36 // BlueprintResponse is the data returned by the GetBlueprint endpoint 37 type BlueprintResponse struct { 38 Blueprint struct { 39 ProcessInfo struct { 40 FieldID string `json:"field_id"` 41 IsContinuous bool `json:"is_continuous"` 42 APIName string `json:"api_name"` 43 Continuous bool `json:"continuous"` 44 FieldLabel string `json:"field_label"` 45 Name string `json:"name"` 46 ColumnName string `json:"column_name"` 47 FieldValue string `json:"field_value"` 48 ID string `json:"id"` 49 FieldName string `json:"field_name"` 50 } `json:"process_info"` 51 Transitions []struct { 52 NextTransitions []string `json:"next_transitions"` 53 PercentPartialSave float64 `json:"percent_partial_save"` 54 Data struct { 55 Attachments string `json:"Attachments"` 56 } `json:"data"` 57 NextFieldValue string `json:"next_field_value"` 58 Name string `json:"name"` 59 CriteriaMatched bool `json:"criteria_matched"` 60 ID string `json:"id"` 61 Fields []struct { 62 DisplayLabel string `json:"display_label"` 63 Type string `json:"_type"` 64 DataType string `json:"data_type"` 65 ColumnName string `json:"column_name"` 66 PersonalityName string `json:"personality_name"` 67 ID string `json:"id"` 68 TransitionSequence int `json:"transition_sequence"` 69 Mandatory bool `json:"mandatory"` 70 Layouts string `json:"layouts"` 71 } `json:"fields"` 72 CriteriaMessage string `json:"criteria_message"` 73 } `json:"transitions"` 74 } `json:"blueprint"` 75 } 76 77 // UpdateBlueprint updates the blueprint specified by ID in the specified module 78 // https://www.zoho.com/crm/help/api/v2/#update-blueprint 79 func (c *API) UpdateBlueprint( 80 request UpdateBlueprintData, 81 module Module, 82 id string, 83 ) (data UpdateBlueprintResponse, err error) { 84 endpoint := zoho.Endpoint{ 85 Name: "blueprints", 86 URL: fmt.Sprintf( 87 "https://www.zohoapis.%s/crm/v2/%s/%s/actions/blueprint", 88 c.ZohoTLD, 89 module, 90 id, 91 ), 92 Method: zoho.HTTPPost, 93 ResponseData: &UpdateBlueprintResponse{}, 94 RequestBody: request, 95 } 96 97 err = c.Zoho.HTTPRequest(&endpoint) 98 if err != nil { 99 return UpdateBlueprintResponse{}, fmt.Errorf("Failed to update blueprint: %s", err) 100 } 101 102 if v, ok := endpoint.ResponseData.(*UpdateBlueprintResponse); ok { 103 return *v, nil 104 } 105 106 return UpdateBlueprintResponse{}, fmt.Errorf("Data returned was not 'UpdateBlueprintResponse'") 107 } 108 109 // UpdateBlueprintData is the data that should be provided to UpdateBlueprint 110 type UpdateBlueprintData struct { 111 Blueprint []struct { 112 TransitionID string `json:"transition_id"` 113 Data map[string]interface{} `json:"data"` 114 } `json:"blueprint"` 115 } 116 117 // UpdateBlueprintResponse is the data returned by UpdateBlueprint 118 type UpdateBlueprintResponse struct { 119 Code string `json:"code"` 120 Details struct { 121 } `json:"details"` 122 Message string `json:"message"` 123 Status string `json:"status"` 124 }