Flutter/Dart AWS SigV4 and Amazon Incentive Gift Card API.

0

I'm trying to my flutter application a feature that allows users to redeem amazon gift cards.

I've just decided to use the aws_common and aws_signature_v4 pub dev packages. How would you use these packages for amaozn's gift card API? There seems to be no documentation or instance of this case online.

The following code, which gets a 400 response, is based on the documentation for aws_common and aws_signature_v4 here: https://aws.amazon.com/jp/blogs/opensource/introducing-the-aws-sigv4-signer-for-dart/

I assume I'm missing parameters (for example, I see no authentication parameter in the header which is suspicious.)

``

Future createGiftCard() async {
  const signer = AWSSigV4Signer(
    credentialsProvider: AWSCredentialsProvider.environment(),
  );

  const region = 'us-east-1';  // USA west coast
  final scope = AWSCredentialScope(
    region: region,
    service: AWSService('AGCODService'),
  );

  final request = AWSHttpRequest(
    method: AWSHttpMethod.post,
    uri: Uri.https('agcod-v2-gamma.amazon.com', '/CreateGiftCard'),
    headers: const {
      AWSHeaders.target:
          'com.amazonaws.agcod.AGCODService.CreateGiftCard',
      AWSHeaders.contentType: 'application/json',
    },
    body: json.encode({
      'creationRequestId':
          'mypartneridT2' + DateTime.now().millisecondsSinceEpoch.toString(),
      'partnerId': 'mypartnerid',
      'value': {'currencyCode': 'USD', 'amount': '15.00'},
    }).codeUnits,
  );

  // Sign and send the HTTP request
  final signedRequest = await signer.sign(
    request,
    credentialScope: scope,
  );
  final resp = await signedRequest.send();

  final respBody = await resp.response;
  safePrint(respBody.decodeBody());
  safePrint(respBody.statusCode);
}

``

已提问 3 个月前152 查看次数
没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则