Apple and Google provide a way to send subscription events updates the moment they occur on their servers. It's very important to send them to Adapty to avoid delays in processing subscription status, and therefore providing the best experience for your customers.
In most cases, you just have to paste Adapty URL to App Store Connect or use the RTDN topic provided by Adapty in Google Play Console, no coding is needed on your side.
However, if you process these events and want to keep doing it, make sure to forward events to Adapty from your backend. It's very simple, you just have to send raw (without any modification) payload as a request body from Apple or Google to our server using the same URL from settings.
Here are examples for different programming languages:
import requestsurl = "https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad456/" # don't forget to replace this URLpayload = '{"latest_receipt":"abc=","notification_type":"INITIAL_BUY",...}' # json encoded payload from Apple/Googleheaders = {'Content-Type': 'application/json'}response = requests.request("POST", url, headers=headers, data=payload)
const axios = require('axios');const url = 'https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad456/'; // don't forget to replace this URLconst payload = '{"latest_receipt":"abc=","notification_type":"INITIAL_BUY",...}'; // json encoded payload from Apple/Googleconst config = {method: 'post',url: url,headers: {'Content-Type': 'application/json'},data: payload,};const response = await axios(config);
<?phprequire_once 'HTTP/Request2.php';$url = 'https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad456/'; // don't forget to replace this URL$payload = '{"latest_receipt":"abc=","notification_type":"INITIAL_BUY",...}'; // json encoded payload from Apple/Google$request = new HTTP_Request2();$request->setUrl($url);$request->setMethod(HTTP_Request2::METHOD_POST);$request->setConfig(array('follow_redirects' => TRUE));$request->setHeader(array('Content-Type' => 'application/json'));$request->setBody($payload);$response = $request->send();
require "uri"require "net/http"url = URI("https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad456/") # don't forget to replace this URLpayload = '{"latest_receipt":"abc=","notification_type":"INITIAL_BUY",...}' # json encoded payload from Apple/Googlehttps = Net::HTTP.new(url.host, url.port)https.use_ssl = truerequest = Net::HTTP::Post.new(url)request["Content-Type"] = "application/json"request.body = payloadresponse = https.request(request)
String url = "https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad456/"; // don't forget to replace this URLString payload = "{\"latest_receipt\":\"abc=\",\"notification_type\":\"INITIAL_BUY\",...}" // json encoded payload from Apple/GoogleOkHttpClient client = new OkHttpClient().newBuilder().build();MediaType mediaType = MediaType.parse("application/json");RequestBody body = RequestBody.create(mediaType, payload);Request request = new Request.Builder().url(url).method("POST", body).addHeader("Content-Type", "application/json").build();Response response = client.newCall(request).execute();
package mainimport ("fmt""strings""net/http""io/ioutil")func main() {url := "https://api.adapty.io/api/v1/sdk/apple/webhook/123a258e62fad41bfa734f4b0dbcad456/"; // don't forget to replace this URLpayload := strings.NewReader(`{"latest_receipt":"abc=","notification_type":"INITIAL_BUY",...}`) // json encoded payload from Apple/Googlemethod := "POST"client := &http.Client {}req, err := http.NewRequest(method, url, payload)if err != nil {fmt.Println(err)return}req.Header.Add("Content-Type", "application/json")res, err := client.Do(req)if err != nil {fmt.Println(err)return}defer res.Body.Close()}