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

``

Aucune réponse

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions