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
salesforcerrrsalesforcerrr 

Connect to APEX REST endpoint

Hi, 

I have a custom Apex Endpoint and would now like to test it with Swagger. I have been successful in setting this up with Postman (using for example: http://amitsalesforce.blogspot.com/2017/06/test-salesforce-api-by-postman-rest.html 

Now what I did was convert the Postman collection to a Swagger file and try to authenticate using this one. Currently I am getting this error when hitting authenticate in Swagger: 
<error_description>must use HTTP POST</error_description>

I pasted the Swagger file here: 
swagger: '2.0'
info:
  version: '1.0'
  title: Salesforce Test
  description: 'TODO: Add Description'
host: ap4.salesforce.com
basePath: /services/apexrest/api/Account
securityDefinitions:
  auth:
    type: oauth2
    flow: implicit
    authorizationUrl: 'https://na50.salesforce.com/services/oauth2/token?grant_type=password&client_id=***Consumer Key_Here***&client_secret=***Consumer Secret_Here***&username=*********&password=*****password+securityToken******'
    scopes: {}
    x-skip-client-authentication: false
schemes:
  - https
consumes:
  - application/json
produces:
  - application/json
paths:
  /12345:
    get:
      description: 'TODO: Add Description'
      summary: Connect to Developer set up
      tags:
        - Misc
      operationId: 12345Get
      produces:
        - application/json
      parameters: []
      responses:
        '200':
          description: ''
      security:
        - auth: []
      x-unitTests:
        - request:
            method: GET
            uri: /12345
          expectedResponse:
            x-allowExtraHeaders: true
            x-bodyMatchMode: NONE
            x-arrayOrderedMatching: false
            x-arrayCheckCount: false
            x-matchResponseSchema: true
            headers: {}
          x-testShouldPass: true
          x-testEnabled: true
          x-testName: Connect to Developer set up
          x-testDescription: 'TODO: Add Description'
      x-operation-settings:
        CollectParameters: false
        AllowDynamicQueryParameters: false
        AllowDynamicFormParameters: false
        IsMultiContentStreaming: false

Does someone know what I need to change? What flow to use with Swagger as its currently on the implicit one this might be the issue? 

Thanks
 
v varaprasadv varaprasad
Hi ,

As per the error, it is saying you have to use  HTTP POST method in httprequest class.
Using post we can generate the access token.

Hope this helps you!
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com