Reputation: 2168
Using PodioKit (2.0.0 on OSX) i'm struggling to create a new item with an email/phone field populated.
It wants a string for the field (or it throws an exception) but giving it an email as a string I get a 400 error.
In Podio the field can be tagged as what sort of email/phone it is, such as home, work, other etc. so I'm not sure how to specify the email/phone correctly. I can't see any special classes like PKTContactInfo or anything...
Upvotes: 0
Views: 79
Reputation: 216
PodioKit remains a work-in-progress, and unfortunately the Email field isn't yet supported explicitly in the model layer or the PKTItem
convenience methods. Until the SDK can be improved to support such features, you can work around this limitation using PKTItemsApi
's requestToCreateItemInApp
method and building up the parameters for the request yourself.
Creating an Item with Email Field - PodioKit 2.0
Here's an example of creating an Item in an App with only a Title and Email field (Swift 3.0):
let valueDictionary:[String:String] = ["type":"work", "value":"[email protected]"]
let fieldDictionary:[String:Any] = ["email":valueDictionary, "title":"r3-d6"]
let createItemRequest = PKTItemsAPI.requestToCreateItemInApp(withID: 17206313, fields: fieldDictionary, files: nil, tags: nil)
PKTClient.current().perform(createItemRequest).onComplete { response, error in
if error == nil {
print("Save successful!")
} else {
print("Error saving new item.")
}
}
As you noted in your question, the type
of an email field can be any of the following values: home
, work
, other
.
If your item is more complex and you don't want to manually insert all of the fields, you could create the item using the convenience methods and then update the item's email field similar to the example above.
Edit: Updating existing Item with email field - PodioKit 2.0
To update an existing item, you can use PKTItemsAPI
method requestToUpdateItemWithID
. Note that this request requires the Item ID, whereas to the create item requests require an App ID:
let valueDictionary:[String:String] = ["type":"work", "value":"[email protected]"]
let fieldDictionary:[String:Any] = ["email":valueDictionary, "title":"r5-d5"]
let updateItemRequest = PKTItemsAPI.requestToUpdateItem(withID: 383626238, fields: fieldDictionary, files: nil, tags: nil)
PKTClient.current().perform(updateItemRequest).onComplete { response, error in
if error == nil {
print("Completed update!")
} else {
print("Error updating item.")
}
}
Upvotes: 1