0

I am trying to post data to create a customer using Rotessa API. I am using curl command which I've found in Rotessa API reference. But I am getting errors in return response instead of JSON string. It would be very helpful if I get help on this. Thanks

curl command:

 curl -X POST -H 'Content-Type: application/json' -H "Authorization: Token 
 token=\"<api_key>\"" -d '{"custom_identifier": "test api", "email": 
 "[email protected]", "name": "Mike Smith", "bank_name": "Scotiabank", 
 "transit_number": "11111", "institution_number": "111", "account_number": 
 "11111111", "address": { "address_1": "123 Main Street", "address_2": "Unit 
 4", "city": "Toronto", "province_code": "ON", "postal_code": "M1B 0B7" }}' 
 <rotessa_endpoint>/customers.json  

and converted php code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://api.rotessa.com/v1/customers.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"custom_identifier\": \"test api\", 
                                   \"email\": \"[email protected]\", 
                                   \"name\": \"Mike Smith\", 
                                   \"bank_name\": \"Scotiabank\", 
                                   \"transit_number\": \"11111\", 
                                   \"institution_number\": \"111\", 
                                   \"account_number\": \"11111111\", 
                                   \"address\": { \"address_1\": \"123 Main
                                                                   Street\", 
                                                  \"address_2\": \"Unit 4\", 
                                                  \"city\": \"Toronto\", 
                                                  \"province_code\": \"ON\", 
                                                  \"postal_code\": \"M1B 
                                                               0B7\" }}");

    curl_setopt($ch, CURLOPT_POST, 1);

    $headers = array();
    $headers[] = "Content-Type: application/json";
    $headers[] = "Authorization: Token token=\"<api_key>\"";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $result = curl_exec($ch);
    if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
    }


    curl_close ($ch);

    echo $result;

it gives the following error:

    {"errors":[{"error_code":"unauthorized","error_message":"Not Found."}]}

To resolve further confusion I used real api_key in my testing. Just didn't post it here.

2 Answers 2

1

Above you have endpoint URL /customers.json, below you have /customers.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, i've noticed and changed accordingly but still getting the same error. Thanks for your reply.
0

Normally the APIs need an API key and should be sent by curl.

curl "<rotessa_endpoint>/customers.json" -H "Authorization: Token token=\"<api_key>\""

Instead of <api_key> should enter your API key.

rotessa API KEY

13 Comments

@DanFromGermany I don't think so. I thinks in the first he puts just "<api_key> instead on real key and in second version ` Token token=\"<token>\""` the same history.
I think he removed the keys so he does not expose them publicly on the internet.
Yes, I did enter the API key. without the key, it won't make any sense. As Dan said I just took it off before posting here. But still getting the same error. Thanks for your input.
@user9310297 Great, is your problem solved or not yet?
@malus jan No not yet :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.