title: Taro.addCard(option)

sidebar_label: addCard

Adds cards and offers in batch. It can be used only in Mini Programs or cultural interaction Mini Games that complete verification. For more documents, see API Documentation for WeChat Cards & Offers.

cardExt Description The extended parameter of the card or offer. It must be passed as a JSON-serialized string.

Reference

Type

  1. (option: Option) => Promise<SuccessCallbackResult>

Parameters

Option

Property Type Required Description
cardList RequestInfo[] Yes The list of cards and offers to be added
complete (res: any) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: any) => void No The callback function for a failed API call
success (res: Result) => void No The callback function for a successful API call

RequestInfo

Property Type Description
cardExt string The extended parameter of the card or offer. It must be passed as a JSON-serialized string.
cardId string The ID of the card or offer

SuccessCallbackResult

Property Type Description
cardList AddCardResponseInfo[] The list of cards and offers to be added
errMsg string Call result

AddCardResponseInfo

Property Type Description
cardExt string The extended parameter of the card or offer. See description above for the composition of this parameter.
cardId string The ID of the card or offer claimed by the user
code string Encrypted code. It is a string obtained after the code of the card or offer claimed by the user is encrypted. To decrypt the code, see Code Decryption API.
isSuccess boolean Indicates whether the card or offer is successfully claimed

Sample Code

  1. Taro.addCard({
  2. cardList: [
  3. {
  4. cardId: '',
  5. cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
  6. }, {
  7. cardId: '',
  8. cardExt: '{"code": "", "openid": "", "timestamp": "", "signature":""}'
  9. }
  10. ],
  11. success: function (res) {
  12. console.log(res.cardList) // The results of card and offer addition
  13. }
  14. })

API Support

API WeChat Mini-Program H5 React Native
Taro.addCard ✔️