Repository: mainflux/mainflux
Pull request #1631 (2022-07-25 19:47:38)

NOISSUE - Combining Query Parameters
Signed-off-by: b1ackd0t <blackd0t@protonmail.com>

### What does this do?
Combines the query parameters to PageMetadata such that we don't need to pass Offset, Limit e.t.c but we pass the PageMetadata that contains these fields

### Which issue(s) does this PR fix/relate to?
N/A

### List any changes that modify/break current functionality
Combines the different query parameters to one struct, `PageMetadata`

### Have you included tests for your changes?
Yes

### Did you document any new/modified functionality?
No

### Notes
N/A

dborovcanin: Please resolve conflicts so we can review.

Patch:
diff --git a/cli/bootstrap.go b/cli/bootstrap.go
index 3ba75682..d849e97e 100644
--- a/cli/bootstrap.go
+++ b/cli/bootstrap.go
@@ -27,7 +27,7 @@ var cmdBootstrap = []cobra.Command{
 				return
 			}
 
-			id, err := sdk.AddBootstrap(args[1], cfg)
+			id, err := sdk.AddBootstrap(cfg, args[1])
 			if err != nil {
 				logError(err)
 				return
@@ -46,7 +46,7 @@ var cmdBootstrap = []cobra.Command{
 				return
 			}
 
-			c, err := sdk.ViewBootstrap(args[1], args[0])
+			c, err := sdk.ViewBootstrap(args[0], args[1])
 			if err != nil {
 				logError(err)
 				return
@@ -71,7 +71,7 @@ var cmdBootstrap = []cobra.Command{
 				return
 			}
 
-			if err := sdk.UpdateBootstrap(args[1], cfg); err != nil {
+			if err := sdk.UpdateBootstrap(cfg, args[1]); err != nil {
 				logError(err)
 				return
 			}
@@ -89,7 +89,7 @@ var cmdBootstrap = []cobra.Command{
 				return
 			}
 
-			if err := sdk.RemoveBootstrap(args[1], args[0]); err != nil {
+			if err := sdk.RemoveBootstrap(args[0], args[1]); err != nil {
 				logError(err)
 				return
 			}
@@ -107,7 +107,7 @@ var cmdBootstrap = []cobra.Command{
 				return
 			}
 
-			c, err := sdk.Bootstrap(args[1], args[0])
+			c, err := sdk.Bootstrap(args[0], args[1])
 			if err != nil {
 				logError(err)
 				return
diff --git a/cli/channels.go b/cli/channels.go
index bec29491..21e5e61b 100644
--- a/cli/channels.go
+++ b/cli/channels.go
@@ -61,7 +61,7 @@ var cmdChannels = []cobra.Command{
 			}
 
 			if args[0] == "all" {
-				l, err := sdk.Channels(args[1], pageMetadata)
+				l, err := sdk.Channels(pageMetadata, args[1])
 				if err != nil {
 					logError(err)
 					return
@@ -130,8 +130,12 @@ var cmdChannels = []cobra.Command{
 				logUsage(cmd.Use)
 				return
 			}
-
-			cl, err := sdk.ThingsByChannel(args[1], args[0], uint64(Offset), uint64(Limit), false)
+			pm := mfxsdk.PageMetadata{
+				Offset:       uint64(Offset),
+				Limit:        uint64(Limit),
+				Disconnected: false,
+			}
+			cl, err := sdk.ThingsByChannel(args[0], pm, args[1])
 			if err != nil {
 				logError(err)
 				return
@@ -149,8 +153,12 @@ var cmdChannels = []cobra.Command{
 				logUsage(cmd.Use)
 				return
 			}
-
-			cl, err := sdk.ThingsByChannel(args[1], args[0], uint64(Offset), uint64(Limit), false)
+			pm := mfxsdk.PageMetadata{
+				Offset:       uint64(Offset),
+				Limit:        uint64(Limit),
+				Disconnected: false,
+			}
+			cl, err := sdk.ThingsByChannel(args[0], pm, args[1])
 			if err != nil {
 				logError(err)
 				return
diff --git a/cli/groups.go b/cli/groups.go
index bc8d885b..60419dbd 100644
--- a/cli/groups.go
+++ b/cli/groups.go
@@ -59,11 +59,11 @@ var cmdGroups = []cobra.Command{
 					logUsage(cmd.Use)
 					return
 				}
-				meta := mfxsdk.PageMetadata{
+				pm := mfxsdk.PageMetadata{
 					Offset: uint64(Offset),
 					Limit:  uint64(Limit),
 				}
-				l, err := sdk.Groups(meta, args[1])
+				l, err := sdk.Groups(pm, args[1])
 				if err != nil {
 					logError(err)
 					return
@@ -76,7 +76,11 @@ var cmdGroups = []cobra.Command{
 					logUsage(cmd.Use)
 					return
 				}
-				l, err := sdk.Children(args[1], uint64(Offset), uint64(Limit), args[2])
+				pm := mfxsdk.PageMetadata{
+					Offset: uint64(Offset),
+					Limit:  uint64(Limit),
+				}
+				l, err := sdk.Children(args[1], pm, args[2])
 				if err != nil {
 					logError(err)
 					return
@@ -89,7 +93,11 @@ var cmdGroups = []cobra.Command{
 					logUsage(cmd.Use)
 					return
 				}
-				l, err := sdk.Parents(args[1], uint64(Offset), uint64(Limit), args[2])
+				pm := mfxsdk.PageMetadata{
+					Offset: uint64(Offset),
+					Limit:  uint64(Limit),
+				}
+				l, err := sdk.Parents(args[1], pm, args[2])
 				if err != nil {
 					logError(err)
 					return
@@ -146,7 +154,7 @@ var cmdGroups = []cobra.Command{
 				logError(err)
 				return
 			}
-			if err := sdk.Unassign(args[2], args[1], ids...); err != nil {
+			if err := sdk.Unassign(args[1], ids, args[2]); err != nil {
 				logError(err)
 				return
 			}
@@ -178,7 +186,11 @@ var cmdGroups = []cobra.Command{
 				logUsage(cmd.Use)
 				return
 			}
-			up, err := sdk.Members(args[0], args[1], uint64(Offset), uint64(Limit))
+			pm := mfxsdk.PageMetadata{
+				Offset: uint64(Offset),
+				Limit:  uint64(Limit),
+			}
+			up, err := sdk.Members(args[0], pm, args[1])
 			if err != nil {
 				logError(err)
 				return
@@ -195,7 +207,11 @@ var cmdGroups = []cobra.Command{
 				logUsage(cmd.Use)
 				return
 			}
-			up, err := sdk.Memberships(args[0], args[1], uint64(Offset), uint64(Limit))
+			pm := mfxsdk.PageMetadata{
+				Offset: uint64(Offset),
+				Limit:  uint64(Limit),
+			}
+			up, err := sdk.Memberships(args[0], pm, args[1])
 			if err != nil {
 				logError(err)
 				return
diff --git a/cli/keys.go b/cli/keys.go
index a40edcac..c08052a8 100644
--- a/cli/keys.go
+++ b/cli/keys.go
@@ -26,7 +26,7 @@ var cmdAPIKeys = []cobra.Command{
 				return
 			}
 
-			resp, err := sdk.Issue(args[1], d)
+			resp, err := sdk.Issue(d, args[1])
 			if err != nil {
 				logError(err)
 				return
diff --git a/cli/provision.go b/cli/provision.go
index 8f0b149f..ce8f4536 100644
--- a/cli/provision.go
+++ b/cli/provision.go
@@ -125,7 +125,7 @@ var cmdProvision = []cobra.Command{
 				Email:    un,
 				Password: "12345678",
 			}
-			if _, err := sdk.CreateUser("", user); err != nil {
+			if _, err := sdk.CreateUser(user, ""); err != nil {
 				logError(err)
 				return
 			}
diff --git a/cli/things.go b/cli/things.go
index 27a5cad6..edef9486 100644
--- a/cli/things.go
+++ b/cli/things.go
@@ -59,7 +59,7 @@ var cmdThings = []cobra.Command{
 				Metadata: metadata,
 			}
 			if args[0] == "all" {
-				l, err := sdk.Things(args[1], pageMetadata)
+				l, err := sdk.Things(pageMetadata, args[1])
 				if err != nil {
 					logError(err)
 					return
@@ -186,8 +186,12 @@ var cmdThings = []cobra.Command{
 				logUsage(cmd.Use)
 				return
 			}
-
-			cl, err := sdk.ChannelsByThing(args[1], args[0], uint64(Offset), uint64(Limit), true)
+			pm := mfxsdk.PageMetadata{
+				Offset:       uint64(Offset),
+				Limit:        uint64(Limit),
+				Disconnected: true,
+			}
+			cl, err := sdk.ChannelsByThing(args[0], pm, args[1])
 			if err != nil {
 				logError(err)
 				return
@@ -205,8 +209,12 @@ var cmdThings = []cobra.Command{
 				logUsage(cmd.Use)
 				return
 			}
-
-			cl, err := sdk.ChannelsByThing(args[1], args[0], uint64(Offset), uint64(Limit), false)
+			pm := mfxsdk.PageMetadata{
+				Offset:       uint64(Offset),
+				Limit:        uint64(Limit),
+				Disconnected: false,
+			}
+			cl, err := sdk.ChannelsByThing(args[0], pm, args[1])
 			if err != nil {
 				logError(err)
 				return
@@ -220,9 +228,9 @@ var cmdThings = []cobra.Command{
 // NewThingsCmd returns things command.
 func NewThingsCmd() *cobra.Command {
 	cmd := cobra.Command{
-		Use:   "things [create | get | update | delete | identify | connect | disconnect | connections | not-connected]",
+		Use:   "things [create | get | update | delete | connect | disconnect | connections | not-connected]",
 		Short: "Things management",
-		Long:  `Things management: create, get, update, identify or delete Thing, connect or disconnect Thing from Channel and get the list of Channels connected or disconnected from a Thing`,
+		Long:  `Things management: create, get, update or delete Thing, connect or disconnect Thing from Channel and get the list of Channels connected or disconnected from a Thing`,
 	}
 
 	for i := range cmdThings {
diff --git a/cli/users.go b/cli/users.go
index 484faff6..e7aa57a0 100644
--- a/cli/users.go
+++ b/cli/users.go
@@ -28,7 +28,7 @@ var cmdUsers = []cobra.Command{
 				Email:    args[0],
 				Password: args[1],
 			}
-			id, err := sdk.CreateUser(args[2], user)
+			id, err := sdk.CreateUser(user, args[2])
 			if err != nil {
 				logError(err)
 				return
@@ -61,7 +61,7 @@ var cmdUsers = []cobra.Command{
 				Status:   Status,
 			}
 			if args[0] == "all" {
-				l, err := sdk.Users(args[1], pageMetadata)
+				l, err := sdk.Users(pageMetadata, args[1])
 				if err != nil {
 					logError(err)
 					return
diff --git a/pkg/sdk/go/bootstrap.go b/pkg/sdk/go/bootstrap.go
index df0c2a28..61d5e305 100644
--- a/pkg/sdk/go/bootstrap.go
+++ b/pkg/sdk/go/bootstrap.go
@@ -44,7 +44,7 @@ type ConfigUpdateCertReq struct {
 	CACert     string `json:"ca_cert"`
 }
 
-func (sdk mfSDK) AddBootstrap(token string, cfg BootstrapConfig) (string, errors.SDKError) {
+func (sdk mfSDK) AddBootstrap(cfg BootstrapConfig, token string) (string, errors.SDKError) {
 	data, err := json.Marshal(cfg)
 	if err != nil {
 		return "", errors.NewSDKError(err)
@@ -61,7 +61,7 @@ func (sdk mfSDK) AddBootstrap(token string, cfg BootstrapConfig) (string, errors
 	return id, nil
 }
 
-func (sdk mfSDK) Whitelist(token string, cfg BootstrapConfig) errors.SDKError {
+func (sdk mfSDK) Whitelist(cfg BootstrapConfig, token string) errors.SDKError {
 	data, err := json.Marshal(BootstrapConfig{State: cfg.State})
 	if err != nil {
 		return errors.NewSDKError(err)
@@ -77,7 +77,7 @@ func (sdk mfSDK) Whitelist(token string, cfg BootstrapConfig) errors.SDKError {
 	return sdkerr
 }
 
-func (sdk mfSDK) ViewBootstrap(token, id string) (BootstrapConfig, errors.SDKError) {
+func (sdk mfSDK) ViewBootstrap(id, token string) (BootstrapConfig, errors.SDKError) {
 	url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, configsEndpoint, id)
 	_, body, err := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
 	if err != nil {
@@ -92,7 +92,7 @@ func (sdk mfSDK) ViewBootstrap(token, id string) (BootstrapConfig, errors.SDKErr
 	return bc, nil
 }
 
-func (sdk mfSDK) UpdateBootstrap(token string, cfg BootstrapConfig) errors.SDKError {
+func (sdk mfSDK) UpdateBootstrap(cfg BootstrapConfig, token string) errors.SDKError {
 	data, err := json.Marshal(cfg)
 	if err != nil {
 		return errors.NewSDKError(err)
@@ -102,7 +102,7 @@ func (sdk mfSDK) UpdateBootstrap(token string, cfg BootstrapConfig) errors.SDKEr
 	_, _, sdkerr := sdk.processRequest(http.MethodPut, url, token, string(CTJSON), data, http.StatusOK)
 	return sdkerr
 }
-func (sdk mfSDK) UpdateBootstrapCerts(token, id, clientCert, clientKey, ca string) errors.SDKError {
+func (sdk mfSDK) UpdateBootstrapCerts(id, clientCert, clientKey, ca, token string) errors.SDKError {
 	url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, bootstrapCertsEndpoint, id)
 	request := ConfigUpdateCertReq{
 		ClientCert: clientCert,
@@ -119,7 +119,7 @@ func (sdk mfSDK) UpdateBootstrapCerts(token, id, clientCert, clientKey, ca strin
 	return sdkerr
 }
 
-func (sdk mfSDK) RemoveBootstrap(token, id string) errors.SDKError {
+func (sdk mfSDK) RemoveBootstrap(id, token string) errors.SDKError {
 	url := fmt.Sprintf("%s/%s/%s", sdk.bootstrapURL, configsEndpoint, id)
 	_, _, err := sdk.processRequest(http.MethodDelete, url, token, string(CTJSON), nil, http.StatusNoContent)
 	return err
diff --git a/pkg/sdk/go/certs.go b/pkg/sdk/go/certs.go
index 531a45f5..e8eacd82 100644
--- a/pkg/sdk/go/certs.go
+++ b/pkg/sdk/go/certs.go
@@ -67,7 +67,7 @@ func (sdk mfSDK) RemoveCert(id, token string) errors.SDKError {
 	}
 }
 
-func (sdk mfSDK) RevokeCert(thingID, certID string, token string) errors.SDKError {
+func (sdk mfSDK) RevokeCert(thingID, certID, token string) errors.SDKError {
 	panic("not implemented")
 }
 
diff --git a/pkg/sdk/go/channels.go b/pkg/sdk/go/channels.go
index 17f13fdb..6b178a3e 100644
--- a/pkg/sdk/go/channels.go
+++ b/pkg/sdk/go/channels.go
@@ -51,7 +51,7 @@ func (sdk mfSDK) CreateChannels(chs []Channel, token string) ([]Channel, errors.
 	return ccr.Channels, nil
 }
 
-func (sdk mfSDK) Channels(token string, pm PageMetadata) (ChannelsPage, errors.SDKError) {
+func (sdk mfSDK) Channels(pm PageMetadata, token string) (ChannelsPage, errors.SDKError) {
 	var url string
 	var err error
 
@@ -72,12 +72,14 @@ func (sdk mfSDK) Channels(token string, pm PageMetadata) (ChannelsPage, errors.S
 	return cp, nil
 }
 
-func (sdk mfSDK) ChannelsByThing(token, thingID string, offset, limit uint64, disconn bool) (ChannelsPage, errors.SDKError) {
-	url := fmt.Sprintf("%s/things/%s/channels?offset=%d&limit=%d&disconnected=%t", sdk.thingsURL, thingID, offset, limit, disconn)
-
-	_, body, err := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+func (sdk mfSDK) ChannelsByThing(thingID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError) {
+	url, err := sdk.withQueryParams(fmt.Sprintf("%s/things/%s", sdk.thingsURL, thingID), channelsEndpoint, pm)
 	if err != nil {
-		return ChannelsPage{}, err
+		return ChannelsPage{}, errors.NewSDKError(err)
+	}
+	_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+	if sdkerr != nil {
+		return ChannelsPage{}, sdkerr
 	}
 
 	var cp ChannelsPage
diff --git a/pkg/sdk/go/groups.go b/pkg/sdk/go/groups.go
index b050a478..5ee22758 100644
--- a/pkg/sdk/go/groups.go
+++ b/pkg/sdk/go/groups.go
@@ -7,8 +7,6 @@ import (
 	"encoding/json"
 	"fmt"
 	"net/http"
-	"net/url"
-	"strconv"
 	"strings"
 
 	"github.com/mainflux/mainflux/pkg/errors"
@@ -42,7 +40,7 @@ func (sdk mfSDK) DeleteGroup(id, token string) errors.SDKError {
 	return err
 }
 
-func (sdk mfSDK) Assign(memberIDs []string, memberType, groupID string, token string) errors.SDKError {
+func (sdk mfSDK) Assign(memberIDs []string, memberType, groupID, token string) errors.SDKError {
 	var ids []string
 	url := fmt.Sprintf("%s/%s/%s/members", sdk.authURL, groupsEndpoint, groupID)
 	ids = append(ids, memberIDs...)
@@ -60,7 +58,7 @@ func (sdk mfSDK) Assign(memberIDs []string, memberType, groupID string, token st
 	return sdkerr
 }
 
-func (sdk mfSDK) Unassign(token, groupID string, memberIDs ...string) errors.SDKError {
+func (sdk mfSDK) Unassign(groupID string, memberIDs []string, token string) errors.SDKError {
 	var ids []string
 	url := fmt.Sprintf("%s/%s/%s/members", sdk.authURL, groupsEndpoint, groupID)
 	ids = append(ids, memberIDs...)
@@ -77,12 +75,14 @@ func (sdk mfSDK) Unassign(token, groupID string, memberIDs ...string) errors.SDK
 	return sdkerr
 }
 
-func (sdk mfSDK) Members(groupID, token string, offset, limit uint64) (MembersPage, errors.SDKError) {
-	url := fmt.Sprintf("%s/%s/%s/members?offset=%d&limit=%d&", sdk.authURL, groupsEndpoint, groupID, offset, limit)
-
-	_, body, err := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+func (sdk mfSDK) Members(groupID string, pm PageMetadata, token string) (MembersPage, errors.SDKError) {
+	url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.authURL, groupsEndpoint, groupID), "members", pm)
 	if err != nil {
-		return MembersPage{}, err
+		return MembersPage{}, errors.NewSDKError(err)
+	}
+	_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+	if sdkerr != nil {
+		return MembersPage{}, sdkerr
 	}
 
 	var tp MembersPage
@@ -93,41 +93,33 @@ func (sdk mfSDK) Members(groupID, token string, offset, limit uint64) (MembersPa
 	return tp, nil
 }
 
-func (sdk mfSDK) Groups(meta PageMetadata, token string) (GroupsPage, errors.SDKError) {
-	u, err := url.Parse(sdk.authURL)
+func (sdk mfSDK) Groups(pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
+	url, err := sdk.withQueryParams(sdk.authURL, groupsEndpoint, pm)
 	if err != nil {
 		return GroupsPage{}, errors.NewSDKError(err)
 	}
-	u.Path = groupsEndpoint
-	q := u.Query()
-	q.Add("offset", strconv.FormatUint(meta.Offset, 10))
-	if meta.Limit != 0 {
-		q.Add("limit", strconv.FormatUint(meta.Limit, 10))
-	}
-	if meta.Level != 0 {
-		q.Add("level", strconv.FormatUint(meta.Level, 10))
-	}
-	if meta.Name != "" {
-		q.Add("name", meta.Name)
-	}
-	if meta.Type != "" {
-		q.Add("type", meta.Type)
-	}
-	u.RawQuery = q.Encode()
-	return sdk.getGroups(token, u.String())
+	return sdk.getGroups(url, token)
 }
 
-func (sdk mfSDK) Parents(id string, offset, limit uint64, token string) (GroupsPage, errors.SDKError) {
-	url := fmt.Sprintf("%s/%s/%s/parents?offset=%d&limit=%d&tree=false&level=%d", sdk.authURL, groupsEndpoint, id, offset, limit, MaxLevel)
-	return sdk.getGroups(token, url)
+func (sdk mfSDK) Parents(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
+	pm.Level = MaxLevel
+	url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.authURL, groupsEndpoint, id), "parents", pm)
+	if err != nil {
+		return GroupsPage{}, errors.NewSDKError(err)
+	}
+	return sdk.getGroups(url, token)
 }
 
-func (sdk mfSDK) Children(id string, offset, limit uint64, token string) (GroupsPage, errors.SDKError) {
-	url := fmt.Sprintf("%s/%s/%s/children?offset=%d&limit=%d&tree=false&level=%d", sdk.authURL, groupsEndpoint, id, offset, limit, MaxLevel)
-	return sdk.getGroups(token, url)
+func (sdk mfSDK) Children(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
+	pm.Level = MaxLevel
+	url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.authURL, groupsEndpoint, id), "children", pm)
+	if err != nil {
+		return GroupsPage{}, errors.NewSDKError(err)
+	}
+	return sdk.getGroups(url, token)
 }
 
-func (sdk mfSDK) getGroups(token, url string) (GroupsPage, errors.SDKError) {
+func (sdk mfSDK) getGroups(url, token string) (GroupsPage, errors.SDKError) {
 	_, body, err := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
 	if err != nil {
 		return GroupsPage{}, err
@@ -167,11 +159,14 @@ func (sdk mfSDK) UpdateGroup(t Group, token string) errors.SDKError {
 	return sdkerr
 }
 
-func (sdk mfSDK) Memberships(memberID, token string, offset, limit uint64) (GroupsPage, errors.SDKError) {
-	url := fmt.Sprintf("%s/%s/%s/groups?offset=%d&limit=%d&", sdk.authURL, membersEndpoint, memberID, offset, limit)
-	_, body, err := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+func (sdk mfSDK) Memberships(memberID string, pm PageMetadata, token string) (GroupsPage, errors.SDKError) {
+	url, err := sdk.withQueryParams(fmt.Sprintf("%s/%s/%s", sdk.authURL, membersEndpoint, memberID), groupsEndpoint, pm)
 	if err != nil {
-		return GroupsPage{}, err
+		return GroupsPage{}, errors.NewSDKError(err)
+	}
+	_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+	if sdkerr != nil {
+		return GroupsPage{}, sdkerr
 	}
 
 	var tp GroupsPage
diff --git a/pkg/sdk/go/keys.go b/pkg/sdk/go/keys.go
index e7b42648..64a9d757 100644
--- a/pkg/sdk/go/keys.go
+++ b/pkg/sdk/go/keys.go
@@ -28,7 +28,7 @@ const (
 	APIKey
 )
 
-func (sdk mfSDK) Issue(token string, d time.Duration) (KeyRes, errors.SDKError) {
+func (sdk mfSDK) Issue(d time.Duration, token string) (KeyRes, errors.SDKError) {
 	datareq := keyReq{Type: APIKey, Duration: d}
 	data, err := json.Marshal(datareq)
 	if err != nil {
diff --git a/pkg/sdk/go/sdk.go b/pkg/sdk/go/sdk.go
index e8688e19..21591adb 100644
--- a/pkg/sdk/go/sdk.go
+++ b/pkg/sdk/go/sdk.go
@@ -45,15 +45,16 @@ type User struct {
 	Metadata map[string]interface{} `json:"metadata,omitempty"`
 }
 type PageMetadata struct {
-	Total    uint64                 `json:"total"`
-	Offset   uint64                 `json:"offset"`
-	Limit    uint64                 `json:"limit"`
-	Level    uint64                 `json:"level,omitempty"`
-	Email    string                 `json:"email,omitempty"`
-	Name     string                 `json:"name,omitempty"`
-	Type     string                 `json:"type,omitempty"`
-	Metadata map[string]interface{} `json:"metadata,omitempty"`
-	Status   string                 `json:"status,omitempty"`
+	Total        uint64                 `json:"total"`
+	Offset       uint64                 `json:"offset"`
+	Limit        uint64                 `json:"limit"`
+	Level        uint64                 `json:"level,omitempty"`
+	Email        string                 `json:"email,omitempty"`
+	Name         string                 `json:"name,omitempty"`
+	Type         string                 `json:"type,omitempty"`
+	Disconnected bool                   `json:"disconnected,omitempty"`
+	Metadata     map[string]interface{} `json:"metadata,omitempty"`
+	Status       string                 `json:"status,omitempty"`
 }
 
 // Group represents mainflux users group.
@@ -92,13 +93,13 @@ type Key struct {
 // SDK contains Mainflux API.
 type SDK interface {
 	// CreateUser registers mainflux user.
-	CreateUser(token string, user User) (string, errors.SDKError)
+	CreateUser(user User, token string) (string, errors.SDKError)
 
 	// User returns user object by id.
-	User(token, id string) (User, errors.SDKError)
+	User(id, token string) (User, errors.SDKError)
 
 	// Users returns list of users.
-	Users(token string, pm PageMetadata) (UsersPage, errors.SDKError)
+	Users(pm PageMetadata, token string) (UsersPage, errors.SDKError)
 
 	// CreateToken receives credentials and returns user token.
 	CreateToken(user User) (string, errors.SDKError)
@@ -122,11 +123,11 @@ type SDK interface {
 	CreateThings(things []Thing, token string) ([]Thing, errors.SDKError)
 
 	// Things returns page of things.
-	Things(token string, pm PageMetadata) (ThingsPage, errors.SDKError)
+	Things(pm PageMetadata, token string) (ThingsPage, errors.SDKError)
 
 	// ThingsByChannel returns page of things that are connected or not connected
 	// to specified channel.
-	ThingsByChannel(token, chanID string, offset, limit uint64, disconnected bool) (ThingsPage, errors.SDKError)
+	ThingsByChannel(chanID string, pm PageMetadata, token string) (ThingsPage, errors.SDKError)
 
 	// Thing returns thing object by id.
 	Thing(id, token string) (Thing, errors.SDKError)
@@ -147,28 +148,28 @@ type SDK interface {
 	DeleteGroup(id, token string) errors.SDKError
 
 	// Groups returns page of groups.
-	Groups(meta PageMetadata, token string) (GroupsPage, errors.SDKError)
+	Groups(pm PageMetadata, token string) (GroupsPage, errors.SDKError)
 
 	// Parents returns page of users groups.
-	Parents(id string, offset, limit uint64, token string) (GroupsPage, errors.SDKError)
+	Parents(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError)
 
 	// Children returns page of users groups.
-	Children(id string, offset, limit uint64, token string) (GroupsPage, errors.SDKError)
+	Children(id string, pm PageMetadata, token string) (GroupsPage, errors.SDKError)
 
 	// Group returns users group object by id.
 	Group(id, token string) (Group, errors.SDKError)
 
 	// Assign assigns member of member type (thing or user) to a group.
-	Assign(memberIDs []string, memberType, groupID string, token string) errors.SDKError
+	Assign(memberIDs []string, memberType, groupID, token string) errors.SDKError
 
 	// Unassign removes member from a group.
-	Unassign(token, groupID string, memberIDs ...string) errors.SDKError
+	Unassign(groupID string, memberIDs []string, token string) errors.SDKError
 
 	// Members lists members of a group.
-	Members(groupID, token string, offset, limit uint64) (MembersPage, errors.SDKError)
+	Members(groupID string, pm PageMetadata, token string) (MembersPage, errors.SDKError)
 
 	// Memberships lists groups for user.
-	Memberships(userID, token string, offset, limit uint64) (GroupsPage, errors.SDKError)
+	Memberships(userID string, pm PageMetadata, token string) (GroupsPage, errors.SDKError)
 
 	// UpdateGroup updates existing group.
 	UpdateGroup(group Group, token string) errors.SDKError
@@ -186,11 +187,11 @@ type SDK interface {
 	CreateChannels(channels []Channel, token string) ([]Channel, errors.SDKError)
 
 	// Channels returns page of channels.
-	Channels(token string, pm PageMetadata) (ChannelsPage, errors.SDKError)
+	Channels(pm PageMetadata, token string) (ChannelsPage, errors.SDKError)
 
 	// ChannelsByThing returns page of channels that are connected or not connected
 	// to specified thing.
-	ChannelsByThing(token, thingID string, offset, limit uint64, connected bool) (ChannelsPage, errors.SDKError)
+	ChannelsByThing(thingID string, pm PageMetadata, token string) (ChannelsPage, errors.SDKError)
 
 	// Channel returns channel data by id.
 	Channel(id, token string) (Channel, errors.SDKError)
@@ -202,7 +203,7 @@ type SDK interface {
 	DeleteChannel(id, token string) errors.SDKError
 
 	// SendMessage send message to specified channel.
-	SendMessage(chanID, msg, token string) errors.SDKError
+	SendMessage(chanID, msg, key string) errors.SDKError
 
 	// ReadMessages read messages of specified channel.
 	ReadMessages(chanID, token string) (MessagesPage, errors.SDKError)
@@ -214,25 +215,25 @@ type SDK interface {
 	Health() (mainflux.HealthInfo, errors.SDKError)
 
 	// AddBootstrap add bootstrap configuration
-	AddBootstrap(token string, cfg BootstrapConfig) (string, errors.SDKError)
+	AddBootstrap(cfg BootstrapConfig, token string) (string, errors.SDKError)
 
 	// View returns Thing Config with given ID belonging to the user identified by the given token.
-	ViewBootstrap(token, id string) (BootstrapConfig, errors.SDKError)
+	ViewBootstrap(id, token string) (BootstrapConfig, errors.SDKError)
 
 	// Update updates editable fields of the provided Config.
-	UpdateBootstrap(token string, cfg BootstrapConfig) errors.SDKError
+	UpdateBootstrap(cfg BootstrapConfig, token string) errors.SDKError
 
 	// Update boostrap config certificates
-	UpdateBootstrapCerts(token string, id string, clientCert, clientKey, ca string) errors.SDKError
+	UpdateBootstrapCerts(id string, clientCert, clientKey, ca string, token string) errors.SDKError
 
 	// Remove removes Config with specified token that belongs to the user identified by the given token.
-	RemoveBootstrap(token, id string) errors.SDKError
+	RemoveBootstrap(id, token string) errors.SDKError
 
 	// Bootstrap returns Config to the Thing with provided external ID using external key.
 	Bootstrap(externalKey, externalID string) (BootstrapConfig, errors.SDKError)
 
 	// Whitelist updates Thing state Config with given ID belonging to the user identified by the given token.
-	Whitelist(token string, cfg BootstrapConfig) errors.SDKError
+	Whitelist(cfg BootstrapConfig, token string) errors.SDKError
 
 	// IssueCert issues a certificate for a thing required for mtls.
 	IssueCert(thingID string, keyBits int, keyType, valid, token string) (Cert, errors.SDKError)
@@ -244,13 +245,13 @@ type SDK interface {
 	RevokeCert(thingID, certID, token string) errors.SDKError
 
 	// Issue issues a new key, returning its token value alongside.
-	Issue(token string, duration time.Duration) (KeyRes, errors.SDKError)
+	Issue(duration time.Duration, token string) (KeyRes, errors.SDKError)
 
 	// Revoke removes the key with the provided ID that is issued by the user identified by the provided key.
-	Revoke(token, id string) errors.SDKError
+	Revoke(id, token string) errors.SDKError
 
 	// RetrieveKey retrieves data for the key identified by the provided ID, that is issued by the user identified by the provided key.
-	RetrieveKey(token, id string) (retrieveKeyRes, errors.SDKError)
+	RetrieveKey(id, token string) (retrieveKeyRes, errors.SDKError)
 }
 
 type mfSDK struct {
@@ -352,6 +353,7 @@ func (pm PageMetadata) query() (string, error) {
 	q.Add("total", strconv.FormatUint(pm.Total, 10))
 	q.Add("offset", strconv.FormatUint(pm.Offset, 10))
 	q.Add("limit", strconv.FormatUint(pm.Limit, 10))
+	q.Add("disconnected", strconv.FormatBool(pm.Disconnected))
 	if pm.Level != 0 {
 		q.Add("level", strconv.FormatUint(pm.Level, 10))
 	}
diff --git a/pkg/sdk/go/things.go b/pkg/sdk/go/things.go
index d8fb0190..fa0657f0 100644
--- a/pkg/sdk/go/things.go
+++ b/pkg/sdk/go/things.go
@@ -63,9 +63,8 @@ func (sdk mfSDK) CreateThings(things []Thing, token string) ([]Thing, errors.SDK
 	return ctr.Things, nil
 }
 
-func (sdk mfSDK) Things(token string, pm PageMetadata) (ThingsPage, errors.SDKError) {
+func (sdk mfSDK) Things(pm PageMetadata, token string) (ThingsPage, errors.SDKError) {
 	url, err := sdk.withQueryParams(sdk.thingsURL, thingsEndpoint, pm)
-
 	if err != nil {
 		return ThingsPage{}, errors.NewSDKError(err)
 	}
@@ -83,12 +82,14 @@ func (sdk mfSDK) Things(token string, pm PageMetadata) (ThingsPage, errors.SDKEr
 	return tp, nil
 }
 
-func (sdk mfSDK) ThingsByChannel(token, chanID string, offset, limit uint64, disconn bool) (ThingsPage, errors.SDKError) {
-	url := fmt.Sprintf("%s/channels/%s/things?offset=%d&limit=%d&disconnected=%t", sdk.thingsURL, chanID, offset, limit, disconn)
-
-	_, body, err := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+func (sdk mfSDK) ThingsByChannel(chanID string, pm PageMetadata, token string) (ThingsPage, errors.SDKError) {
+	url, err := sdk.withQueryParams(fmt.Sprintf("%s/channels/%s", sdk.thingsURL, chanID), thingsEndpoint, pm)
 	if err != nil {
-		return ThingsPage{}, err
+		return ThingsPage{}, errors.NewSDKError(err)
+	}
+	_, body, sdkerr := sdk.processRequest(http.MethodGet, url, token, string(CTJSON), nil, http.StatusOK)
+	if sdkerr != nil {
+		return ThingsPage{}, sdkerr
 	}
 
 	var tp ThingsPage
diff --git a/pkg/sdk/go/users.go b/pkg/sdk/go/users.go
index 534b836b..474c7fff 100644
--- a/pkg/sdk/go/users.go
+++ b/pkg/sdk/go/users.go
@@ -19,7 +19,7 @@ const (
 	membersEndpoint  = "members"
 )
 
-func (sdk mfSDK) CreateUser(token string, u User) (string, errors.SDKError) {
+func (sdk mfSDK) CreateUser(u User, token string) (string, errors.SDKError) {
 	data, err := json.Marshal(u)
 	if err != nil {
 		return "", errors.NewSDKError(err)
@@ -51,7 +51,7 @@ func (sdk mfSDK) User(userID, token string) (User, errors.SDKError) {
 	return u, nil
 }
 
-func (sdk mfSDK) Users(token string, pm PageMetadata) (UsersPage, errors.SDKError) {
+func (sdk mfSDK) Users(pm PageMetadata, token string) (UsersPage, errors.SDKError) {
 	var url string
 	var err error
 
diff --git a/provision/service.go b/provision/service.go
index 4d3f1e96..1e1fd324 100644
--- a/provision/service.go
+++ b/provision/service.go
@@ -100,7 +100,7 @@ func (ps *provisionService) Mapping(token string) (map[string]interface{}, error
 		Metadata: make(map[string]interface{}),
 	}
 
-	if _, err := ps.sdk.Users(token, userFilter); err != nil {
+	if _, err := ps.sdk.Users(userFilter, token); err != nil {
 		return map[string]interface{}{}, errors.Wrap(ErrUnauthorized, err)
 	}
 	return ps.conf.Bootstrap.Content, nil
@@ -202,12 +202,12 @@ func (ps *provisionService) Provision(token, name, externalID, externalKey strin
 				ClientKey:   cert.ClientKey,
 				Content:     string(content),
 			}
-			bsid, err := ps.sdk.AddBootstrap(token, bsReq)
+			bsid, err := ps.sdk.AddBootstrap(bsReq, token)
 			if err != nil {
 				return Result{}, errors.Wrap(ErrFailedBootstrap, err)
 			}
 
-			bsConfig, err = ps.sdk.ViewBootstrap(token, bsid)
+			bsConfig, err = ps.sdk.ViewBootstrap(bsid, token)
 			if err != nil {
 				return Result{}, errors.Wrap(ErrFailedBootstrapValidate, err)
 			}
@@ -227,7 +227,7 @@ func (ps *provisionService) Provision(token, name, externalID, externalKey strin
 			res.CACert = cert.CACert
 
 			if needsBootstrap(thing) {
-				if err = ps.sdk.UpdateBootstrapCerts(token, bsConfig.MFThing, cert.ClientCert, cert.ClientKey, cert.CACert); err != nil {
+				if err = ps.sdk.UpdateBootstrapCerts(bsConfig.MFThing, cert.ClientCert, cert.ClientKey, cert.CACert, token); err != nil {
 					return Result{}, errors.Wrap(ErrFailedCertCreation, err)
 				}
 			}
@@ -238,7 +238,7 @@ func (ps *provisionService) Provision(token, name, externalID, externalKey strin
 				MFThing: thing.ID,
 				State:   Active,
 			}
-			if err := ps.sdk.Whitelist(token, wlReq); err != nil {
+			if err := ps.sdk.Whitelist(wlReq, token); err != nil {
 				res.Error = err.Error()
 				return res, ErrThingUpdate
 			}
@@ -366,7 +366,7 @@ func (ps *provisionService) recover(e *error, ths *[]SDK.Thing, chs *[]SDK.Chann
 		clean(ps, things, channels, token)
 		for _, th := range things {
 			if needsBootstrap(th) {
-				ps.errLog(ps.sdk.RemoveBootstrap(token, th.ID))
+				ps.errLog(ps.sdk.RemoveBootstrap(th.ID, token))
 			}
 
 		}
@@ -377,9 +377,9 @@ func (ps *provisionService) recover(e *error, ths *[]SDK.Thing, chs *[]SDK.Chann
 		clean(ps, things, channels, token)
 		for _, th := range things {
 			if needsBootstrap(th) {
-				bs, err := ps.sdk.ViewBootstrap(token, th.ID)
+				bs, err := ps.sdk.ViewBootstrap(th.ID, token)
 				ps.errLog(errors.Wrap(ErrFailedBootstrapRetrieval, err))
-				ps.errLog(ps.sdk.RemoveBootstrap(token, bs.MFThing))
+				ps.errLog(ps.sdk.RemoveBootstrap(bs.MFThing, token))
 			}
 		}
 	}
@@ -391,9 +391,9 @@ func (ps *provisionService) recover(e *error, ths *[]SDK.Thing, chs *[]SDK.Chann
 				ps.errLog(ps.sdk.RemoveCert(th.ID, token))
 			}
 			if needsBootstrap(th) {
-				bs, err := ps.sdk.ViewBootstrap(token, th.ID)
+				bs, err := ps.sdk.ViewBootstrap(th.ID, token)
 				ps.errLog(errors.Wrap(ErrFailedBootstrapRetrieval, err))
-				ps.errLog(ps.sdk.RemoveBootstrap(token, bs.MFThing))
+				ps.errLog(ps.sdk.RemoveBootstrap(bs.MFThing, token))
 			}
 		}
 		return
diff --git a/tools/provision/provision.go b/tools/provision/provision.go
index b9f86729..98353f3e 100644
--- a/tools/provision/provision.go
+++ b/tools/provision/provision.go
@@ -83,7 +83,7 @@ func Provision(conf Config) {
 	}
 
 	// Create new user
-	if _, err := s.CreateUser("", user); err != nil {
+	if _, err := s.CreateUser(user, ""); err != nil {
 		log.Fatalf("Unable to create new user: %s", err.Error())
 		return
 
diff --git a/users/mocks/users.go b/users/mocks/users.go
index 837eb2ab..3e34b27c 100644
--- a/users/mocks/users.go
+++ b/users/mocks/users.go
@@ -91,48 +91,48 @@ func (urm *userRepositoryMock) RetrieveByID(ctx context.Context, id string) (use
 	return val, nil
 }
 
-func (urm *userRepositoryMock) RetrieveAll(ctx context.Context, status string, offset, limit uint64, ids []string, email string, um users.Metadata) (users.UserPage, error) {
+func (urm *userRepositoryMock) RetrieveAll(ctx context.Context, ids []string, pm users.PageMetadata) (users.UserPage, error) {
 	urm.mu.Lock()
 	defer urm.mu.Unlock()
 
 	up := users.UserPage{}
 	i := uint64(0)
 
-	if email != "" {
-		val, ok := urm.users[email]
+	if pm.Email != "" {
+		val, ok := urm.users[pm.Email]
 		if !ok {
 			return users.UserPage{}, errors.ErrNotFound
 		}
-		up.Offset = offset
-		up.Limit = limit
+		up.Offset = pm.Offset
+		up.Limit = pm.Limit
 		up.Total = uint64(i)
 		up.Users = []users.User{val}
 		return up, nil
 	}
 
-	if status == users.EnabledStatusKey || status == users.DisabledStatusKey {
+	if pm.Status == users.EnabledStatusKey || pm.Status == users.DisabledStatusKey {
 		for _, u := range sortUsers(urm.users) {
-			if i >= offset && i < (limit+offset) {
-				if status == u.Status {
+			if i >= pm.Offset && i < (pm.Limit+pm.Offset) {
+				if pm.Status == u.Status {
 					up.Users = append(up.Users, u)
 				}
 			}
 			i++
 		}
-		up.Offset = offset
-		up.Limit = limit
+		up.Offset = pm.Offset
+		up.Limit = pm.Limit
 		up.Total = uint64(i)
 		return up, nil
 	}
 	for _, u := range sortUsers(urm.users) {
-		if i >= offset && i < (limit+offset) {
+		if i >= pm.Offset && i < (pm.Limit+pm.Offset) {
 			up.Users = append(up.Users, u)
 		}
 		i++
 	}
 
-	up.Offset = offset
-	up.Limit = limit
+	up.Offset = pm.Offset
+	up.Limit = pm.Limit
 	up.Total = uint64(i)
 
 	return up, nil
diff --git a/users/postgres/users.go b/users/postgres/users.go
index 5dd7d013..09440544 100644
--- a/users/postgres/users.go
+++ b/users/postgres/users.go
@@ -132,18 +132,18 @@ func (ur userRepository) RetrieveByID(ctx context.Context, id string) (users.Use
 	return toUser(dbu)
 }
 
-func (ur userRepository) RetrieveAll(ctx context.Context, status string, offset, limit uint64, userIDs []string, email string, um users.Metadata) (users.UserPage, error) {
-	eq, ep, err := createEmailQuery("", email)
+func (ur userRepository) RetrieveAll(ctx context.Context, userIDs []string, pm users.PageMetadata) (users.UserPage, error) {
+	eq, ep, err := createEmailQuery("", pm.Email)
 	if err != nil {
 		return users.UserPage{}, errors.Wrap(errors.ErrViewEntity, err)
 	}
 
-	mq, mp, err := createMetadataQuery("", um)
+	mq, mp, err := createMetadataQuery("", pm.Metadata)
 	if err != nil {
 		return users.UserPage{}, errors.Wrap(errors.ErrViewEntity, err)
 	}
-	aq := fmt.Sprintf("status = '%s'", status)
-	if status == users.AllStatusKey {
+	aq := fmt.Sprintf("status = '%s'", pm.Status)
+	if pm.Status == users.AllStatusKey {
 		aq = ""
 	}
 
@@ -168,8 +168,8 @@ func (ur userRepository) RetrieveAll(ctx context.Context, status string, offset,
 
 	q := fmt.Sprintf(`SELECT id, email, metadata FROM users %s ORDER BY email LIMIT :limit OFFSET :offset;`, emq)
 	params := map[string]interface{}{
-		"limit":    limit,
-		"offset":   offset,
+		"limit":    pm.Limit,
+		"offset":   pm.Offset,
 		"email":    ep,
 		"metadata": mp,
 	}
@@ -206,8 +206,8 @@ func (ur userRepository) RetrieveAll(ctx context.Context, status string, offset,
 		Users: items,
 		PageMetadata: users.PageMetadata{
 			Total:  total,
-			Offset: offset,
-			Limit:  limit,
+			Offset: pm.Offset,
+			Limit:  pm.Limit,
 		},
 	}
 
diff --git a/users/service.go b/users/service.go
index 708e195e..29a51eff 100644
--- a/users/service.go
+++ b/users/service.go
@@ -254,7 +254,7 @@ func (svc usersService) ListUsers(ctx context.Context, token string, pm PageMeta
 	if err := svc.authorize(ctx, id.id, "authorities", "member"); err != nil {
 		return UserPage{}, err
 	}
-	return svc.users.RetrieveAll(ctx, pm.Status, pm.Offset, pm.Limit, nil, pm.Email, pm.Metadata)
+	return svc.users.RetrieveAll(ctx, nil, pm)
 }
 
 func (svc usersService) UpdateUser(ctx context.Context, token string, u User) error {
@@ -356,7 +356,7 @@ func (svc usersService) ListMembers(ctx context.Context, token, groupID string,
 		}, nil
 	}
 
-	return svc.users.RetrieveAll(ctx, pm.Status, pm.Offset, pm.Limit, userIDs, pm.Email, pm.Metadata)
+	return svc.users.RetrieveAll(ctx, userIDs, pm)
 }
 
 func (svc usersService) EnableUser(ctx context.Context, token, id string) error {
diff --git a/users/tracing/users.go b/users/tracing/users.go
index a4cedcdd..a33e9977 100644
--- a/users/tracing/users.go
+++ b/users/tracing/users.go
@@ -75,12 +75,12 @@ func (urm userRepositoryMiddleware) UpdatePassword(ctx context.Context, email, p
 	return urm.repo.UpdatePassword(ctx, email, password)
 }
 
-func (urm userRepositoryMiddleware) RetrieveAll(ctx context.Context, status string, offset, limit uint64, ids []string, email string, um users.Metadata) (users.UserPage, error) {
+func (urm userRepositoryMiddleware) RetrieveAll(ctx context.Context, ids []string, pm users.PageMetadata) (users.UserPage, error) {
 	span := createSpan(ctx, urm.tracer, members)
 	defer span.Finish()
 	ctx = opentracing.ContextWithSpan(ctx, span)
 
-	return urm.repo.RetrieveAll(ctx, status, offset, limit, ids, email, um)
+	return urm.repo.RetrieveAll(ctx, ids, pm)
 }
 
 func (urm userRepositoryMiddleware) ChangeStatus(ctx context.Context, id, status string) error {
diff --git a/users/users.go b/users/users.go
index 3264b6ff..63002ce7 100644
--- a/users/users.go
+++ b/users/users.go
@@ -66,7 +66,7 @@ type UserRepository interface {
 	RetrieveByID(ctx context.Context, id string) (User, error)
 
 	// RetrieveAll retrieves all users for given array of userIDs.
-	RetrieveAll(ctx context.Context, status string, offset, limit uint64, userIDs []string, email string, m Metadata) (UserPage, error)
+	RetrieveAll(ctx context.Context, userIDs []string, pm PageMetadata) (UserPage, error)
 
 	// UpdatePassword updates password for user with given email
 	UpdatePassword(ctx context.Context, email, password string) error


Test patch:
diff --git a/pkg/sdk/go/channels_test.go b/pkg/sdk/go/channels_test.go
index 75841781..e6b0a7b5 100644
--- a/pkg/sdk/go/channels_test.go
+++ b/pkg/sdk/go/channels_test.go
@@ -307,7 +307,7 @@ func TestChannels(t *testing.T) {
 			Metadata: tc.metadata,
 		}
 
-		page, err := mainfluxSDK.Channels(tc.token, filter)
+		page, err := mainfluxSDK.Channels(filter, tc.token)
 		assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
 		assert.Equal(t, tc.response, page.Channels, fmt.Sprintf("%s: expected response channel %s, got %s", tc.desc, tc.response, page.Channels))
 	}
@@ -439,7 +439,12 @@ func TestChannelsByThing(t *testing.T) {
 	}
 
 	for _, tc := range cases {
-		page, err := mainfluxSDK.ChannelsByThing(tc.token, tc.thing, tc.offset, tc.limit, tc.disconnected)
+		pm := sdk.PageMetadata{
+			Offset:       tc.offset,
+			Limit:        tc.limit,
+			Disconnected: tc.disconnected,
+		}
+		page, err := mainfluxSDK.ChannelsByThing(tc.thing, pm, tc.token)
 		assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
 		assert.Equal(t, tc.response, page.Channels, fmt.Sprintf("%s: expected response channel %s, got %s", tc.desc, tc.response, page.Channels))
 	}
diff --git a/pkg/sdk/go/things_test.go b/pkg/sdk/go/things_test.go
index 80556173..46c0d519 100644
--- a/pkg/sdk/go/things_test.go
+++ b/pkg/sdk/go/things_test.go
@@ -360,7 +360,7 @@ func TestThings(t *testing.T) {
 			Limit:    uint64(tc.limit),
 			Metadata: tc.metadata,
 		}
-		page, err := mainfluxSDK.Things(tc.token, filter)
+		page, err := mainfluxSDK.Things(filter, tc.token)
 		assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
 		assert.Equal(t, tc.response, page.Things, fmt.Sprintf("%s: expected response channel %s, got %s", tc.desc, tc.response, page.Things))
 	}
@@ -498,7 +498,12 @@ func TestThingsByChannel(t *testing.T) {
 		},
 	}
 	for _, tc := range cases {
-		page, err := mainfluxSDK.ThingsByChannel(tc.token, tc.channel, tc.offset, tc.limit, tc.disconnected)
+		pm := sdk.PageMetadata{
+			Offset:       tc.offset,
+			Limit:        tc.limit,
+			Disconnected: tc.disconnected,
+		}
+		page, err := mainfluxSDK.ThingsByChannel(tc.channel, pm, tc.token)
 		assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
 		assert.Equal(t, tc.response, page.Things, fmt.Sprintf("%s: expected response channel %s, got %s", tc.desc, tc.response, page.Things))
 	}
diff --git a/pkg/sdk/go/users_test.go b/pkg/sdk/go/users_test.go
index 509c1533..a81fefa9 100644
--- a/pkg/sdk/go/users_test.go
+++ b/pkg/sdk/go/users_test.go
@@ -129,7 +129,7 @@ func TestCreateUser(t *testing.T) {
 	}
 
 	for _, tc := range cases {
-		_, err := mainfluxSDK.CreateUser(tc.token, tc.user)
+		_, err := mainfluxSDK.CreateUser(tc.user, tc.token)
 		assert.Equal(t, tc.err, err, fmt.Sprintf("%s: unexpected error %s", tc.desc, err))
 	}
 }
@@ -153,7 +153,7 @@ func TestUser(t *testing.T) {
 
 	tkn, _ := auth.Issue(context.Background(), &mainflux.IssueReq{Id: user.ID, Email: user.Email, Type: mfauth.APIKey})
 	token := tkn.GetValue()
-	userID, err := mainfluxSDK.CreateUser(token, user)
+	userID, err := mainfluxSDK.CreateUser(user, token)
 	require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
 	usertoken, err := mainfluxSDK.CreateToken(user)
 	require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
@@ -224,7 +224,7 @@ func TestUsers(t *testing.T) {
 		password := fmt.Sprintf("password%d", i)
 		metadata := map[string]interface{}{"name": fmt.Sprintf("user%d", i)}
 		us := sdk.User{Email: email, Password: password, Metadata: metadata}
-		userID, err := mainfluxSDK.CreateUser(token, us)
+		userID, err := mainfluxSDK.CreateUser(us, token)
 		require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
 		us.ID = userID
 		us.Password = ""
@@ -317,7 +317,7 @@ func TestUsers(t *testing.T) {
 			Limit:    uint64(tc.limit),
 			Metadata: tc.metadata,
 		}
-		page, err := mainfluxSDK.Users(tc.token, filter)
+		page, err := mainfluxSDK.Users(filter, tc.token)
 		assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected error %s, got %s", tc.desc, tc.err, err))
 		assert.Equal(t, tc.response, page.Users, fmt.Sprintf("%s: expected response user %s, got %s", tc.desc, tc.response, page.Users))
 	}
@@ -342,7 +342,7 @@ func TestCreateToken(t *testing.T) {
 
 	tkn, _ := auth.Issue(context.Background(), &mainflux.IssueReq{Id: user.ID, Email: user.Email, Type: mfauth.APIKey})
 	token := tkn.GetValue()
-	_, err := mainfluxSDK.CreateUser(token, user)
+	_, err := mainfluxSDK.CreateUser(user, token)
 	require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
 
 	cases := []struct {
@@ -396,7 +396,7 @@ func TestUpdateUser(t *testing.T) {
 
 	tkn, _ := auth.Issue(context.Background(), &mainflux.IssueReq{Id: user.ID, Email: user.Email, Type: mfauth.APIKey})
 	token := tkn.GetValue()
-	userID, err := mainfluxSDK.CreateUser(token, user)
+	userID, err := mainfluxSDK.CreateUser(user, token)
 	require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
 	usertoken, err := mainfluxSDK.CreateToken(user)
 	require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
@@ -457,7 +457,7 @@ func TestUpdatePassword(t *testing.T) {
 
 	tkn, _ := auth.Issue(context.Background(), &mainflux.IssueReq{Id: user.ID, Email: user.Email, Type: mfauth.APIKey})
 	token := tkn.GetValue()
-	_, err := mainfluxSDK.CreateUser(token, user)
+	_, err := mainfluxSDK.CreateUser(user, token)
 	require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
 	usertoken, err := mainfluxSDK.CreateToken(user)
 	require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
diff --git a/users/postgres/users_test.go b/users/postgres/users_test.go
index 5afca583..65e6e117 100644
--- a/users/postgres/users_test.go
+++ b/users/postgres/users_test.go
@@ -232,7 +232,14 @@ func TestRetrieveAll(t *testing.T) {
 		},
 	}
 	for desc, tc := range cases {
-		page, err := userRepo.RetrieveAll(context.Background(), users.EnabledStatusKey, tc.offset, tc.limit, tc.ids, tc.email, tc.metadata)
+		pm := users.PageMetadata{
+			Offset:   tc.offset,
+			Limit:    tc.limit,
+			Email:    tc.email,
+			Metadata: tc.metadata,
+			Status:   users.EnabledStatusKey,
+		}
+		page, err := userRepo.RetrieveAll(context.Background(), tc.ids, pm)
 		size := uint64(len(page.Users))
 		assert.Equal(t, tc.size, size, fmt.Sprintf("%s: expected size %d got %d\n", desc, tc.size, size))
 		assert.Nil(t, err, fmt.Sprintf("%s: expected no error got %d\n", desc, err))
diff --git a/users/service_test.go b/users/service_test.go
index 45499fbc..0e367025 100644
--- a/users/service_test.go
+++ b/users/service_test.go
@@ -271,10 +271,11 @@ func TestListUsers(t *testing.T) {
 
 	for desc, tc := range cases {
 		pm := users.PageMetadata{
-			Offset: tc.offset,
-			Limit:  tc.limit,
-			Email:  tc.email,
-			Status: "all",
+			Offset:   tc.offset,
+			Limit:    tc.limit,
+			Email:    tc.email,
+			Metadata: nil,
+			Status:   "all",
 		}
 		page, err := svc.ListUsers(context.Background(), tc.token, pm)
 		size := uint64(len(page.Users))