klaviyo / klaviyo-swift-sdk

SDK that allows users to incorporate Klaviyo's event and person tracking functionality within iOS applications. Written in Swift.
MIT License
10 stars 10 forks source link

Client Push token API is failing when background field is UNAVAILABLE #100

Closed sairamkotha closed 10 months ago

sairamkotha commented 10 months ago

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

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

ndurell commented 10 months ago

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?

sairamkotha commented 10 months ago

@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.

ndurell commented 10 months ago

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.