I had to make a new account here because your system wasn’t sending out emails when it was supposed to.
Here’s my real issue. I reached the point where the test customer has already accepted a hold on his credit card for 7 days and your system won’t allow me to connect a new order to the payment since the payment state is approved.
What I’m trying to do is after receiving payment, I want to be able to insert somewhere all the customer names and emails that the buyer made purchases for.
So I tried creating custom attributes as follows…
First the definition…
curl https://connect.squareupsandbox.com/v2/customers/custom-attribute-definitions \
-X POST \
-H 'Square-Version: 2024-07-17' \
-H 'Authorization: Bearer EAAAlx9JezVirPKdRae5GUAFquTz05526ec7gJq3ZLyXeRFF7kscnJYB4_AiEVz3' \
-H 'Content-Type: application/json' \
-d '{
"custom_attribute_definition": {
"description": "some kind of string for a customer",
"key": "mystringkey",
"name": "its a string",
"schema": {
"$ref": "https://developer-production-s.squarecdn.com/schemas/v1/common.json#squareup.common.String"
},
"visibility": "VISIBILITY_READ_ONLY"
},
"idempotency_key": "3ece97cc-94ba-4aeb-8002-0c9a584727e1"
}'
That succeeds. So at this point I’m, guessing I use “mystringkey” to set values.
Now assuming one customer made a purchase for 2 customers in one order, I want to make a one-time massive update to avoid a too many requests error (HTTP response code 429) should hundreds of customers make purchases.
Say this customer ordered for Jackie Chan and John Smith. What I do is send the first name, last name and email as one string comma-separated.
So I tried the following request:
curl https://connect.squareupsandbox.com/v2/customers/custom-attributes/bulk-upsert \
-X POST \
-H 'Square-Version: 2024-07-17' \
-H 'Authorization: Bearer EAAAlx9JezVirPKdRae5GUAFquTz05526ec7gJq3ZLyXeRFF7kscnJYB4_AiEVz3' \
-H 'Content-Type: application/json' \
-d '{
"values": {
"mystringkey": {
"custom_attribute": {
"key": "recipient1",
"value": "john,smith,[email protected]"
},
"customer_id": "SSRGKPX6CHN9BY7W41Y7MX35FM",
"idempotency_key": "feae3079-003d-4a95-b7e5-f79592650894"
},
"mystringkey": {
"custom_attribute": {
"key": "recipient2",
"value": "jackie,chan,[email protected]"
},
"customer_id": "SSRGKPX6CHN9BY7W41Y7MX35FM",
"idempotency_key": "feae3079-003d-4a95-b7e5-f79592650895"
}
}
}'
And I get this error:
{"values":{"mystringkey":{"errors":[{"code":"BAD_REQUEST","detail":"No matching definition found for value","field":"key","category":"INVALID_REQUEST_ERROR"}]}}}
Then I try:
curl https://connect.squareupsandbox.com/v2/customers/custom-attributes/bulk-upsert \
-X POST \
-H 'Square-Version: 2024-07-17' \
-H 'Authorization: Bearer EAAAlx9JezVirPKdRae5GUAFquTz05526ec7gJq3ZLyXeRFF7kscnJYB4_AiEVz3' \
-H 'Content-Type: application/json' \
-d '{
"values": {
"recipient1": {
"custom_attribute": {
"key": "mystringkey",
"value": "john,smith,[email protected]"
},
"customer_id": "SSRGKPX6CHN9BY7W41Y7MX35FM",
"idempotency_key": "feae3079-003d-4a95-b7e5-f79592650894"
},
"recipient2": {
"custom_attribute": {
"key": "mystringkey",
"value": "jackie,chan,[email protected]"
},
"customer_id": "SSRGKPX6CHN9BY7W41Y7MX35FM",
"idempotency_key": "feae3079-003d-4a95-b7e5-f79592650895"
}
}
}'
and I get:
{"values":{"recipient1":{"errors":[{"code":"CONFLICT","detail":"Attempted to create a record with key\u003dmystringkey, parent_resource_id\u003dSSRGKPX6CHN9BY7W41Y7MX35FM when one already exists in the database. This indicates a race condition where the same value was created multiple times in a short time period.","field":"key","category":"INVALID_REQUEST_ERROR"}]},"recipient2":{"customer_id":"SSRGKPX6CHN9BY7W41Y7MX35FM","custom_attribute":{"key":"mystringkey","version":1,"updated_at":"2024-07-22T00:22:52.035Z","value":"jackie,chan,[email protected]","created_at":"2024-07-22T00:22:52.035Z","visibility":"VISIBILITY_READ_ONLY"}}}}
But I read in the error (if I can translate it):
“Attempted to create a record with key “mystringkey”, parent_resource_id SSRGKPX6CHN9BY7W41Y7MX35FM when one already exists in the database. This indicates a race condition where the same value was created multiple times in a short time period.”
However I’m trying to set two different values and it seems its accepting one but not the other, and I don’t want to make an HTTP request for each value I want to send.
I grabbed the customer ID from the Square API explorer because I gave it my valid sandbox key for testing.
How do I fix this so the bulk upsert works and I can have multiple values assigned for a customer?
And I wouldn’t have this issue if the note field in the customers API would accept an array of strings instead of one string with a character limit.