# Exchange OAuth credentials for an access token POST https://app.askelephant.ai/api/v1/oauth/token Content-Type: application/x-www-form-urlencoded Exchanges OAuth client or user grant credentials for an access token. Reference: https://docs.askelephant.ai/api-reference/authentication/oauth-token ## OpenAPI Specification ```yaml openapi: 3.1.0 info: title: AskElephant Public API version: 1.0.0 paths: /v1/oauth/token: post: operationId: oauth-token summary: Exchange OAuth credentials for an access token description: Exchanges OAuth client or user grant credentials for an access token. tags: - subpackage_authentication parameters: - name: Authorization in: header description: Bearer authentication required: true schema: type: string responses: '200': description: Access token issued successfully. content: application/json: schema: $ref: '#/components/schemas/Authentication_oauthToken_Response_200' '400': description: Invalid OAuth request. content: application/json: schema: $ref: '#/components/schemas/OauthTokenRequestBadRequestError' '401': description: Invalid client credentials. content: application/json: schema: $ref: '#/components/schemas/OauthTokenRequestUnauthorizedError' '500': description: Server error during token exchange. content: application/json: schema: $ref: '#/components/schemas/OauthTokenRequestInternalServerError' requestBody: content: application/json: schema: type: object properties: grant_type: $ref: >- #/components/schemas/V1OauthTokenPostRequestBodyContentApplicationXWwwFormUrlencodedSchemaGrantType client_id: type: string description: OAuth client ID. Required for `client_secret_post`. client_secret: type: string description: OAuth client secret. Required for `client_secret_post`. scope: type: string description: Space-delimited scopes requested for the access token. code: type: string description: Authorization code for the `authorization_code` grant. redirect_uri: type: string format: uri description: Redirect URI bound to the authorization code. code_verifier: type: string description: PKCE code verifier for the authorization code exchange. refresh_token: type: string description: Refresh token for the `refresh_token` grant. required: - grant_type servers: - url: https://app.askelephant.ai/api - url: https://app-staging.askelephant.ai/api components: schemas: V1OauthTokenPostRequestBodyContentApplicationXWwwFormUrlencodedSchemaGrantType: type: string enum: - authorization_code - refresh_token - client_credentials title: >- V1OauthTokenPostRequestBodyContentApplicationXWwwFormUrlencodedSchemaGrantType Authentication_oauthToken_Response_200: type: object properties: access_token: type: string token_type: type: string expires_in: type: integer refresh_token: type: string scope: type: string required: - access_token - token_type - expires_in title: Authentication_oauthToken_Response_200 OauthTokenRequestBadRequestError: type: object properties: error: type: string error_description: type: string required: - error title: OauthTokenRequestBadRequestError OauthTokenRequestUnauthorizedError: type: object properties: error: type: string error_description: type: string required: - error title: OauthTokenRequestUnauthorizedError OauthTokenRequestInternalServerError: type: object properties: error: type: string required: - error title: OauthTokenRequestInternalServerError securitySchemes: BearerAuth: type: http scheme: bearer ``` ## SDK Code Examples ```python import requests url = "https://app.askelephant.ai/api/v1/oauth/token" payload = "" headers = { "Authorization": "Bearer ", "Content-Type": "application/x-www-form-urlencoded" } response = requests.post(url, data=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://app.askelephant.ai/api/v1/oauth/token'; const options = { method: 'POST', headers: { Authorization: 'Bearer ', 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams('') }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://app.askelephant.ai/api/v1/oauth/token" req, _ := http.NewRequest("POST", url, nil) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/x-www-form-urlencoded") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://app.askelephant.ai/api/v1/oauth/token") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/x-www-form-urlencoded' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://app.askelephant.ai/api/v1/oauth/token") .header("Authorization", "Bearer ") .header("Content-Type", "application/x-www-form-urlencoded") .asString(); ``` ```php request('POST', 'https://app.askelephant.ai/api/v1/oauth/token', [ 'form_params' => null, 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/x-www-form-urlencoded', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://app.askelephant.ai/api/v1/oauth/token"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/x-www-form-urlencoded" ] let request = NSMutableURLRequest(url: NSURL(string: "https://app.askelephant.ai/api/v1/oauth/token")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```