# Endpoints

### XP

## This endpoint sends a create project request to the XP contract

<mark style="color:green;">`POST`</mark> `https://api.xp-protocol.io/create-project`

This should be the first step into the XP ecoysystem

#### Headers

| Name                                           | Type             | Description                         |
| ---------------------------------------------- | ---------------- | ----------------------------------- |
| X-API-KEY                                      | \<Your-Key>      | Get an API key from the Huddln team |
| Content-Type<mark style="color:red;">\*</mark> | application/json |                                     |

#### Request Body

| Name                                           | Type                                                                                         | Description                                                                                                                                                                                                     |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| projectId<mark style="color:red;">\*</mark>    | 0xf0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b                           | A 32 Byte string of what you would like the project ID to be. This is not updateable and can only be chosen once.                                                                                               |
| name<mark style="color:red;">\*</mark>         | test                                                                                         | Name this project with something that closely aligns to your company's name.                                                                                                                                    |
| inputActions<mark style="color:red;">\*</mark> | \[{"name":"bought","points":200,"direction":0}]                                              | An array of actions and their properties, use the examlpe provided to construct this object.                                                                                                                    |
| owners<mark style="color:red;">\*</mark>       | \["0x0000000000000000000000000000000000000000","0x0000000000000000000000000000000000000001"] | An array of wallet addresses as strings that have full authority over this project,                                                                                                                             |
| updaters<mark style="color:red;">\*</mark>     | \["0x0000000000000000000000000000000000000000","0x0000000000000000000000000000000000000001"] | An array of wallet addresses as strings that have permissions to call the **updateScore()** method for this project. This is used so that your backend can update the scoring system in a more scalable manner. |

## Update score of a wallet address

<mark style="color:green;">`POST`</mark> `https://api.xp-protocol.io/update-score`

In the XP ecosystem this function should be called any time you want to trigger a score change.

#### Request Body

| Name                                           | Type                                                               | Description                                                                                                                                              |
| ---------------------------------------------- | ------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| updateId<mark style="color:red;">\*</mark>     | 0x2413fb3709b05939f04cf2e92f7d0897fc2596f9ad0b8a9ea855c7bfebaae892 | A unique / semi unique (depending on the use-case) 32 byte string to associate with this update.                                                         |
| projectId<mark style="color:red;">\*</mark>    | 0xf0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b | The 32 byte string ID of the project associated with this update.                                                                                        |
| actionName<mark style="color:red;">\*</mark>   | bought                                                             | A string of the action you would like to trigger against the particular wallet address. This action must already exist in the project's list of actions. |
| scoreType<mark style="color:red;">\*</mark>    | reputation                                                         | A string that indicates which score type you would like this action to accumulate on. This score type must already exist within the project.             |
| targetWallet<mark style="color:red;">\*</mark> | 0xE6F7e0aDD15c665f5AC2B0eeDFd2e8578EF2bf8A                         | The address as a string that you would like to update the score on.                                                                                      |
| signature<mark style="color:red;">\*</mark>    | <0x....>                                                           | Create a signature from the message "${Date.now().toString()}" , A full example is provided below.                                                       |
| message<mark style="color:red;">\*</mark>      | 1656535069845                                                      | A string generated from JS Date.now().toString(), this is a string that represents the current epoch time in milliseconds.                               |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    // Response
}
```

{% endtab %}
{% endtabs %}

More endpoints coming soon...

#### Example Request

The below request demonstrates how to perform a POST call to the **/update-score** endpoint with an X-API-KEY & Signature provided by either an "updater" or an "owner" of the project.

```javascript
let myHeaders = new Headers();
let message = Date.now().toString();
let signatureObject = await web3.eth.accounts.sign(message, <PRIVATE_KEY>); //Private key of a wallet that is either an Updater or an Owner of the current project.
let signature = signatureObject.signature;

//Headers
myHeaders.append("X-API-KEY","<key>");
myHeaders.append("Content-Type", "application/json");
  
  //UpdateId, should be unique, duplicate updateIds are ignored and do will not update the target address's score.
  ///think of an updateId as a unique transaction.
 let updateId = targetAddress.toString()':'+ Date.now().toString()
 let id = '0x' + sha256(updateId).toString(); // 0x to signify its a bytes32
  //Send to API
    const body = JSON.stringify({
        "updateId": <updateId>,
        "projectId": <PROJECT_ID>,
        "actionName": <action-name>,
        "scoreType": <scoreType>,
        "targetWallet": <targetAddress>,
        "signature": signature,
        "message": message
    })
    const requestOptions = {
        method: 'POST',
        headers: myHeaders,
        body: body,
        redirect: 'follow'
    };
    
    let response = await fetch('https://api.xp-protocol.io/update-score, requestOptions).then(async (response) => ({ status: response.status, value: await response.text() }));
c
```
