Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

API Help, Gift Cards -  Query on Customer ID

API Help, Gift Cards -  Query on Customer ID

LSchroeder
Visitor
1 0 0

 

Hi,

 

I need to make an API call to return all the gift cards associated with a customer id.

 

I can successfully make an API call based on the last characters of a gift card. The below call returns a collection with one gift card object, as expected.

 

 

const API_URL = ‘…myshopify.com/admin/api/2022-01/gift_cards/search.json?query=last_characters:kh3x' 

 

However, I need a collection with all gift card objects associated with the customer_id. The following call attempts to query by the customer_id that was returned by the above call. It does not return any gift cards:

 

const API_URL = ‘…myshopify.com/admin/api/2022-01/gift_cards/search.json?query=customer_id:5382638226' 

 

The call is successful in that it returns an object, but the object contains no gift cards: {gift_cards=[]}

 

I understand that the gift cards don’t “belong” to the customer object, but the customer_id is a property of the gift card object, just as last_characters is a property of the gift card object, do I don’t understand why the first call works and the second doesn’t. I’ve tested it with several customer id numbers, with the same result.

 

Help, please?

Reply 1 (1)

eliasdiek
Shopify Partner
7 2 5

Hey @LSchroeder,

 

The gift card search endpoint does not support search by customer_id. you should use email field instead like below:

const API_URL = ‘…myshopify.com/admin/api/2022-01/gift_cards/search.json?query=email:customer@example.com'

 

Elias Diek