> For the complete documentation index, see [llms.txt](https://yasmeen-rezk.gitbook.io/my-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yasmeen-rezk.gitbook.io/my-notes/bug-bounty-playbook-v2/api-testing/apis.md).

# APIs

There are several types of APIs, and they are each slightly different.

💡If you come across an API endpoint the first step is to figure out what type of API it is.

## <mark style="color:yellow;">Rest API</mark>

#### Signs

* Request and response data are JSON strings.
* The application is issuing a PUT request.
* The HTTP response contains a MIME type of JSON.

<figure><img src="https://509923538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ2ZeCCTH4XZTY31hlbGx%2Fuploads%2F39UnBD3lOLioGjhFsOEH%2Fimage.png?alt=media&amp;token=8a24d255-2bd6-4b0b-9bce-0d07dab90daf" alt=""><figcaption><p>REST API</p></figcaption></figure>

#### Cons

* ⚠️ Rest API requires the client to send multiple requests to different endpoints on the API to query data from the backend database.

## <mark style="color:yellow;">Remote Procedure Call (RPC)</mark>

Fairly basic, each HTTP request maps to a particular function.

💡XMLRPC uses XML while JSONRPC uses JSON for its encoding type.

* If this endpoint was a JSONRPC API the data would be contained in a JSON string instead of an XML doc.

#### Signs

* The file name is “xmlrpc.php”.
* the request body contains two tags called “methodCall” and “methodName”.
* The request only uses two, GET and POST methods.

<figure><img src="https://509923538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ2ZeCCTH4XZTY31hlbGx%2Fuploads%2FW2o3sCCFltVQBthqsGru%2Fimage.png?alt=media&amp;token=56d6d5b8-efc6-40a6-aad5-1c031175c095" alt=""><figcaption></figcaption></figure>

## <mark style="color:yellow;">Simple Object Access Protocol (SOAP)</mark>

Like an advanced version of XMLRPC:

* Both use XML for encoding and HTTP to transfer messages.

#### Signs

The message is first wrapped in a “<soapenv:Envelope>” tag which contains the header and body tags.

* header part is optional and contains information about the message itself like values related to authentication, and complex types.
* body is the part of the XML document which actually contains our message:

```xml
<!-- SOAP body we are calling a method named “ GetCitiesByCountry ” and an argument called “CountryName ” with a string 
value of “gero et”  -->
<soapenv:Body> 
<web:GetCitiesByCountry> 
<!--type: string--> 
<web:CountryName>gero et</web:CountryName> 
</web:GetCitiesByCountry> 
<soapenv:Body>
```

## <mark style="color:yellow;">GraphQL API</mark>

A data query language developed by Facebook acts as an alternative to REST API.

* a single request can be used to gather all the necessary information from the backend.
* missing authentication by default graphQL endpoints can be vulnerable to other bugs such as IDOR.

#### Directory brute force paths to check for graphQL:

* /graphql
* /graphiql
* /graphql.php
* /graphql/console

**Once you find an open graphQL instance** you need to know what queries it supports using [the introspection system](https://graphql.org/learn/introspection/).

💡Types that start with a “\_\_” can be ignored as those are part of the introspection system.

Once an interesting type is found you can query its field values, an example:

* Show all the available queries on the endpoint:

&#x20;     \--> example.com/graphql?query={\_\_schema{types{name,fields{name}}}}

Once an interesting type is found, query its field values:

&#x20;     \--> example.com/graphql?query={TYPE\_1{FIELD\_1,FIELD\_2 }}

Once the query is submitted it will pull the relevant information and return the results.

**EX:**

<figure><img src="https://509923538-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ2ZeCCTH4XZTY31hlbGx%2Fuploads%2FhAQ2Qv4sdYiPn0OozccU%2Fimage.png?alt=media&amp;token=666bd131-0ead-4bd3-8299-b0a13a4cc427" alt=""><figcaption></figcaption></figure>
