Opa, boa tarde. Estou com dificuldades ao criar gift cards através da API da vtex. Já utilizei pra outras funções como buscas de pedidos ou criação de cupom, mas o gift card especificamente por algum motivo não tá rolando.
Segue abaixo exemplo de implementação por PHP:
$curlHandler = curl_init();
curl_setopt_array($curlHandler, [
CURLOPT_URL => 'https://lojaexemplo.vtexcommercestable.com.br/api/giftcards',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER, array('X-VTEX-API-AppKey: ' . APP_KEY,'X-VTEX-API-AppToken: ' . APP_SECRET,'Content-Type: application/json','Accept: application/json'),
CURLOPT_POSTFIELDS => '{"relationName":"loyalty-program","expiringDate":"2023-08-18T21:23:08","caption":"teste","profileId":"idodmeuperfil","currencyCode":"BRL","restrictedToOwner":true,"multipleCredits":true,"multipleRedemptions":false}',
]);
$response = curl_exec($curlHandler);
curl_close($curlHandler);
print_r($response);
Sem falta, ele retorna um erro pouco aproveitável:
[ClassName] => System.AggregateException
[Message] => One or more errors occurred.
[Data] =>
[InnerException] => stdClass Object
(
[ClassName] => System.ArgumentNullException
[Message] => Value cannot be null.
[Data] =>
[InnerException] =>
[HelpURL] =>
[StackTraceString] => at System.Uri.EscapeDataString(String stringToEscape)
at Vtex.ProfileSystem.Client.ProfileSystemGatewayConnector.<GetProfileInfoWithNoCacheAsync>d__33.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Vtex.ProfileSystem.Client.ProfileSystemGatewayConnector.<>c__DisplayClass2a.<<GetProfileInfoAsync>b__29>d__2c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Vtex.Practices.Caching.Core.CacheManager.<>c__DisplayClass96_0`1.<<GetInternalAlmostThreadSafeAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Vtex.ProfileSystem.Client.ProfileSystemGatewayConnector.<GetProfileInfoAsync>d__2f.MoveNext()
Jogar os mesmos parametros nesta página, no entanto, funciona: GiftCard API . A primeira vista considero que pode ter algo errado no meu código, mas implementação similar no campo de cupons não gerou erro, então fica complicado.
Além disso, outra dúvida que tenho é como atrelar uma coleção específica a esse gift code. Essa opção existe pelo admin e é extremamente importante para o que preciso desenvolver, mas não encontro menções a esse campo na documentação da api gift card. preciso gerar um gift card (Ou cupom) de uso único, atrelado a um cpf, que só funciona para produtos determinados na nossa loja. Essa opção pelo admin atende perfeitamente, mas queria saber como fazer pela api
Obrigado pela atenção