1

So I would like to expose a custom rest api endpoint in sales force to access and update by custom object.

My Apex Class looks like

@RestResource(urlMapping='/v1/gcxintegrateddata/*')
global with sharing class GCXIntegratedDataController {

     @HttpGet
     global static List<GCX_Integrated_Data__c> getList() {

        // ... removed for brevity

        return data;
    }
}

I have a connected app that in a sandbox environment in lightning.force

https://xxxx.lightning.force.com

I can get an authentication token using postman but when i try to invoke my endpoint i always get an INVALID_SESSION_ID

Is there anything that I am missing?

This is what my request looks like

 GET /services/apexrest/v1/gcxintegrateddata
cache-control: no-cache
postman-token: 4e638e44-8e8c-4397-846c-b285abbcd7d4
authorization: Bearer 00D6F000002TjRj!ARMAQJgUk7HgTzNhvBPVn59WwFYoMB19vEIPSLg1DMU24cmnEVJWnWeCcWuL5aBmUH7AM3Z9Cyuec.VFPhSAaC19Jx8ulEtJ
user-agent: PostmanRuntime/7.3.0
accept: */*
host: xxxx.salesforce.com
inst=APP_0k; 79eb100099b9a8bf=3:false:.salesforce.com
accept-encoding: gzip, deflate
HTTP/1.1 401
status: 401
date: Fri, 30 Nov 2018 05:37:56 GMT
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
x-xss-protection: 1; mode=block
content-security-policy: upgrade-insecure-requests
x-robots-tag: none
cache-control: private
www-authenticate: Token
content-type: application/json;charset=UTF-8
transfer-encoding: chunked
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

1 Answer 1

1

Follow the below steps to get Authorization code using POSTMAN and make a callout:

  • Slect the Authorization Tab and choose the type as OAuth 2.0
  • Click on "Get New Access Token".
  • Token Name : Test
  • Authorization: https://login.salesforce.com/services/oauth2/authorize
  • Token Request: https://login.salesforce.com/services/oauth2/token
  • Client Id: Enter Client Id from your connected App
  • Client secret : Enter Client Secret from your connected App
  • Grant Type : Authorization Code
  • Click on Request Token. You will be redirected to Salesforce login screen
  • Enter Credentials
  • Once successful login, notice access Token is generated in right hand side in your post man.
  • Choose Add Token as "Header"
  • Then select "Use Token"
  • Now in the top section in Post Man choose "GET" and add your End point and click on "Send".
1
  • Works! Thanks :) My problem was caused by using the incorrect account for password grant type. I was using the prod instead of sandbox. Dec 3, 2018 at 3:33

You must log in to answer this question.

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