satismeter / satismeter-ios

SatisMeter iOS SDK
https://satismeter.com
MIT License
7 stars 6 forks source link

400 Bad Request #20

Closed tonespy closed 1 year ago

tonespy commented 4 years ago

I get a 400 bad request anytime I fill in a survey. See below for sample response in the log.

Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: bad request (400)" UserInfo={NSLocalizedDescription=Request failed: bad request (400), NSErrorFailingURLKey=https://app.satismeter.com/api/responses, com.alamofire.serialization.response.error.data={length = 47, bytes = 0x7b226572 726f7273 223a5b7b 22746974 ... 66696564 227d5d7d }, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x282085b00> { URL: https://app.satismeter.com/api/responses } { Status Code: 400, Headers {
    "Access-Control-Allow-Headers" =     (
        "Content-Type,Auth-Token"
    );
    "Access-Control-Allow-Methods" =     (
        "PUT,POST"
    );
    "Access-Control-Allow-Origin" =     (
        "*"
    );
    "Access-Control-Expose-Headers" =     (
        "Location,Auth-Token"
    );
    Connection =     (
        "keep-alive"
    );
    "Content-Length" =     (
        47
    );
    "Content-Type" =     (
        "application/json; charset=utf-8"
    );
    Date =     (
        "Thu, 20 Feb 2020 21:53:15 GMT"
    );
    Etag =     (
        "W/\"2f-j2bd44CrSw0K37KdSWGeWzQmJcc\""
    );
    Server =     (
        Cowboy
    );
    "Strict-Transport-Security" =     (
        "max-age=15552000; includeSubDomains"
    );
    Vary =     (
        "Accept-Encoding"
    );
    Via =     (
        "1.1 vegur"
    );
    "X-Powered-By" =     (
        Express
    );
    "X-Request-Id" =     (
        "1f30905a-64e6-4262-8380-30fed0c7e6b0"
    );
} }}, <NSHTTPURLResponse: 0x282085b00> { URL: https://app.satismeter.com/api/responses } { Status Code: 400, Headers {
    "Access-Control-Allow-Headers" =     (
        "Content-Type,Auth-Token"
    );
    "Access-Control-Allow-Methods" =     (
        "PUT,POST"
    );
    "Access-Control-Allow-Origin" =     (
        "*"
    );
    "Access-Control-Expose-Headers" =     (
        "Location,Auth-Token"
    );
    Connection =     (
        "keep-alive"
    );
    "Content-Length" =     (
        47
    );
    "Content-Type" =     (
        "application/json; charset=utf-8"
    );
    Date =     (
        "Thu, 20 Feb 2020 21:53:15 GMT"
    );
    Etag =     (
        "W/\"2f-j2bd44CrSw0K37KdSWGeWzQmJcc\""
    );
    Server =     (
        Cowboy
    );
    "Strict-Transport-Security" =     (
        "max-age=15552000; includeSubDomains"
    );
    Vary =     (
        "Accept-Encoding"
    );
    Via =     (
        "1.1 vegur"
    );
    "X-Powered-By" =     (
        Express
    );
    "X-Request-Id" =     (
        "1f30905a-64e6-4262-8380-30fed0c7e6b0"
    );
} }, {
    errors =     (
                {
            title = "Campaign not specified";
        }
    );
}
jsedlacek commented 4 years ago

@tonespy Thanks for reporting the bug. Is this while using the forceSurvey flag?

tonespy commented 4 years ago

@tonespy Thanks for reporting the bug. Is this while using the forceSurvey flag?

Yeah. Correct.

jsedlacek commented 4 years ago

@tonespy we have found the cause of the issue. After we migrated project to support multiple survey campaigns, the forceSurvey flag triggers the survey, but fails to store the response.

We will fix this issue in next release of iOS SDK.

Meanwhile, the workaround for testing is to use this targeting, so that we show the survey every time:

Snímek obrazovky 2020-03-04 v 10 55 15 Snímek obrazovky 2020-03-04 v 10 55 21
tonespy commented 4 years ago

Hmm. Okay. How long do you think the new release will be available?

I got a feedback from the online chat system that, adding a campaign id fixes the issue. Yeah, it did. But, it means users are restricted to a single campaign. And, the project is live with that fix 😁

jsedlacek commented 4 years ago

@tonespy How you pass the campaign in your code? Could you please send me a snippet here?

The reported issue is present only when forceSurvey is active. I assume you're not using forceSurvey in production, so no changes should be necessary there.

tonespy commented 4 years ago

@tonespy How you pass the campaign in your code? Could you please send me a snippet here?

The reported issue is present only when forceSurvey is active. I assume you're not using forceSurvey in production, so no changes should be necessary there.

let traitsDictionary = [
            "name": name,
            "email": email,
            "campaign": campainInfo,
            "createdAt": Date().getISODateString()
        ]

        SatisMeter.sharedInstance()?.identifyUser(withUserId: "\(user_id)", writeKey: write_key, andTraitsDictionary: traitsDictionary)
        SatisMeter.sharedInstance()?.forceSurvey(true)
jsedlacek commented 1 year ago

Fixed some time ago.

oliwierSojda1234 commented 7 months ago

@tonespy May I ask you to share the model of campainInfo? @jsedlacek may I ask you for an assistance how should we specify the campaign on mobile? Getting a 400 when there's no campaign property, but the SDK doesn't set it, when I intercept the request and add a property manually everything works and I receive a 204.

tonespy commented 7 months ago

@tonespy May I ask you to share the model of campainInfo?

Lol. 4yrs later 🤣🤣