|
|
|
@@ -5,10 +5,9 @@ import "encoding/json" |
|
|
|
import "strings" |
|
|
|
|
|
|
|
//abstract CRUD operation for espoCRM Entity |
|
|
|
var crmSite = "https://c.hitxy.org.au/" |
|
|
|
|
|
|
|
func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err error) { |
|
|
|
url := crmSite + "api/v1/" + entityType |
|
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType |
|
|
|
jsonStr, err := postRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
|
if err != nil { |
|
|
|
entity, _ = crmRescueDuplicateCreate(err, entityType) |
|
|
|
@@ -18,7 +17,7 @@ func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err e |
|
|
|
} |
|
|
|
|
|
|
|
func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { |
|
|
|
url := crmSite + "api/v1/" + entityType + "/" + id |
|
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
jsonStr, err := patchRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
@@ -28,7 +27,7 @@ func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interfa |
|
|
|
} |
|
|
|
|
|
|
|
func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { |
|
|
|
url := crmSite + "api/v1/" + entityType + "/" + id |
|
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
jsonStr, err := putRAW(jsonB, url, crmBuildCommonAPIHeader()) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
@@ -38,7 +37,7 @@ func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interf |
|
|
|
} |
|
|
|
|
|
|
|
func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { |
|
|
|
url := crmSite + "api/v1/" + entityType + "/" + id |
|
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
resp, err := deleteRAW(url, crmBuildCommonAPIHeader()) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
@@ -50,7 +49,7 @@ func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { |
|
|
|
|
|
|
|
//give an id, return json |
|
|
|
func crmGetEntity(entityType string, id string) (entity interface{}, err error) { |
|
|
|
url := crmSite + "api/v1/" + entityType + "/" + id |
|
|
|
url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id |
|
|
|
jsonStr, err := getRAW(url, crmBuildCommonAPIHeader()) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |