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);
}

``

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠