klaviyo/klaviyo-swift-sdk

Client Push token API is failing when background field is UNAVAILABLE

Closed this issue · 3 comments

Description

Push Tokens are not registering on the dashboard when the background refresh is a UNAVAILABLE field inside the push tokens API.
API:
https://a.klaviyo.com/client/push-tokens/?company_id=XXXXXX
Request body:

{
 {

> "background": "UNAVAILABLE",

      "vendor": "APNs",
      "platform": "ios",
      "enablement_status": "AUTHORIZED",
      "profile": {
        "data": {
          "attributes": {
            "anonymous_id": "41E5D174-6970-4064-8CDA-31132864ABD5",
            "properties": {}
          },
          "type": "profile"
        }
      }
    },
    "type": "push-token"
  }
}

Response:

{
  "errors": [
    {
      "id": "5dc13942-2156-4b17-a2a2-b3b3bd75d858",
      "status": 400,
      "code": "invalid",
      "title": "Invalid input.",
      "detail": "'UNAVAILABLE' is not a valid choice for 'background'.",
      "source": {
        "pointer": "/data/attributes/background"
      },
      "meta": {}
    }
  ]
}

Based on the Swift code:
This enum returns UNAVAILABLE and API is returning 400 status code.
enum PushBackground: String {
case available = "AVAILABLE"
case unavailable = "UNAVAILABLE"

    static func create(from status: UIBackgroundRefreshStatus) -> PushBackground {
        switch status {
        case .available:
            return PushBackground.available
        default:
            return PushBackground.unavailable
        }
    }
}

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

Push tokens API shouldn't fail for background request status

Actual behavior

No response

Steps to reproduce

No response

The Klaviyo Swift SDK version information

2.2.0 version

Destination operating system

iOS 16.4

Xcode version information

Xcode: 14.3.1

Swift Compiler version information

No response

Hello!
Thanks for filing this issue and for the PR. We will take a look at both now. I think we may have gotten our wires crossed on this field. Quick Question: it looks like you may have excluded the token in this request. This is meant to be a required field but we were curious if you just excluded intentionally from the example or it was missing in the payload?

@ndurell I was unable to register PN using this SDK, So I was debugging the SDK and found that my device is in low power mode & background refresh disabled. In these cases, it keeps failing to send the device token to Klaviyo.

Tested out the change and looks good. I do see the token in the request when I test. I'm going to merge your PR and I will post a release probably later today or tomorrow.