Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using PATCH to like and unlike an item does not work using Swift #1931

Closed
helloniklas opened this issue Feb 20, 2017 · 7 comments
Closed

Using PATCH to like and unlike an item does not work using Swift #1931

helloniklas opened this issue Feb 20, 2017 · 7 comments

Comments

@helloniklas
Copy link

So using the current API and v39.0 I'm trying to like and unlike an item with

        var query: [AnyHashable: Any]!
        // If already liked, unlike
        if post.isLikedByCurrentUser {
            query = ["isLikedBy​CurrentUser": "false"]
        }
        else {
            query = ["isLikedBy​CurrentUser": "true"]
        }
        let sendRequest = SendRequest()
        let request = sendRequest.sendRequest("/services/data/v39.0/connect/communities/\(Constants.communityId)/chatter/feed-elements/\(post.id!)/capabilities/chatter-likes/items", query: query)!
        request.method = .PATCH
SFRestAPI.sharedInstance().send(request, fail: { (error) in

But it does not work, nothing is being liked or unliked.

I'm able to use POST to like an item correctly. But according to the latest API I should PATCH with isLikedBy​CurrentUser. If I use post I'm unable to unlike an item with DELETE anyway, so presumable PATCH is the way to go. Not sure if this is related to Swift bridging problems with SendRequest and method?

@helloniklas
Copy link
Author

Still can't get this to work? Has anyone else used chatter api to like/unlike items? Suspect this is some issue with the SDK using PATCH

@bhariharan
Copy link
Contributor

@helloniklas Could you try this with the latest from our dev branch here? We have replaced the network layer with a simple NSURLSession interface. If it still doesn't work, could you set a breakpoint in the callback in SFNetwork.m and print the response from the server?

@helloniklas
Copy link
Author

@bhariharan ok, trying that branch. It still doesn't set the like. It's coming back with a response ok all the time, it's just that it never actually liked the post. The total likes is still 0

Here's the outputs.

["filterGroup": "Medium", "isLikedBy​CurrentUser": "true"]
"<SFRestRequest 0x1702c9840 \nendpoint: /services/data \nmethod: PATCH \npath: /services/data/v39.0/connect/communities/0DB0YXXXXX4Cj1WAE/chatter/feed-elements/0D50Y00000HIh7ASAT/capabilities/chatter-likes/items \nqueryParams: {\n  \"filterGroup\" : \"Medium\",\n  \"isLikedBy​CurrentUser\" : \"true\"\n} \n>"

2017-04-03 17:38:51.749663+0100 MembershipApp[1641:473849] A background URLSession with identifier com.salesforce.network already exists!

Printing description of dataResponseBlock:
(SFDataResponseBlock) dataResponseBlock = 0x0000000100a6d734
Printing description of response:
<NSHTTPURLResponse: 0x17023e8a0> { URL: https://lightfulmemberships-developer-edition.eu11.force.com/services/data/v39.0/connect/communities/0DB0Y0000004Cj1WAE/chatter/feed-elements/0D50Y00000HIh7ASAT/capabilities/chatter-likes/items?filterGroup=Medium&isLikedBy%E2%80%8BCurrentUser=true } { status code: 200, headers {
    "Cache-Control" = "s-maxage=0";
    "Content-Security-Policy" = "reflected-xss block;report-uri /_/ContentDomainCSPNoAuth?type=xss, referrer origin-when-cross-origin";
    "Content-Type" = "application/json;charset=UTF-8";
    Date = "Mon, 03 Apr 2017 16:38:55 GMT";
    Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
    "Set-Cookie" = "BrowserId=aa1DRj0cRNSScVzYFGO6Dw;Path=/;Domain=.force.com;Expires=Fri, 02-Jun-2017 16:38:55 GMT";
    "Transfer-Encoding" = Identity;
    "X-XSS-Protection" = "1; mode=block";
} }

["filterGroup": "Medium", "isLikedBy​CurrentUser": "true"]
"<SFRestRequest 0x1702c9840 \nendpoint: /services/data \nmethod: PATCH \npath: /services/data/v39.0/connect/communities/0DB0YXXXXXX04Cj1WAE/chatter/feed-elements/0D50Y00000HIh7ASAT/capabilities/chatter-likes/items \nqueryParams: {\n  \"filterGroup\" : \"Medium\",\n  \"isLikedBy​CurrentUser\" : \"true\"\n} \n>"
2017-04-03 17:38:51.749663+0100 MembershipApp[1641:473849] A background URLSession with identifier com.salesforce.network already exists!
Printing description of dataResponseBlock:
(SFDataResponseBlock) dataResponseBlock = 0x0000000100a6d734
Printing description of response:
<NSHTTPURLResponse: 0x17023e8a0> { URL: https://xxxxxxxx-developer-edition.eu11.force.com/services/data/v39.0/connect/communities/0DB0Y0000004Cj1WAE/chatter/feed-elements/0D50Y00000HIh7ASAT/capabilities/chatter-likes/items?filterGroup=Medium&isLikedBy%E2%80%8BCurrentUser=true } { status code: 200, headers {
    "Cache-Control" = "s-maxage=0";
    "Content-Security-Policy" = "reflected-xss block;report-uri /_/ContentDomainCSPNoAuth?type=xss, referrer origin-when-cross-origin";
    "Content-Type" = "application/json;charset=UTF-8";
    Date = "Mon, 03 Apr 2017 16:38:55 GMT";
    Expires = "Thu, 01 Jan 1970 00:00:00 GMT";
    "Set-Cookie" = "BrowserId=aa1DRj0cRNSScVzYFGO6Dw;Path=/;Domain=.force.com;Expires=Fri, 02-Jun-2017 16:38:55 GMT";
    "Transfer-Encoding" = Identity;
    "X-XSS-Protection" = "1; mode=block";
} }

@bhariharan
Copy link
Contributor

Could you JSON parse dataResponseBlock and print that as well?

@helloniklas
Copy link
Author

@bhariharan here's the json coming back, total likes 0, so it's not giving an error. Just not liking it. If I like an item with same user on the web portal it likes it fine.

{
  "currentPageUrl" : "\/services\/data\/v39.0\/connect\/communities\/0DB0Y0000004Cj1WAE\/chatter\/feed-elements\/0D50Y00000HIgpBSAT\/capabilities\/chatter-likes\/items",
  "items" : [

  ],
  "previousPageUrl" : null,
  "total" : 0,
  "nextPageToken" : null,
  "previousPageToken" : null,
  "nextPageUrl" : null,
  "currentPageToken" : 0
}

@bhariharan
Copy link
Contributor

@helloniklas I'm not sure what's going on, but it sounds like unexpected behavior by the API endpoint itself. Mobile SDK simply provides convenience methods for making REST requests and receiving responses. It looks like that part is working fine. This forum is reserved for bugs or issues in the client code. Please try posting your question here.

@helloniklas
Copy link
Author

@bhariharan ok, as everything else is working fine for the chatter api, and this is the only one I use using PATCH, I thought it might be some issue with the SDK swift and PATCH.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants