Create a Store Credit
Creates a Store Credit
POST
/
api
/
v2
/
platform
/
store_credits
Create a Store Credit
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
store_credit: {
user_id: '2',
category_id: '4',
created_by_id: '5',
amount: 25,
currency: 'USD',
type_id: '1',
store_id: '2',
amount_used: 10,
memo: 'This credit was given as a refund',
amount_authorized: 15.5,
originator_id: '3',
originator_type: 'Refund',
public_metadata: {},
private_metadata: {}
}
})
};
fetch('http://{defaultHost}/api/v2/platform/store_credits', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url http://{defaultHost}/api/v2/platform/store_credits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"store_credit": {
"user_id": "2",
"category_id": "4",
"created_by_id": "5",
"amount": 25,
"currency": "USD",
"type_id": "1",
"store_id": "2",
"amount_used": 10,
"memo": "This credit was given as a refund",
"amount_authorized": 15.5,
"originator_id": "3",
"originator_type": "Refund",
"public_metadata": {},
"private_metadata": {}
}
}
'{
"data": {
"id": "6",
"type": "store_credit",
"attributes": {
"amount": "150.0",
"amount_used": "0.0",
"memo": null,
"deleted_at": null,
"currency": "USD",
"amount_authorized": "0.0",
"originator_type": null,
"created_at": "2022-11-08T19:35:39.272Z",
"updated_at": "2022-11-08T19:35:39.272Z",
"public_metadata": {},
"private_metadata": {},
"display_amount": "$150.00",
"display_amount_used": "$0.00"
},
"relationships": {
"user": {
"data": {
"id": "113",
"type": "user"
}
},
"created_by": {
"data": {
"id": "114",
"type": "user"
}
},
"store_credit_category": {
"data": {
"id": "18",
"type": "store_credit_category"
}
},
"store_credit_type": {
"data": {
"id": "18",
"type": "store_credit_type"
}
},
"store_credit_events": {
"data": [
{
"id": "7",
"type": "store_credit_event"
}
]
}
}
}
}{
"error": "User can't be blank, Category can't be blank, Created by can't be blank, Currency can't be blank, Amount must be greater than 0, Amount used Cannot be greater than amount., and Amount authorized Exceeds total credits.",
"errors": {
"user": [
"can't be blank"
],
"category": [
"can't be blank"
],
"created_by": [
"can't be blank"
],
"currency": [
"can't be blank"
],
"amount": [
"must be greater than 0"
],
"amount_used": [
"Cannot be greater than amount."
],
"amount_authorized": [
"Exceeds total credits."
]
}
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Query Parameters
Select which associated resources you would like to fetch, see: https://jsonapi.org/format/#fetching-includes
Body
application/json
Show child attributes
Show child attributes
Response
Record created
Show child attributes
Show child attributes
Was this page helpful?
⌘I
Create a Store Credit
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
store_credit: {
user_id: '2',
category_id: '4',
created_by_id: '5',
amount: 25,
currency: 'USD',
type_id: '1',
store_id: '2',
amount_used: 10,
memo: 'This credit was given as a refund',
amount_authorized: 15.5,
originator_id: '3',
originator_type: 'Refund',
public_metadata: {},
private_metadata: {}
}
})
};
fetch('http://{defaultHost}/api/v2/platform/store_credits', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));curl --request POST \
--url http://{defaultHost}/api/v2/platform/store_credits \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"store_credit": {
"user_id": "2",
"category_id": "4",
"created_by_id": "5",
"amount": 25,
"currency": "USD",
"type_id": "1",
"store_id": "2",
"amount_used": 10,
"memo": "This credit was given as a refund",
"amount_authorized": 15.5,
"originator_id": "3",
"originator_type": "Refund",
"public_metadata": {},
"private_metadata": {}
}
}
'{
"data": {
"id": "6",
"type": "store_credit",
"attributes": {
"amount": "150.0",
"amount_used": "0.0",
"memo": null,
"deleted_at": null,
"currency": "USD",
"amount_authorized": "0.0",
"originator_type": null,
"created_at": "2022-11-08T19:35:39.272Z",
"updated_at": "2022-11-08T19:35:39.272Z",
"public_metadata": {},
"private_metadata": {},
"display_amount": "$150.00",
"display_amount_used": "$0.00"
},
"relationships": {
"user": {
"data": {
"id": "113",
"type": "user"
}
},
"created_by": {
"data": {
"id": "114",
"type": "user"
}
},
"store_credit_category": {
"data": {
"id": "18",
"type": "store_credit_category"
}
},
"store_credit_type": {
"data": {
"id": "18",
"type": "store_credit_type"
}
},
"store_credit_events": {
"data": [
{
"id": "7",
"type": "store_credit_event"
}
]
}
}
}
}{
"error": "User can't be blank, Category can't be blank, Created by can't be blank, Currency can't be blank, Amount must be greater than 0, Amount used Cannot be greater than amount., and Amount authorized Exceeds total credits.",
"errors": {
"user": [
"can't be blank"
],
"category": [
"can't be blank"
],
"created_by": [
"can't be blank"
],
"currency": [
"can't be blank"
],
"amount": [
"must be greater than 0"
],
"amount_used": [
"Cannot be greater than amount."
],
"amount_authorized": [
"Exceeds total credits."
]
}
}
