@@ -124,7 +124,13 @@ func (c *RestClient) buildJsonRequest(method, url string, params interface{}) *h
124
124
125
125
func (c * RestClient ) addAuthHeader (req * http.Request , method , resType , resId string ) * http.Request {
126
126
now := time .Now ().In (locGmt )
127
- stringToSign := strings .ToLower (fmt .Sprintf ("%s\n %s\n %s\n %s\n %s\n " , method , resType , resId , now .Format (time .RFC1123 ), "" ))
127
+ /*
128
+ * M.A.I. 2022-02-16
129
+ * The original statement had a single ToLower. In the resulting string the resId gets lowered when from MS Docs it should be left unaltered
130
+ * I came across an error on a collection with a mixed case name...
131
+ * stringToSign := strings.ToLower(fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n", method, resType, resId, now.Format(time.RFC1123), ""))
132
+ */
133
+ stringToSign := fmt .Sprintf ("%s\n %s\n %s\n %s\n %s\n " , strings .ToLower (method ), strings .ToLower (resType ), resId , strings .ToLower (now .Format (time .RFC1123 )), "" )
128
134
h := hmac .New (sha256 .New , c .authKey )
129
135
h .Write ([]byte (stringToSign ))
130
136
signature := base64 .StdEncoding .EncodeToString (h .Sum (nil ))
@@ -543,7 +549,19 @@ func (c *RestClient) QueryDocuments(query QueryReq) *RespQueryDocs {
543
549
544
550
method := "POST"
545
551
url := c .endpoint + "/dbs/" + query .DbName + "/colls/" + query .CollName + "/docs"
546
- req := c .buildJsonRequest (method , url , map [string ]interface {}{"query" : query .Query , "parameters" : query .Params })
552
+
553
+ /*
554
+ * M.A.I. 2022-02-16
555
+ * In case of requests with no parameters the original form created a request with parameters set to nil. Apparently MS complaints about it.
556
+ * Original form
557
+ * req := c.buildJsonRequest(method, url, map[string]interface{}{"query": query.Query, "parameters": query.Params})
558
+ */
559
+ requestBody := make (map [string ]interface {}, 0 )
560
+ requestBody ["query" ] = query .Query
561
+ if query .Params != nil {
562
+ requestBody ["parameters" ] = query .Params
563
+ }
564
+ req := c .buildJsonRequest (method , url , requestBody )
547
565
req = c .addAuthHeader (req , method , "docs" , "dbs/" + query .DbName + "/colls/" + query .CollName )
548
566
req .Header .Set ("Content-Type" , "application/query+json" )
549
567
req .Header .Set ("X-Ms-Documentdb-Isquery" , "true" )
0 commit comments