Receiving a request.
Generating a cryptographic signature using your private key.
Sending back a response with the signature.
All of the work is done in
routes/index. You set up environment variables for your key ID and your private key in the
Configure the Sample Code Project
Install Node.js version 10.15.3.
Open Terminal.app and navigate to the sample code directory.
npm installfrom the command line, and make sure it completes successfully.
start-serverfile contains a key ID and private key PEM string. The values provided in the sample are for example purposes only and will not generate signatures that are valid for your apps. You can optionally open
start-serverwith a text editor and replace the example key ID and private key PEM string with your own key ID and private key PEM string that you received from App Store Connect.
Run a Test on Your Local Server
To test the code on your local machine, from the command line:
Navigate to the sample code source folder and run
./start-serverfrom the command line. The server is now running locally and is ready to accept connections on port 3000.
Open another terminal window and use the
curlcommand to send a request. This example command uses the same data listed in the JSON example below:
You will get a response that includes the signature.
Send a Request
To run this sample code, send a request to this URL:
GET http://<yourdomain>/offer, where
<yourdomain> is the domain name or IP address of the server this sample code is running on.
The request must have a
Content-type header of
application/json, and JSON body data with the following format: