# Authentication

To authenticate API requests, you need to generate your keys by sending an email to [support@sendcash.africa](mailto:support@buycoins.africa)

Two keys will be generated for you:

1. **Public Key**: Think of this as a username. It's how Sendcash knows which user is attempting to make a request.
2. **Secret Key**: Think of this as a password. Sendcash **never** stores your Secret Key, we will only generate it and send it to you. Copy & keep your secret key in a secure place (e.g Environment Variables).

To authenticate your GraphQL request, you need to use [Basic Authentication](https://en.wikipedia.org/wiki/Basic_access_authentication) with the **Public Key as username** and the **Secret Key as password**.

### Basic Authentication Primer

* username (Public Key) and password (Secret Key) are concatenated into a single string: `username:password`
* This string is encoded with Base64
* The `Basic` keyword is put before this encoded value and shall result in something like this: `Basic am9objpzZWNyZXQ=`
* The entire string should be added to the header of the request with the key `Authorization`

```
curl --header "Authorization: Basic am9objpzZWNyZXQ=https://api.sendcash.africa/v1/graphql
```

### How to Authenticate with GraphQL

Most GraphQL client libraries have some way to add headers to all your requests. Here's a JavaScript example with [Apollo Boost](https://www.npmjs.com/package/apollo-boost)

```javascript
const ApolloClient = require('apollo-boost').default;

const authValue = 'Basic ' + Buffer.from(process.env.SENDCASH_PUBLIC_KEY + ':' + process.env.SENDCASH_SECRET_KEY).toString('base64');
const client = new ApolloClient({
    uri: process.env.SENDCASH_GRAPHQL_API,
    fetch: fetch,
    headers: {
        authorization: authValue
    }
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sendcash.africa/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
