-1

I try to create a user in rest-API with JSON. That is success.

My question:

1) I need to receive a POST request from a webform containing the user information?

2) Add an APIkey and insert the variables.

3) Generate the JSON to send to the page:

rest.domain.com/api/v1/UserCreate

POST REQUEST FROM MY WEBFORM (example)

     {
     "UserID":"11",
     "GroupID":"22",
     "MemberID":"97865454534231",
     "UserFullName":"Mr Test",
     "UserEmail":"mail@mail.com",
     "UserRegistrationNumber":"9999999",
      }

JSON CALL TO API ( the working json )

    POST /api/v1/UserCreate HTTP/1.1
    Host: rest.domain.com
    APIKey: XXXXXXXXXX-XXXXXXXXX-XXXXXXXXXXX
    Content-Type: application/json

    {
    "APIKey":"XXXXXXXXXX-XXXXXXXXX-XXXXXXXXXXX",
    "UserID":"11",
    "GroupID":"22",
    "UserEmail" : "mail@mail.com",
    "UserRegistrationNumber" : "9999999",
    "UserFullName" : "Mr Test",
    "MemberID" : "123456789",
    }

1 Answers1

-1
  1. Create a php page that listens for a post in the predefined variable $_POST.

  2. Based on the data received build a string of JSON

  3. Adjust the content type of the header and echo the JSON string you built

Example:

// CHECK POST FIELDS
if(@$_POST['UserID'] != ''){

    // GENERATE API KEY
    $apiKey = ''

    // BUILD RESPONSE
    $jsonResponse =     '{';
    $jsonResponse .=     '"APIKey":"'.$apiKey.'",';
    $jsonResponse .=     '"UserID":"'.$_POST['UserID'].'",';
    $jsonResponse .=     '"GroupID":"'.$_POST['GroupID'].'",';
    $jsonResponse .=     '"MemberID":"'.$_POST['MemberID'].'",';
    $jsonResponse .=     '"UserFullName":"'.$_POST['UserFullName'].'",';
    $jsonResponse .=     '"UserEmail":"'.$_POST['UserEmail'].'",';
    $jsonResponse .=     '"UserRegistrationNumber":"'.$_POST['UserRegistrationNumber'].'",';
    $jsonResponse .=    '}';

    // SET HEADER
    header('Content-Type: application/json');

    // ECHO RESPONSE
    echo $jsonResponse;

}
Tony
  • 2,890
  • 1
  • 24
  • 35