Create and Update Card Products

Learn what a card product is as well as how to create and update it.

Overview

A card product defines the behavior and functionality of Marqeta cards. It defines the attributes of the card and provides us with information regarding its usage. It also allows us to specify the specific channels where cards can be used, for example, at ATMs, points of sale (POS), and e-commerce websites.

In addition to the card product object, we can also define the attributes in the card object. If we end up with multiple definitions, the definition in the card object will take precedence over the definition in the card product object.

In this lesson, we’ll learn to create and update a card product.

Create a card product

We can create a card product by making a POST request to the {BASE_URL}/cardproducts endpoint. We can provide basic information about the card product in the body of the request. We can also provide configuration information if we use the config object. This information defines the features and the behavior of the card product.

Request Parameters

Parameter

Type

Category

Description

name

string

required

Name of the card product

Length: 1–40 characters

start_date

datetime

required

Date of activation of the card product

Format: yyyy-DD-mm

Note: The card won't be activated if the start date has already elapsed and the card active status is set to active = False.

token

string

optional

Unique token of the card product

Length: 1–36 characters

Note: If not specified, the system generates one automatically. This value cannot be updated once set.

active

boolean

optional

Status of the card product

Default value: True

end_date

datetime

optional

Date until which the card product will remain active

Format: yyyy-DD-mm

config

object

optional

Contains the characteristics of the card product

Note: Please refer to this course’s appendix for details of the config object.

Lines 4–5: Enter the values for the name and start_date parameters.

Line 8: We set the ecommerce attribute value to True, which enables the user to use the card for online shopping.

Line 9: We set the atm attribute value to True, which enables the user to withdraw cash from ATMs and receive funds at POS systems.

Note: You may also enter values for the other optional parameters that are given in the table above.

Click the “Run” button in the code widget below to see the output.

Press + to interact
url = '{{BASE_URL}}cardproducts'
data = json.dumps({
"name": "",
"start_date": "",
"config": {
"poi": {
"ecommerce": True,
"atm": True,
},
}
})
response = requests.post(url, headers=headers, data=data)
printResponse(response)

When the code is executed successfully, the output of the above code displays the complete card product object with all of the requested data fields. The token field is extracted and saved as CARD_PRODUCT_TOKEN. We’ll use this value to perform a number of operations throughout the course.

In case of failure, an appropriate error message is displayed.

Update a card product

We can update a card product by making a PUT request to the {BASE_URL}/cardproducts/{token} endpoint. The path parameter ({token}) refers to the token of the card product to be updated. We also need to specify the fields that we want to update in the body of the request.

Path Parameter

Parameter

Type

Category

Description

token

string

required

Token of the card product we want to update

Note: To find the fields we can update, refer to the card product creation input parameters table. Please note that we can update all fields except for token, as indicated in the table.

In the code below, let’s change the name of a given card product.

Note: You may choose to change any of the attribute(s) given in the card product creation table.

Line 1: For token, we’ve used the CARD_PRODUCT_TOKEN value that we saved when we created the card product. However, you can change it in case you want to update any other card product object.

Line 6: We enter the value (the new name of the card product) of the name parameter.

Click the “Run” button in the code widget below to see the output.

Press + to interact
token = '{{CARD_PRODUCT_TOKEN}}'
url = '{{BASE_URL}}cardproducts/' + token
data = json.dumps({
"name": ""
})
response = requests.put(url, headers=headers, data=data)
printResponse(response)

When the code is executed successfully, the output displays the complete card product object that corresponds to the given token with all of the requested data fields. This includes the field we just updated.

In case of failure, an appropriate error message is displayed.