0

I am attempting to create a REST integration with Square (https://developer.squareup.com), but am receiving a 302 Found error when I attempt to send a webhook via Square.

My API is working successfully when tested through Workbench with the payload that is being sent via Square, at the URI of /services/apexrest/[SOBJECTNAME]/[RESTRESOURCENAME].

My endpoint URL is as follows: https://ORGNAME--partial.lightning.force.com/services/apexrest/[SOBJECTNAME]/[RESTRESOURCENAME] which generates a 302 Found error, meaning that the endpoint is redirecting. I am unable to process the redirect via Square.

I have tried playing around with different base URLs for the endpoint per the Salesforce documentation and other forum posts, for example ORGNAME--partial.my.salesforce.com (401 unauthorized), ORGNAME--partial.INSTANCE.my.salesforce.com (307 redirect), and ORGNAME--partial.INSTANCE.force.com (401 unauthorized) to no avail. I am unable to use ORGNAME--partial.salesforce.com for the subscription endpoint per Square.

Hoping someone has run into this issue before. Thank you!


Following up on identigral's comment, I have created a Site with the value of https://ORGNAME-square.INSTANCE.force.com/square/ and have updated my webhook endpoint accordingly to https://ORGNAME-square.INSTANCE.force.com/square/services/apexrest/[SOBJECTNAME]/[RESTRESOURCENAME]. Now getting a code of status 500 Internal Server Error.

I should add that I also have a Remote Site Setting with the appropriate value of https://connect.squareupsandbox.com.

5
  • 2
    It works in Workbench because you're authenticated. For a typical webhook, your REST endpoint must be public - see answer by gils in this Q&A for a howto
    – identigral
    Commented Feb 16, 2022 at 7:17
  • Hello @identigral! I have a site set up now and am getting a 500 error. Commented Feb 16, 2022 at 8:18
  • It's unclear on what API you're calling after you've created the Site and what your webhook is doing. Please edit your question and provide a Minimal, Reproducible Example. See How to Ask and Help Center for guidance on this.
    – identigral
    Commented Feb 16, 2022 at 8:29
  • What is the urlMapping you've specified in your @restResource annotation?
    – Derek F
    Commented Feb 16, 2022 at 12:19
  • Hi @DerekF, the urlMapping is /[SOBJECT]/[RESTRESOURCENAME], as specified in the URI. I have verified spelling and capitalization. Commented Feb 16, 2022 at 19:40

1 Answer 1

1

Just posting the follow up as to what the issue was. We were able to solve this via @identigral's comment of setting up a site and debugging through the Site Guest User. The resulting 500 error was caused by Square sending the same payload multiple times and duplicate detection bouncing it back.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .