function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hemmhemm 

Sites Pageview for Apex REST calls?

We are hosting an Apex REST endpoint on our salesforce site. The URL path to the service is similar to https://mycompany.secure.force.com/services/apexrest/endpointName.

I am confused as to whether a hit against that endpoint will count as a Site Pageview, API call or both? It appears that it is counting as a pageview, but it seems to me that it should not and should only count as an API hit. Please clarify.
Abhinav GuptaAbhinav Gupta
I am not sure if you can host Apex REST webservices via Sites pages. As Apex REST is always meant to execute behind Security Layer, with all REST calls expecting a sessionid or oauth token to authorize. 

You might hack to access the Apex REST class directly from Sites controller, but it doesn't looks like an ideal solution to me.
I think if you want to use Sites pages as REST resources, best would be to change Visualforce page content type to XML/JSON and print out stuff directly, it could work somewhat for public guest users.

Answering your original questions : If you are hitting a sites page its a sites view, not an API call. Unless you are using Http class in Sites Apex controller :) 
hemmhemm
Yes, you can communicate with Apex REST via Sites. Just go to the Public Site Settings profile for the site and add the apex class under "Enabled Apex Class Access". Your endpoint will be site.force.com/services/apexrest/WhatEverEndpointYouSpecify. We are using this today to have Stripe's webhooks communicate back to our org as we process payments. Works like a charm. No authentication necessary.

hemmhemm
Also, note that in this example, we are hitting a Sites URL, but it is not a page exactly. It's a REST endpoint for code execution.
Abhinav GuptaAbhinav Gupta
@hemm thats good to learn !
Anesh MistryAnesh Mistry
Hello, did you resolve this. 

If you host a Rest API via Apex through a Force.com Site (unauthenticated) does it consume 1 API call AND 1 Pageview?
hemmhemm
No one seems to know. I've been asking this question in different places for a couple of years now and have never received an answer. People guess an answer, but no one at salesforce seems to really know.

I'd love someone to just clarification in the documentation at https://help.salesforce.com/HTViewHelpDoc?id=sites_limits.htm&language=en_US#SitesPageViewsWhatCounts (https://help.salesforce.com/HTViewHelpDoc?id=sites_limits.htm&language=en_US#SitesPageViewsWhatCounts) and put an end to the question.